Module:Schema

local p = {}

local utilsSchema = require("Module:UtilsSchema")

function p.Validate(frame) return p.validate(frame:getParent:getTitle, frame.args[1]) end

function p.validate(docPageName, schemaName) local docPage = mw.title.new(docPageName) local dataPage = docPage.basePageTitle if mw.title.getCurrentTitle.text ~= dataPage.text then return "" end local modulePage = dataPage.basePageTitle local module = require(modulePage.fullText) if not module.Schemas then error(string.format("Module '%s' does not export any schemas.", modulePage.text)) end schemaName = schemaName or dataPage.subpageText if not module.Schemas[schemaName] then error(string.format("Module '%s' has no such schema '%s'.", modulePage.text, schemaName)) end local data = mw.loadData(dataPage.fullText) local err = utilsSchema.validate(module.Schemas[schemaName], schemaName, data, "data") if err then return "" end end

return p