{"version":3,"sources":["jsdelivr-header.js","/npm/@seriousme/openapi-schema-validator@2.8.0/index.js"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA,OCNS,iBAAoB,iBACpB,aAAgB,0BAChB,cAAe,QAAW,kBAC5B,YAAa,0BACb,UAAW,sBACX,qBAAsB,qBACpB,YAAa,SAAY,iBACzB,UAAW,gBAAmB,eAUvC,MAAQ,QAAS,YAAe,iBAE1B,gBAAkB,IAAI,IAAI,CAAC,MAAO,MAAO,MAAO,QAGhD,YAAc,CAEnB,0CAA2C,MAE3C,+CAAgD,SAG3C,YAAc,iBAMpB,SAAS,UAAU,GAClB,OAAO,cAAc,IAAI,IAAI,cAAsB,KACpD,CAMA,SAAS,WAAW,GACnB,OAAO,KAAK,MAAM,aAAa,UAAU,GAAO,SACjD,CAeA,SAAS,kBAAkB,GAC1B,IAAK,MAAM,KAAW,gBAAiB,CACtC,MAAM,EAAgC,QAAZ,EAAoB,UAAY,UACpD,EAAO,EAAc,GAC3B,GAAoB,iBAAT,GAAqB,EAAK,WAAW,GAC/C,MAAO,CACN,UACA,oBACA,qBAAsB,EAGzB,CACA,MAAO,CACN,aAAS,EACT,uBAAmB,EACnB,0BAAsB,EAExB,CAUA,eAAe,iBAAiB,GAC/B,GAAoB,iBAAT,EACV,MAAO,CACN,QAAQ,EACR,SAAU,KACV,KAAkC,GAIpC,GAAoB,iBAAT,EACV,MAAO,CACN,QAAQ,EACR,aAAc,sEAAsE,MAKtF,IAAI,EAAa,EAEb,EAAW,KAEf,IAAK,EAAW,MAAM,MACrB,IACC,QAAmB,SAAS,EAAM,SAClC,EAAW,CACZ,CAAE,MAAO,GACR,MAAO,CACN,QAAQ,EACR,aAAc,wBAAwB,KAExC,CAGD,IACC,MAAO,CACN,QAAQ,EACR,WACA,KACC,KAAK,EAAY,CAAE,OAAQ,cAG9B,CAAE,MAAO,GACR,MAAO,CACN,QAAQ,EACR,aAAc,qCAEhB,CACD,QAEO,MAAM,UAIZ,W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AAE,GAAa,GACrB,QAAE,GAAY,kBAAkB,GACtC,GAAK,EAAL,CAOA,GAAI,EACH,MAAM,IAAI,MACT,6DAGF,EAAgB,CAPhB,KALA,CACC,MAAM,EAA6B,EAAU,KAAK,EAElD,KAAK,WAAW,EAAM,EAEvB,CAQD,CACA,OAAO,KAAK,SAAqC,EAClD,CAMA,eAAA,CAAgB,GACf,IAAK,KAAK,cAAc,GAAU,CACjC,MAAM,EAAS,WAAW,cAAc,iBAClC,EAAgB,EAAO,QAIvB,EAAM,IAAI,EAFf,YAAY,IAEY,KAAK,YAC9B,WAAW,GACX,EAAI,UAAU,eAAe,GAC7B,KAAK,cAAc,GAAW,EAAI,QAAQ,EAC3C,CACA,OAAO,KAAK,cAAc,EAC3B","file":"/npm/@seriousme/openapi-schema-validator@2.8.0/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/@seriousme/openapi-schema-validator@2.8.0/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","import { readFileSync } from \"node:fs\";\nimport { readFile } from \"node:fs/promises\";\nimport { fileURLToPath, URL } from \"node:url\";\nimport Ajv2020 from \"ajv/dist/2020.js\";\nimport Ajv04 from \"ajv-draft-04\";\nimport addFormatsModule from \"ajv-formats\";\nimport { JSON_SCHEMA, load } from \"js-yaml\";\nimport { checkRefs, replaceRefs } from \"./resolve.js\";\n\n/** @typedef {import(\"ajv/dist/core.js\").default} AjvCore */\n/** @typedef {typeof import(\"ajv/dist/core.js\").default} AjvCoreConstructor */\n\n/** @typedef {import(\"./index.js\").Validator} ValidatorDecl */\n/** @typedef {import(\"./index.js\").SpecData} SpecData */\n\n// ajv-formats is a CommonJS module,\n// so we need to access its default property to get the correct typed value\nconst { default: addFormats } = addFormatsModule;\n\nconst openApiVersions = new Set([\"2.0\", \"3.0\", \"3.1\", \"3.2\"]);\n\n/** @type {Partial<Record<string, AjvCoreConstructor>>} */\nconst ajvVersions = {\n\t// @ts-expect-error using pure typescript doesn't produce an error\n\t\"http://json-schema.org/draft-04/schema#\": Ajv04,\n\t// @ts-expect-error using pure  typescript doesn't produce an error\n\t\"https://json-schema.org/draft/2020-12/schema\": Ajv2020,\n};\n\nconst inlinedRefs = \"x-inlined-refs\";\n\n/**\n * @param {string} fileName\n * @returns {string}\n */\nfunction localFile(fileName) {\n\treturn fileURLToPath(new URL(fileName, import.meta.url));\n}\n\n/**\n * @param {string} file\n * @returns {{ $schema: string, [x: string]: unknown }}\n */\nfunction importJSON(file) {\n\treturn JSON.parse(readFileSync(localFile(file), \"utf-8\"));\n}\n\n/**\n *\n * @param {{ swagger?: string, openapi?: string }} specification\n * @returns {{\n * \tversion: string,\n * \tspecificationType: 'swagger' | 'openapi',\n *  specificationVersion: string,\n * } | {\n * \tversion: undefined,\n * \tspecificationType: undefined,\n *  specificationVersion: undefined,\n * }}\n */\nfunction getOpenApiVersion(specification) {\n\tfor (const version of openApiVersions) {\n\t\tconst specificationType = version === \"2.0\" ? \"swagger\" : \"openapi\";\n\t\tconst prop = specification[specificationType];\n\t\tif (typeof prop === \"string\" && prop.startsWith(version)) {\n\t\t\treturn {\n\t\t\t\tversion,\n\t\t\t\tspecificationType,\n\t\t\t\tspecificationVersion: prop,\n\t\t\t};\n\t\t}\n\t}\n\treturn {\n\t\tversion: undefined,\n\t\tspecificationType: undefined,\n\t\tspecificationVersion: undefined,\n\t};\n}\n\n/**\n * @typedef {SpecData} SpecFromData\n */\n\n/**\n * @param {unknown} data\n * @returns {Promise<{ loaded: true; fileName: string | null; spec: SpecFromData} | { loaded: false; errorMessage: string }>}\n */\nasync function loadSpecFromData(data) {\n\tif (typeof data === \"object\") {\n\t\treturn {\n\t\t\tloaded: true,\n\t\t\tfileName: null,\n\t\t\tspec: /** @type {SpecFromData} */ (data),\n\t\t};\n\t}\n\n\tif (typeof data !== \"string\") {\n\t\treturn {\n\t\t\tloaded: false,\n\t\t\terrorMessage: `Invalid input type. Expected \"string\" or \"object\", but got \"${typeof data}\"`,\n\t\t};\n\t}\n\n\t/** @type {string} */\n\tlet sourceData = data;\n\t/** @type {string | null} */\n\tlet fileName = null;\n\t// If string doesn't contains \\n assuming is a file path\n\tif (!sourceData.match(/\\n/)) {\n\t\ttry {\n\t\t\tsourceData = await readFile(data, \"utf-8\");\n\t\t\tfileName = data;\n\t\t} catch (_) {\n\t\t\treturn {\n\t\t\t\tloaded: false,\n\t\t\t\terrorMessage: `Could not read file \"${data}\"`,\n\t\t\t};\n\t\t}\n\t}\n\n\ttry {\n\t\treturn {\n\t\t\tloaded: true,\n\t\t\tfileName,\n\t\t\tspec: /** @type {SpecFromData} */ (\n\t\t\t\tload(sourceData, { schema: JSON_SCHEMA })\n\t\t\t),\n\t\t};\n\t} catch (_) {\n\t\treturn {\n\t\t\tloaded: false,\n\t\t\terrorMessage: \"Failed to parse input as YAML/JSON\",\n\t\t};\n\t}\n}\n\nexport class Validator {\n\t/**\n\t * @param {import('./index.js').ValidatorOptions} ajvOptions\n\t */\n\tconstructor(ajvOptions = {}) {\n\t\t// AJV is a bit too strict in its strict validation of openAPI schemas\n\t\t// so switch strict mode and validateFormats off\n\t\tif (ajvOptions.strict !== \"log\") {\n\t\t\tajvOptions.strict = false;\n\t\t}\n\t\tthis.ajvOptions = ajvOptions;\n\t\t/** @type {Partial<Record<string, ReturnType<AjvCore['compile']>>>} */\n\t\tthis.ajvValidators = {};\n\t\t/** @type {Record<string, unknown>} */\n\t\tthis.externalRefs = {};\n\t}\n\n\tstatic supportedVersions = openApiVersions;\n\n\t/** @type {ValidatorDecl['resolveRefs']} */\n\tresolveRefs(opts = {}) {\n\t\treturn /** @type {SpecData} */ (\n\t\t\treplaceRefs(this.specification || opts.specification)\n\t\t);\n\t}\n\n\t/** @type {ValidatorDecl['addSpecRef']} */\n\tasync addSpecRef(data, uri) {\n\t\tconst specResult = await loadSpecFromData(data);\n\t\tif (!specResult.loaded) {\n\t\t\tthrow new Error(specResult.errorMessage);\n\t\t}\n\n\t\tconst { spec } = specResult;\n\n\t\tconst newUri = uri || spec[\"$id\"];\n\t\tif (typeof newUri !== \"string\") {\n\t\t\tthrow new Error(\"uri parameter or $id attribute must be a string\");\n\t\t}\n\n\t\tspec[\"$id\"] = newUri;\n\t\tthis.externalRefs[newUri] = spec;\n\t}\n\n\t/** @type {ValidatorDecl['validate']} */\n\tasync validate(data) {\n\t\tconst specResult = await loadSpecFromData(data);\n\n\t\tif (!specResult.loaded) {\n\t\t\treturn {\n\t\t\t\tvalid: false,\n\t\t\t\terrors: specResult.errorMessage,\n\t\t\t};\n\t\t}\n\t\tconst { spec: specification } = specResult;\n\t\tthis.specification = specification;\n\n\t\tif (Object.keys(this.externalRefs).length > 0) {\n\t\t\tspecification[inlinedRefs] = this.externalRefs;\n\t\t}\n\t\tconst { version, specificationType, specificationVersion } =\n\t\t\tgetOpenApiVersion(specification);\n\t\tthis.version = version;\n\t\tthis.specificationVersion = specificationVersion;\n\t\tthis.specificationType = specificationType;\n\t\tif (!version) {\n\t\t\treturn {\n\t\t\t\tvalid: false,\n\t\t\t\terrors:\n\t\t\t\t\t\"Cannot find supported swagger/openapi version in specification, version must be a string.\",\n\t\t\t};\n\t\t}\n\t\tconst validateSchema = this.getAjvValidator(version);\n\t\t// check if the specification matches the JSONschema\n\t\tconst schemaResult = validateSchema(specification);\n\t\t// check if the references are valid as those can't be validated bu JSONschema\n\t\tif (schemaResult) {\n\t\t\treturn checkRefs(specification);\n\t\t}\n\n\t\t/** @type {Awaited<ReturnType<ValidatorDecl['validate']>>} */\n\t\tconst result = {\n\t\t\tvalid: false,\n\t\t};\n\n\t\tif (validateSchema.errors) {\n\t\t\tresult.errors = validateSchema.errors;\n\t\t}\n\n\t\treturn result;\n\t}\n\n\t/** @type {ValidatorDecl['validateBundle']} */\n\tasync validateBundle(data) {\n\t\tif (!Array.isArray(data)) {\n\t\t\treturn {\n\t\t\t\tvalid: false,\n\t\t\t\terrors: \"Parameter data must be an array\",\n\t\t\t};\n\t\t}\n\n\t\t/** @type {SpecFromData | undefined} */\n\t\tlet specification;\n\n\t\tfor (const item of data) {\n\t\t\tconst specResult = await loadSpecFromData(item);\n\t\t\tif (!specResult.loaded) {\n\t\t\t\tthrow new Error(specResult.errorMessage);\n\t\t\t}\n\n\t\t\tconst { spec, fileName } = specResult;\n\t\t\tconst { version } = getOpenApiVersion(spec);\n\t\t\tif (!version) {\n\t\t\t\tconst uri = /** @type {string} */ (spec[\"$id\"] || fileName);\n\t\t\t\t// it is not the main openApi specification, but a sub-schema\n\t\t\t\tthis.addSpecRef(spec, uri);\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif (specification) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t\"Only one openApi specification can be validated at a time\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tspecification = spec;\n\t\t}\n\t\treturn this.validate(/** @type {SpecFromData} */ (specification));\n\t}\n\n\t/**\n\t * @param {string} version\n\t * @returns {ReturnType<AjvCore['compile']>}\n\t */\n\tgetAjvValidator(version) {\n\t\tif (!this.ajvValidators[version]) {\n\t\t\tconst schema = importJSON(`./schemas/v${version}/schema.json`);\n\t\t\tconst schemaVersion = schema.$schema;\n\t\t\tconst AjvClass = /** @type {AjvCoreConstructor} */ (\n\t\t\t\tajvVersions[schemaVersion]\n\t\t\t);\n\t\t\tconst ajv = new AjvClass(this.ajvOptions);\n\t\t\taddFormats(ajv);\n\t\t\tajv.addFormat(\"media-range\", true); // used in 3.1\n\t\t\tthis.ajvValidators[version] = ajv.compile(schema);\n\t\t}\n\t\treturn this.ajvValidators[version];\n\t}\n}\n"]}