From c91dacee2771f6ddee7ed68cce3cde67efe67aac Mon Sep 17 00:00:00 2001 From: Bartosz Michalik Date: Tue, 26 Sep 2023 15:33:31 +0200 Subject: [PATCH 1/6] Opening validator for extensions. to provide own validator and/or spec postprocessor --- dist/Dockerfile | 7 ------- dist/cli.js | 2 +- dist/cli.js.map | 2 +- dist/index.js | 2 +- dist/index.js.map | 2 +- src/index.js | 31 +++++++++++++++++++------------ src/validator.js | 4 ++-- 7 files changed, 25 insertions(+), 25 deletions(-) delete mode 100644 dist/Dockerfile diff --git a/dist/Dockerfile b/dist/Dockerfile deleted file mode 100644 index 83d1572..0000000 --- a/dist/Dockerfile +++ /dev/null @@ -1,7 +0,0 @@ -FROM node:18.16.0-alpine3.17 - -RUN npm install -g openapi-examples-validator@5.0.0 - -ENV NODE_OPTIONS="--unhandled-rejections=strict" -ENTRYPOINT ["openapi-examples-validator"] -CMD ["--help"] \ No newline at end of file diff --git a/dist/cli.js b/dist/cli.js index 1e7dddd..22c4cf7 100644 --- a/dist/cli.js +++ b/dist/cli.js @@ -1,3 +1,3 @@ #!/usr/bin/env node -(()=>{var e={831:(e,t,r)=>{const a=r(981),{ENOENT:o}=r(373).code,s={jsENOENT:o.code,jsonPathNotFound:"JsonPathNotFound",errorAndErrorsMutuallyExclusive:"ErrorErrorsMutuallyExclusive",parseError:"ParseError",validation:"Validation"};class n{static create(e){const{code:t,message:r,path:o,cause:i}=e,p=t||e.type||s.validation,l={message:r};return s.validation===p||s.errorAndErrorsMutuallyExclusive===p?a(l,e):(o&&a(l,{params:{path:o}}),i&&a(l,i)),new n(p,l)}constructor(e,t={}){Object.assign(this,{type:e,...t})}}e.exports={ApplicationError:n,ErrorType:s}},339:(e,t,r)=>{const a=r(156).version,o=r(304),{validateFile:s,validateExample:n,validateExamplesByMap:i}=r(579),p="true"===process.env.OPENAPI_EXAMPLES_VALIDATOR_TESTS;o.version(a).arguments("").description("Validate embedded examples in OpenAPI-specs (JSON and YAML supported).\n To validate external examples, use the `-s` and `-e` option.\n To pass a mapping-file, to validate multiple external examples, use the `-m` option.").option("-s, --schema-jsonpath ","Path to OpenAPI-schema, to validate the example file against").option("-e, --example-filepath ","file path to example file, to be validated").option("-m, --mapping-filepath ","file path to map, containing schema-paths as key and the file-path(s) to examples as value. If wildcards are used, the parameter has to be put in quotes.").option("-c, --cwd-to-mapping-file","changes to the directory of the mapping-file, before resolving the example's paths. Use this option, if your mapping-files use relative paths for the examples").option("-n, --no-additional-properties","don't allow properties that are not described in the schema").option("-r, --all-properties-required","make all the properties in the schema required").option("-o, --ignore-formats ",'Datatype formats to ignore (to prevent "unknown format" message in the error-console.)').action((async function(e,t){const{schemaJsonpath:r,exampleFilepath:a,mappingFilepath:o,cwdToMappingFile:l,allPropertiesRequired:c}=t,u=!t.additionalProperties,d=function(e){return null!=e&&Array.isArray(e)?1!==e.length||-1===e[0].indexOf("\n")?e:e[0].split("\n").filter((e=>!e.match(/^\s*$/))):e}(t.ignoreFormats);let m;o?(console.log("Validating with mapping file"),m=await i(e,o,{cwdToMappingFile:l,noAdditionalProperties:u,ignoreFormats:d,allPropertiesRequired:c})):r&&a?(console.log("Validating single external example"),m=await n(e,r,a,{noAdditionalProperties:u,ignoreFormats:d,allPropertiesRequired:c})):(console.log("Validating examples"),m=await s(e,{noAdditionalProperties:u,ignoreFormats:d,allPropertiesRequired:c})),function(e){const t=p;if(function(e){const{schemasWithExamples:t,examplesWithoutSchema:r,examplesTotal:a,matchingFilePathsMapping:o}=e,s=[`Schemas with examples found: ${t}`,`Examples without schema found: ${r}`,`Total examples found: ${a}`];null!=o&&s.push(`Matching mapping files found: ${o}`),process.stdout.write(`${s.join("\n")}\n`)}(e.statistics),e.valid)return process.stdout.write("\nNo errors found.\n\n"),void(!t&&process.exit(0));process.stdout.write("\nErrors found.\n\n"),process.stderr.write(JSON.stringify(e.errors,null," ")),!t&&process.exit(1)}(m)})),o.on("--help",(()=>{console.log("\n\n Example for external example-file:\n"),console.log(" $ openapi-examples-validator -s $.paths./.get.responses.200.schema -e example.json openapi-spec.json\n\n")})),e.exports=o.parseAsync(process.argv)},457:e=>{e.exports={parent:"parent",parentProperty:"parentProperty",path:"path",pointer:"pointer",value:"value"}},884:(e,t,r)=>{const a=r(442),o=r(955),s=/^3\./;e.exports={getImplementation:function(e){return"string"==typeof e.swagger?a:e.openapi&&e.openapi.match(s)?o:null}}},305:(e,t,r)=>{const{applyCallbackToAllObjectModels:a}=r(818);e.exports={setAllPropertiesRequired:function(e,t=[]){a(e,t,(()=>e=>{e.hasOwnProperty("properties")&&(e.required=Object.keys(e.properties))}))}}},818:(e,t,r)=>{const{JSONPath:a}=r(166),o=r(457);function s(e,t,r=o.path,s){return a({json:e,path:t,flatten:!0,resultType:r,callback:s})}e.exports={applyCallbackToAllObjectModels:function(e,t,r){const a=new Set;s(e,"$..schema..").forEach((e=>{(function(e){if(!e.match(/\['properties']$/))return;const t=e.match(/(?{s(e,r).forEach((e=>{for(const r of t)r.startsWith(e)&&t.delete(r)}))}))}(e,a,t);for(const t of a){const a=r(t);s(e,t,o.value,((e,t,r)=>{var o;("object"===(o=e).type||o.properties)&&a(e,t,r)}))}}}},257:(e,t,r)=>{const{applyCallbackToAllObjectModels:a}=r(818);e.exports={setNoAdditionalProperties:function(e,t=[]){const r=new RegExp("(?t=>{r.test(e)?console.warn(`"additionalProperties" flag not set for ${e} because it has a parent with a JSON-schema combiner keyword.`):o.some((e=>t.hasOwnProperty(e)))?console.warn(`"additionalProperties" flag not set for ${e} because it contains JSON-schema combiner keyword.`):t.hasOwnProperty("additionalProperties")||(t.additionalProperties=!1)}))}};const o=["oneOf","allOf","anyOf","not"]},442:(e,t,r)=>{const{JSONPath:a}=r(166),o=r(548),{setAllPropertiesRequired:s}=r(305),{setNoAdditionalProperties:n}=r(257);function i(){return["$..examples.application/json"]}e.exports={buildValidationMap:function(e){return e.reduce(((e,t)=>{const r=function(e){const t=a.toPathArray(e).slice(),r=t.lastIndexOf("examples");return t.splice(r,t.length-r,"schema"),a.toPathString(t)}(t);return e[r]=(e[r]||new Set).add(t),e}),{})},escapeExampleName:function(e){return e},getJsonPathsToExamples:i,prepare:function(e,{noAdditionalProperties:t,allPropertiesRequired:r}={}){const a=o(e);return t&&n(a,["$..examples.application/json"]),r&&s(a,["$..examples.application/json"]),a},unescapeExampleNames:function(e){return e}}},955:(e,t,r)=>{const{JSONPath:a}=r(166),o=r(548),{ApplicationError:s,ErrorType:n}=r(831),{setAllPropertiesRequired:i}=r(305),{setNoAdditionalProperties:p}=r(257),l="single",c="multi";function u(){return["$..responses..content.application/json.example","$..responses..content.application/json.examples.*.value","$..parameters..example","$..parameters..examples.*.value","$..requestBody.content.application/json.example","$..requestBody.content.application/json.examples.*.value"]}e.exports={buildValidationMap:function(e){const t=new Map;return e.reduce(((e,r)=>{const{pathSchemaAsArray:o,exampleType:i}=function(e){const t=a.toPathArray(e).slice(),r=t.lastIndexOf("example"),o=r>-1?l:c,s=o===l?r:t.lastIndexOf("examples");return t.splice(s,t.length-s,"schema"),{exampleType:o,pathSchemaAsArray:t}}(r),p=a.toPathString(o),u=t.get(p);return u&&u!==i&&function(e){const t=e.slice(0,e.length-1);throw s.create({type:n.errorAndErrorsMutuallyExclusive,message:'Properties "error" and "errors" are mutually exclusive',params:{pathContext:a.toPointer(t)}})}(o),t.set(p,i),e[p]=(e[p]||new Set).add(r),e}),{})},escapeExampleName:function(e){return e.replace(/\['examples'\]\['(.*)\]\['value'\]$/,"['examples']['`$1]['value']")},getJsonPathsToExamples:u,prepare:function(e,{noAdditionalProperties:t,allPropertiesRequired:r}={}){const a=o(e);return t&&p(a,["$..responses..content.application/json.example","$..responses..content.application/json.examples.*.value","$..parameters..example","$..parameters..examples.*.value","$..requestBody.content.application/json.example","$..requestBody.content.application/json.examples.*.value"]),r&&i(a,["$..responses..content.application/json.example","$..responses..content.application/json.examples.*.value","$..parameters..example","$..parameters..examples.*.value","$..requestBody.content.application/json.example","$..requestBody.content.application/json.examples.*.value"]),a},unescapeExampleNames:function(e){return e&&e.replace(/\/examples\/`(.*)\/value$/,"/examples/$1/value")}}},579:(e,t,r)=>{const a=r(981),o=r(760),s=r(574),n=r(147),i=r(17),p=r(230),l=r(66),{JSONPath:c}=r(166),u=r(432),{createError:d}=r(373).custom,m=r(457),{getValidatorFactory:h,compileValidate:f}=r(239),x=r(884),{ApplicationError:g,ErrorType:y}=r(831),{createValidationResponse:v,dereferenceJsonSchema:P}=r(903),b=Symbol("internal"),j="schemasWithExamples",w=["yaml","yml"],E=d(y.jsonPathNotFound);async function $(e,{noAdditionalProperties:t,ignoreFormats:r,allPropertiesRequired:a}={}){const o=x.getImplementation(e);e=await u.dereference(e),e=o.prepare(e,{noAdditionalProperties:t,allPropertiesRequired:a});let s=o.getJsonPathsToExamples().reduce(((t,r)=>t.concat(function(e,t){return c({json:e,path:t,resultType:m.path})}(e,r))),[]).map(o.escapeExampleName);return function({impl:e},t,r,{ignoreFormats:a}){const o=S(),s={valid:!0,statistics:o,errors:[]},n=k(r,{ignoreFormats:a});let i;try{i=e.buildValidationMap(t)}catch(e){if(!(e instanceof g))throw e;return s.valid=!1,s.errors.push(e),s}return Object.keys(i).forEach((e=>{!function({openapiSpec:e,createValidator:t,pathSchema:r,validationMap:a,statistics:o,validationResult:s}){const n=s.errors;a[r].forEach((a=>{const i=F(a,e),p=T(r,e,!0),l=N({createValidator:t,schema:p,example:i,statistics:o}).map((e=>(e.examplePath=c.toPointer(c.toPathArray(a)),e)));l.length&&(s.valid=!1,n.splice(n.length-1,0,...l))}))}({openapiSpec:r,createValidator:n,pathSchema:e,validationMap:i,statistics:o,validationResult:s})})),s.errors.forEach((t=>{t.examplePath=e.unescapeExampleNames(t.examplePath)})),s}({impl:o},s,e,{ignoreFormats:r})}async function A(e){const t=function(e){const t=e.split(".").pop();return w.includes(t)}(e);let r;if(t)try{r=l.parse(n.readFileSync(e,"utf-8"))}catch(e){const{name:t,message:r}=e;throw new g(y.parseError,{message:`${t}: ${r}`})}else r=JSON.parse(n.readFileSync(e,"utf-8"));return await P(e,r)}function q(e){const t=S(),r=e(t);return v({errors:r,statistics:t})}function O(e,t,r,{cwdToMappingFile:a=!1,dirPathMapExternalExamples:l,ignoreFormats:c}){return s(Object.entries(t),(([t,u])=>{let d=null;try{d=T(t,e)}catch(e){return g.create(e)}return s(o([u]),(t=>{let o=[];try{const e=a?i.join(l,t):t,r=p.sync(e);if(0===r.length)return[g.create({type:y.jsENOENT,message:`No such file or directory: '${e}'`,path:e})];for(const e of r)o.push({path:i.normalize(e),content:JSON.parse(n.readFileSync(e,"utf-8"))})}catch(e){return[g.create(e)]}return s(o,(t=>N({createValidator:k(e,{ignoreFormats:c}),schema:d,example:t.content,statistics:r,filePathExample:t.path})))}))}))}function S(){const e={[b]:{[j]:new Set},examplesTotal:0,examplesWithoutSchema:0};return Object.defineProperty(e,j,{enumerable:!0,get:()=>e[b][j].size}),e}function F(e,t){return c({json:t,path:e,flatten:!0,wrap:!1,resultType:m.value})}function N({createValidator:e,schema:t,example:r,statistics:a,filePathExample:o}){const s=[];if(a.examplesTotal++,!t)return a.examplesWithoutSchema++,s;a[b][j].add(t);const n=f(e(),t);return n(r)?s:s.concat(...n.errors.map(g.create)).map((e=>o?(e.exampleFilePath=o,e):e))}function k(e,{ignoreFormats:t}){return h(e,{schemaId:"auto",discriminator:!0,strict:!1,allErrors:!0,formats:t&&t.reduce(((e,t)=>(e[t]=()=>!0,e)),{})})}function T(e,t,r=!1){const a=F(e,t);if(!r&&!a)throw new E(`Path to schema can't be found: '${e}'`,{params:{path:e}});return a}e.exports={default:$,validateFile:async function(e,{noAdditionalProperties:t,ignoreFormats:r,allPropertiesRequired:a}={}){let o=null;try{o=await A(e)}catch(e){return v({errors:[g.create(e)]})}return $(o,{noAdditionalProperties:t,ignoreFormats:r,allPropertiesRequired:a})},validateExample:async function(e,t,r,{noAdditionalProperties:a,ignoreFormats:o,allPropertiesRequired:s}={}){let i=null,p=null,l=null;try{i=JSON.parse(n.readFileSync(r,"utf-8")),l=await A(e),l=x.getImplementation(l).prepare(l,{noAdditionalProperties:a,allPropertiesRequired:s}),p=T(t,l)}catch(e){return v({errors:[g.create(e)]})}return q((e=>N({createValidator:k(l,{ignoreFormats:o}),schema:p,example:i,statistics:e,filePathExample:r})))},validateExamplesByMap:async function(e,t,{cwdToMappingFile:r,noAdditionalProperties:o,ignoreFormats:s,allPropertiesRequired:l}={}){let c=0;const u=p.sync(t,{nonull:!0});let d=[];for(const t of u){let a=null,p=null;try{a=JSON.parse(n.readFileSync(t,"utf-8")),p=await A(e),p=x.getImplementation(p).prepare(p,{noAdditionalProperties:o,allPropertiesRequired:l})}catch(e){d.push(v({errors:[g.create(e)]}));continue}c++,d.push(q((e=>O(p,a,e,{cwdToMappingFile:r,dirPathMapExternalExamples:i.dirname(t),ignoreFormats:s}).map((e=>Object.assign(e,{mapFilePath:i.normalize(t)}))))))}return a(d.reduce(((e,t)=>{return e?(a=t,v({errors:(r=e).errors.concat(a.errors),statistics:Object.entries(r.statistics).reduce(((e,[t,o])=>j===t?([r,a].forEach((t=>{const r=t.statistics[b][j].values();for(let t of r)e[b][j].add(t)})),e):(e[t]=o+a.statistics[t],e)),S())})):t;var r,a}),null),{statistics:{matchingFilePathsMapping:c}})}}},903:(e,t,r)=>{const a=r(17),o=r(432);e.exports={createValidationResponse:function({errors:e,statistics:t={}}){return{valid:!e.length,statistics:t,errors:e}},dereferenceJsonSchema:async function(e,t){const r=process.cwd();process.chdir(a.dirname(e));const s=await o.dereference(t);return process.chdir(r),s}}},239:(e,t,r)=>{const{JSONPath:a}=r(166),o=r(125),s=r(643),n=r(638),i="$..$ref",p="https://www.npmjs.com/package/openapi-examples-validator/defs.json";e.exports={getValidatorFactory:function(e,t){const r=function(e){const t={$id:p};return a({path:i,json:e,callback(r){if(!r.startsWith("#"))return;const a=r.substring(1),s=o.get(e,a);o.set(t,a,s)}}),t}(e);return()=>{const e=new s(t);return n(e),e.addSchema(r),e}},compileValidate:function(e,t){const r=function(e,t){const r=Object.assign({},e);return r.$id="https://www.npmjs.com/package/openapi-examples-validator/schema.json",r}(t);let o;a({path:i,json:r,callback(e,t,r){e.startsWith("#")&&(r.parent[r.parentProperty]=`${p}${e}`)}});try{o=e.compile(r)}catch(e){o=()=>{},o.errors=[e]}return o}}},156:e=>{e.exports={name:"openapi-examples-validator",version:"5.0.0",description:"Validates embedded examples in OpenAPI-JSONs",main:"dist/index.js",engines:{node:">=16"},bin:{"openapi-examples-validator":"dist/cli.js"},"standard-version":{scripts:{postchangelog:"npm run release:create-dockerfile && npm run release:stage-artifacts"}},scripts:{"start-dev":"babel-node src/cli",build:"npm run build:clean && npm run build:webpack","build:clean":"rimraf dist","build:webpack":"webpack --bail --progress --profile --mode production --config ./webpack/config.babel.js",coverage:'rimraf ./coverage && nyc --reporter=lcov --reporter=text -x "dist/**/*" -x "test/**/*.js" npm test',coveralls:"cat ./coverage/lcov.info | coveralls",test:"npm run build && npm run test:mocha","test-mutations":"stryker run","test:mocha":'mocha --require "./test/util/setup-tests" --recursive "./test/specs/**/*.js"',release:"npm run build && standard-version -a","release:create-dockerfile":"npm run build && node etc/src/build-dockerfile.js","release:stage-artifacts":"git add dist/*"},repository:{type:"git",url:"git+https://github.com/codekie/openapi-examples-validator.git"},keywords:["swagger","openapi","json","validate","examples"],author:"Josua Amann",license:"MIT",bugs:{url:"https://github.com/codekie/openapi-examples-validator/issues"},homepage:"https://github.com/codekie/openapi-examples-validator#readme",devDependencies:{"@babel/cli":"^7.21.5","@babel/core":"^7.21.8","@babel/eslint-parser":"^7.21.8","@babel/node":"^7.20.7","@babel/preset-env":"^7.21.5","@babel/register":"^7.21.0","@stryker-mutator/core":"^6.4.2","@stryker-mutator/mocha-runner":"^6.4.2","babel-loader":"^9.1.2",chai:"^4.3.6","core-js-pure":"^3.30.2",coveralls:"^3.1.1",eslint:"^8.41.0","eslint-webpack-plugin":"^4.0.1","json-loader":"^0.5.7",mocha:"^10.2.0","mocha-lcov-reporter":"^1.3.0",nyc:"^15.1.0",rimraf:"^5.0.1","standard-version":"^9.5.0","stryker-cli":"^1.0.2",webpack:"^5.83.1","webpack-cli":"^5.1.1"},dependencies:{ajv:"^8.12.0","ajv-draft-04":"^1.0.0","ajv-formats":"^2.1.1",commander:"^6.2.1",errno:"^1.0.0",glob:"^8.1.0","json-pointer":"^0.6.2","json-schema-ref-parser":"^9.0.9","jsonpath-plus":"^7.2.0","lodash.clonedeep":"^4.5.0","lodash.flatmap":"^4.5.0","lodash.flatten":"^4.4.0","lodash.merge":"^4.6.2",yaml:"^2.2.2"}}},643:e=>{"use strict";e.exports=require("ajv-draft-04")},638:e=>{"use strict";e.exports=require("ajv-formats")},304:e=>{"use strict";e.exports=require("commander")},373:e=>{"use strict";e.exports=require("errno")},230:e=>{"use strict";e.exports=require("glob")},125:e=>{"use strict";e.exports=require("json-pointer")},432:e=>{"use strict";e.exports=require("json-schema-ref-parser")},166:e=>{"use strict";e.exports=require("jsonpath-plus")},548:e=>{"use strict";e.exports=require("lodash.clonedeep")},574:e=>{"use strict";e.exports=require("lodash.flatmap")},760:e=>{"use strict";e.exports=require("lodash.flatten")},981:e=>{"use strict";e.exports=require("lodash.merge")},66:e=>{"use strict";e.exports=require("yaml")},147:e=>{"use strict";e.exports=require("fs")},17:e=>{"use strict";e.exports=require("path")}},t={},r=function r(a){var o=t[a];if(void 0!==o)return o.exports;var s=t[a]={exports:{}};return e[a](s,s.exports,r),s.exports}(339);module.exports=r})(); +(()=>{var e={831:(e,t,r)=>{const a=r(981),{ENOENT:o}=r(373).code,s={jsENOENT:o.code,jsonPathNotFound:"JsonPathNotFound",errorAndErrorsMutuallyExclusive:"ErrorErrorsMutuallyExclusive",parseError:"ParseError",validation:"Validation"};class n{static create(e){const{code:t,message:r,path:o,cause:i}=e,p=t||e.type||s.validation,l={message:r};return s.validation===p||s.errorAndErrorsMutuallyExclusive===p?a(l,e):(o&&a(l,{params:{path:o}}),i&&a(l,i)),new n(p,l)}constructor(e,t={}){Object.assign(this,{type:e,...t})}}e.exports={ApplicationError:n,ErrorType:s}},339:(e,t,r)=>{const a=r(156).version,o=r(304),{validateFile:s,validateExample:n,validateExamplesByMap:i}=r(579),p="true"===process.env.OPENAPI_EXAMPLES_VALIDATOR_TESTS;o.version(a).arguments("").description("Validate embedded examples in OpenAPI-specs (JSON and YAML supported).\n To validate external examples, use the `-s` and `-e` option.\n To pass a mapping-file, to validate multiple external examples, use the `-m` option.").option("-s, --schema-jsonpath ","Path to OpenAPI-schema, to validate the example file against").option("-e, --example-filepath ","file path to example file, to be validated").option("-m, --mapping-filepath ","file path to map, containing schema-paths as key and the file-path(s) to examples as value. If wildcards are used, the parameter has to be put in quotes.").option("-c, --cwd-to-mapping-file","changes to the directory of the mapping-file, before resolving the example's paths. Use this option, if your mapping-files use relative paths for the examples").option("-n, --no-additional-properties","don't allow properties that are not described in the schema").option("-r, --all-properties-required","make all the properties in the schema required").option("-o, --ignore-formats ",'Datatype formats to ignore (to prevent "unknown format" message in the error-console.)').action((async function(e,t){const{schemaJsonpath:r,exampleFilepath:a,mappingFilepath:o,cwdToMappingFile:l,allPropertiesRequired:c}=t,u=!t.additionalProperties,d=function(e){return null!=e&&Array.isArray(e)?1!==e.length||-1===e[0].indexOf("\n")?e:e[0].split("\n").filter((e=>!e.match(/^\s*$/))):e}(t.ignoreFormats);let m;o?(console.log("Validating with mapping file"),m=await i(e,o,{cwdToMappingFile:l,noAdditionalProperties:u,ignoreFormats:d,allPropertiesRequired:c})):r&&a?(console.log("Validating single external example"),m=await n(e,r,a,{noAdditionalProperties:u,ignoreFormats:d,allPropertiesRequired:c})):(console.log("Validating examples"),m=await s(e,{noAdditionalProperties:u,ignoreFormats:d,allPropertiesRequired:c})),function(e){const t=p;if(function(e){const{schemasWithExamples:t,examplesWithoutSchema:r,examplesTotal:a,matchingFilePathsMapping:o}=e,s=[`Schemas with examples found: ${t}`,`Examples without schema found: ${r}`,`Total examples found: ${a}`];null!=o&&s.push(`Matching mapping files found: ${o}`),process.stdout.write(`${s.join("\n")}\n`)}(e.statistics),e.valid)return process.stdout.write("\nNo errors found.\n\n"),void(!t&&process.exit(0));process.stdout.write("\nErrors found.\n\n"),process.stderr.write(JSON.stringify(e.errors,null," ")),!t&&process.exit(1)}(m)})),o.on("--help",(()=>{console.log("\n\n Example for external example-file:\n"),console.log(" $ openapi-examples-validator -s $.paths./.get.responses.200.schema -e example.json openapi-spec.json\n\n")})),e.exports=o.parseAsync(process.argv)},457:e=>{e.exports={parent:"parent",parentProperty:"parentProperty",path:"path",pointer:"pointer",value:"value"}},884:(e,t,r)=>{const a=r(442),o=r(955),s=/^3\./;e.exports={getImplementation:function(e){return"string"==typeof e.swagger?a:e.openapi&&e.openapi.match(s)?o:null}}},305:(e,t,r)=>{const{applyCallbackToAllObjectModels:a}=r(818);e.exports={setAllPropertiesRequired:function(e,t=[]){a(e,t,(()=>e=>{e.hasOwnProperty("properties")&&(e.required=Object.keys(e.properties))}))}}},818:(e,t,r)=>{const{JSONPath:a}=r(166),o=r(457);function s(e,t,r=o.path,s){return a({json:e,path:t,flatten:!0,resultType:r,callback:s})}e.exports={applyCallbackToAllObjectModels:function(e,t,r){const a=new Set;s(e,"$..schema..").forEach((e=>{(function(e){if(!e.match(/\['properties']$/))return;const t=e.match(/(?{s(e,r).forEach((e=>{for(const r of t)r.startsWith(e)&&t.delete(r)}))}))}(e,a,t);for(const t of a){const a=r(t);s(e,t,o.value,((e,t,r)=>{var o;("object"===(o=e).type||o.properties)&&a(e,t,r)}))}}}},257:(e,t,r)=>{const{applyCallbackToAllObjectModels:a}=r(818);e.exports={setNoAdditionalProperties:function(e,t=[]){const r=new RegExp("(?t=>{r.test(e)?console.warn(`"additionalProperties" flag not set for ${e} because it has a parent with a JSON-schema combiner keyword.`):o.some((e=>t.hasOwnProperty(e)))?console.warn(`"additionalProperties" flag not set for ${e} because it contains JSON-schema combiner keyword.`):t.hasOwnProperty("additionalProperties")||(t.additionalProperties=!1)}))}};const o=["oneOf","allOf","anyOf","not"]},442:(e,t,r)=>{const a=r(548),{setAllPropertiesRequired:o}=r(305),{setNoAdditionalProperties:s}=r(257);function n(){return["$..examples[?(@property.match(/[/+]json/))]"]}e.exports={buildValidationMap:function(e){return e.reduce(((e,t)=>{const r=function(e){const t=e.split("/"),r=t.lastIndexOf("examples");return t.splice(r,t.length-r,"schema"),t.join("/")}(t);return e[r]=(e[r]||new Set).add(t),e}),{})},getJsonPathsToExamples:n,prepare:function(e,{noAdditionalProperties:t,allPropertiesRequired:r}={}){const n=a(e);return t&&s(n,["$..examples[?(@property.match(/[/+]json/))]"]),r&&o(n,["$..examples[?(@property.match(/[/+]json/))]"]),n}}},955:(e,t,r)=>{const a=r(548),{ApplicationError:o,ErrorType:s}=r(831),{setAllPropertiesRequired:n}=r(305),{setNoAdditionalProperties:i}=r(257),p="$..responses..content[?(@property.match(/[/+]json/))]",l="$..requestBody.content[?(@property.match(/[/+]json/))]",c=".example",u=".examples.*.value",d=`${p}${c}`,m=`${p}${u}`,h=`${l}${c}`,f=`${l}${u}`,g="single",x="multi";function y(){return[d,m,"$..parameters..example","$..parameters..examples.*.value",h,f]}e.exports={buildValidationMap:function(e){const t=new Map;return e.reduce(((e,r)=>{const{pathSchemaAsArray:a,exampleType:n}=function(e){const t=e.split("/"),r=t.lastIndexOf("example"),a=r>-1?g:x,o=a===g?r:t.lastIndexOf("examples");return t.splice(o,t.length-o,"schema"),{exampleType:a,pathSchemaAsArray:t}}(r),i=a.join("/"),p=t.get(i);return p&&p!==n&&function(e){const t=e.slice(0,e.length-1);throw o.create({type:s.errorAndErrorsMutuallyExclusive,message:'Properties "error" and "errors" are mutually exclusive',params:{pathContext:t.join("/")}})}(a),t.set(i,n),e[i]=(e[i]||new Set).add(r),e}),{})},getJsonPathsToExamples:y,prepare:function(e,{noAdditionalProperties:t,allPropertiesRequired:r}={}){const o=a(e);return t&&i(o,y()),r&&n(o,y()),o}}},579:(e,t,r)=>{const a=r(981),o=r(760),s=r(574),n=r(125),i=r(147),p=r(17),l=r(230),c=r(66),{JSONPath:u}=r(166),d=r(432),{createError:m}=r(373).custom,h=r(457),{getValidatorFactory:f,compileValidate:g}=r(239),x=r(884),{ApplicationError:y,ErrorType:v}=r(831),{createValidationResponse:P,dereferenceJsonSchema:b}=r(903),w=Symbol("internal"),j="schemasWithExamples",E=["yaml","yml"],A=m(v.jsonPathNotFound);async function F(e,{noAdditionalProperties:t,ignoreFormats:r,allPropertiesRequired:a,specPostprocessor:o=(e=>e),validatorFactory:s=((e,{ignoreFormats:t})=>V(e,{ignoreFormats:t}))}={}){const n=x.getImplementation(e);e=await d.dereference(e),e=n.prepare(e,{noAdditionalProperties:t,allPropertiesRequired:a}),"function"==typeof o&&(e=o(e));let i=n.getJsonPathsToExamples().reduce(((t,r)=>t.concat(S(e,r))),[]).map(n.escapeExampleName);return function({impl:e,createValidator:t},r,a){const o=T(),s={valid:!0,statistics:o,errors:[]};let n;try{n=e.buildValidationMap(r)}catch(e){if(!(e instanceof y))throw e;return s.valid=!1,s.errors.push(e),s}return Object.keys(n).forEach((e=>{!function({openapiSpec:e,createValidator:t,schemaPointer:r,validationMap:a,statistics:o,validationResult:s}){const n=s.errors;a[r].forEach((a=>{const i=N(a,e),p=R(r,e,!0),l=M({createValidator:t,schema:p,example:i,statistics:o}).map((e=>(e.examplePath=a,e)));l.length&&(s.valid=!1,n.splice(n.length-1,0,...l))}))}({openapiSpec:a,createValidator:t,schemaPointer:e,validationMap:n,statistics:o,validationResult:s})})),s}({impl:n,createValidator:s(e,{ignoreFormats:r})},i,e)}async function O(e){const t=function(e){const t=e.split(".").pop();return E.includes(t)}(e);let r;if(t)try{r=c.parse(i.readFileSync(e,"utf-8"))}catch(e){const{name:t,message:r}=e;throw new y(v.parseError,{message:`${t}: ${r}`})}else r=JSON.parse(i.readFileSync(e,"utf-8"));return await b(e,r)}function q(e){const t=T(),r=e(t);return P({errors:r,statistics:t})}function $(e,t,r,{cwdToMappingFile:a=!1,dirPathMapExternalExamples:n,ignoreFormats:c}){return s(Object.entries(t),(([t,u])=>{let d=null;try{d=R(k(t,e),e)}catch(e){return y.create(e)}return s(o([u]),(t=>{let o=[];try{const e=a?p.join(n,t):t,r=l.sync(e);if(0===r.length)return[y.create({type:v.jsENOENT,message:`No such file or directory: '${e}'`,path:e})];for(const e of r)o.push({path:p.normalize(e),content:JSON.parse(i.readFileSync(e,"utf-8"))})}catch(e){return[y.create(e)]}return s(o,(t=>M({createValidator:V(e,{ignoreFormats:c}),schema:d,example:t.content,statistics:r,filePathExample:t.path})))}))}))}function S(e,t){return u({json:t,path:e,resultType:h.pointer})}function k(e,t){const r=S(e,t);return 0===r.length&&J(e),r.length>1?[y.create({type:v.jsonPathNotFound,message:`Path to schema cannot identify unique schema: '${e}'`,path:e})]:r[0]}function T(){const e={[w]:{[j]:new Set},examplesTotal:0,examplesWithoutSchema:0};return Object.defineProperty(e,j,{enumerable:!0,get:()=>e[w][j].size}),e}function N(e,t){try{return n.get(t,e)}catch(e){return}}function M({createValidator:e,schema:t,example:r,statistics:a,filePathExample:o}){const s=[];if(a.examplesTotal++,!t)return a.examplesWithoutSchema++,s;a[w][j].add(t);const n=g(e(),t);return n(r)?s:s.concat(...n.errors.map(y.create)).map((e=>o?(e.exampleFilePath=o,e):e))}function V(e,{ignoreFormats:t}){return f(e,{schemaId:"auto",discriminator:!0,strict:!1,allErrors:!0,formats:t&&t.reduce(((e,t)=>(e[t]=()=>!0,e)),{})})}function R(e,t,r=!1){const a=N(e,t);return r||a||J(e),a}function J(e){throw new A(`Path to schema can't be found: '${e}'`,{params:{path:e}})}e.exports={default:F,validateFile:async function(e,{noAdditionalProperties:t,ignoreFormats:r,allPropertiesRequired:a}={}){let o=null;try{o=await O(e)}catch(e){return P({errors:[y.create(e)]})}return F(o,{noAdditionalProperties:t,ignoreFormats:r,allPropertiesRequired:a})},validateExample:async function(e,t,r,{noAdditionalProperties:a,ignoreFormats:o,allPropertiesRequired:s}={}){let n=null,p=null,l=null;try{n=JSON.parse(i.readFileSync(r,"utf-8")),l=await O(e),l=x.getImplementation(l).prepare(l,{noAdditionalProperties:a,allPropertiesRequired:s}),p=R(k(t,l),l)}catch(e){return P({errors:[y.create(e)]})}return q((e=>M({createValidator:V(l,{ignoreFormats:o}),schema:p,example:n,statistics:e,filePathExample:r})))},validateExamplesByMap:async function(e,t,{cwdToMappingFile:r,noAdditionalProperties:o,ignoreFormats:s,allPropertiesRequired:n}={}){let c=0;const u=l.sync(t,{nonull:!0});let d=[];for(const t of u){let a=null,l=null;try{a=JSON.parse(i.readFileSync(t,"utf-8")),l=await O(e),l=x.getImplementation(l).prepare(l,{noAdditionalProperties:o,allPropertiesRequired:n})}catch(e){d.push(P({errors:[y.create(e)]}));continue}c++,d.push(q((e=>$(l,a,e,{cwdToMappingFile:r,dirPathMapExternalExamples:p.dirname(t),ignoreFormats:s}).map((e=>Object.assign(e,{mapFilePath:p.normalize(t)}))))))}return a(d.reduce(((e,t)=>{return e?(a=t,P({errors:(r=e).errors.concat(a.errors),statistics:Object.entries(r.statistics).reduce(((e,[t,o])=>j===t?([r,a].forEach((t=>{const r=t.statistics[w][j].values();for(let t of r)e[w][j].add(t)})),e):(e[t]=o+a.statistics[t],e)),T())})):t;var r,a}),null),{statistics:{matchingFilePathsMapping:c}})},getValidatorFactory:f}},903:(e,t,r)=>{const a=r(17),o=r(432);e.exports={createValidationResponse:function({errors:e,statistics:t={}}){return{valid:!e.length,statistics:t,errors:e}},dereferenceJsonSchema:async function(e,t){const r=process.cwd();process.chdir(a.dirname(e));const s=await o.dereference(t);return process.chdir(r),s}}},239:(e,t,r)=>{const{JSONPath:a}=r(166),o=r(125),s=r(643),n=r(638),i="$..$ref",p="https://www.npmjs.com/package/openapi-examples-validator/defs.json";e.exports={getValidatorFactory:function(e,t,{provider:r=(e=>new s(e))}){const l=function(e){const t={$id:p};return a({path:i,json:e,callback(r){if(!r.startsWith("#"))return;const a=r.substring(1),s=o.get(e,a);o.set(t,a,s)}}),t}(e);return()=>{const e=r(t);return n(e),e.addSchema(l),e}},compileValidate:function(e,t){const r=function(e,t){const r=Object.assign({},e);return r.$id="https://www.npmjs.com/package/openapi-examples-validator/schema.json",r}(t);let o;a({path:i,json:r,callback(e,t,r){e.startsWith("#")&&(r.parent[r.parentProperty]=`${p}${e}`)}});try{o=e.compile(r)}catch(e){o=()=>{},o.errors=[e]}return o}}},156:e=>{e.exports={name:"openapi-examples-validator",version:"5.0.0",description:"Validates embedded examples in OpenAPI-JSONs",main:"dist/index.js",engines:{node:">=16"},bin:{"openapi-examples-validator":"dist/cli.js"},"standard-version":{scripts:{postchangelog:"npm run release:create-dockerfile && npm run release:stage-artifacts"}},scripts:{"start-dev":"babel-node src/cli",build:"npm run build:clean && npm run build:webpack","build:clean":"rimraf dist","build:webpack":"webpack --bail --progress --profile --mode production --config ./webpack/config.babel.js",coverage:'rimraf ./coverage && nyc --reporter=lcov --reporter=text -x "dist/**/*" -x "test/**/*.js" npm test',coveralls:"cat ./coverage/lcov.info | coveralls",test:"npm run build && npm run test:mocha","test-mutations":"stryker run","test:mocha":'mocha --require "./test/util/setup-tests" --recursive "./test/specs/**/*.js"',release:"npm run build && standard-version -a","release:create-dockerfile":"npm run build && node etc/src/build-dockerfile.js","release:stage-artifacts":"git add dist/*"},repository:{type:"git",url:"git+https://github.com/codekie/openapi-examples-validator.git"},keywords:["swagger","openapi","json","validate","examples"],author:"Josua Amann",license:"MIT",bugs:{url:"https://github.com/codekie/openapi-examples-validator/issues"},homepage:"https://github.com/codekie/openapi-examples-validator#readme",devDependencies:{"@babel/cli":"^7.21.5","@babel/core":"^7.21.8","@babel/eslint-parser":"^7.21.8","@babel/node":"^7.20.7","@babel/preset-env":"^7.21.5","@babel/register":"^7.21.0","@stryker-mutator/core":"^6.4.2","@stryker-mutator/mocha-runner":"^6.4.2","babel-loader":"^9.1.2",chai:"^4.3.6","chai-string":"^1.5.0","core-js-pure":"^3.30.2",coveralls:"^3.1.1",eslint:"^8.41.0","eslint-webpack-plugin":"^4.0.1","json-loader":"^0.5.7",mocha:"^10.2.0","mocha-lcov-reporter":"^1.3.0",nyc:"^15.1.0",rimraf:"^5.0.1","standard-version":"^9.5.0","stryker-cli":"^1.0.2",webpack:"^5.83.1","webpack-cli":"^5.1.1"},dependencies:{ajv:"^8.12.0","ajv-draft-04":"^1.0.0","ajv-formats":"^2.1.1",commander:"^6.2.1",errno:"^1.0.0",glob:"^8.1.0","json-pointer":"^0.6.2","json-schema-ref-parser":"^9.0.9","jsonpath-plus":"^7.2.0","lodash.clonedeep":"^4.5.0","lodash.flatmap":"^4.5.0","lodash.flatten":"^4.4.0","lodash.merge":"^4.6.2",yaml:"^2.2.2"}}},643:e=>{"use strict";e.exports=require("ajv-draft-04")},638:e=>{"use strict";e.exports=require("ajv-formats")},304:e=>{"use strict";e.exports=require("commander")},373:e=>{"use strict";e.exports=require("errno")},230:e=>{"use strict";e.exports=require("glob")},125:e=>{"use strict";e.exports=require("json-pointer")},432:e=>{"use strict";e.exports=require("json-schema-ref-parser")},166:e=>{"use strict";e.exports=require("jsonpath-plus")},548:e=>{"use strict";e.exports=require("lodash.clonedeep")},574:e=>{"use strict";e.exports=require("lodash.flatmap")},760:e=>{"use strict";e.exports=require("lodash.flatten")},981:e=>{"use strict";e.exports=require("lodash.merge")},66:e=>{"use strict";e.exports=require("yaml")},147:e=>{"use strict";e.exports=require("fs")},17:e=>{"use strict";e.exports=require("path")}},t={},r=function r(a){var o=t[a];if(void 0!==o)return o.exports;var s=t[a]={exports:{}};return e[a](s,s.exports,r),s.exports}(339);module.exports=r})(); //# sourceMappingURL=cli.js.map \ No newline at end of file diff --git a/dist/cli.js.map b/dist/cli.js.map index 1f50ed9..2ded30d 100644 --- a/dist/cli.js.map +++ b/dist/cli.js.map @@ -1 +1 @@ -{"version":3,"file":"cli.js","mappings":";2BAAA,MACIA,EAAQC,EAAQ,MAChB,OAAEC,GAAWD,EAAAA,KAAAA,KA6BXE,EAAY,CACdC,SAAUF,EAAOG,KACjBC,iBAAkB,mBAClBC,gCAAiC,+BACjCC,WAAY,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sBAAsB,SAAS,IAAM,UAAU,OAAS,SAAS,mBAAmB,SAAS,cAAc,SAAS,QAAU,UAAU,cAAc,UAAU,aAAe,CAAC,IAAM,UAAU,eAAe,SAAS,cAAc,SAAS,UAAY,SAAS,MAAQ,SAAS,KAAO,SAAS,eAAe,SAAS,yBAAyB,SAAS,gBAAgB,SAAS,mBAAmB,SAAS,iBAAiB,SAAS,iBAAiB,SAAS,eAAe,SAAS,KAAO,U,uBCAn0ED,EAAOC,QAAUvB,QAAQ,e,uBCAzBsB,EAAOC,QAAUvB,QAAQ,c,uBCAzBsB,EAAOC,QAAUvB,QAAQ,Y,uBCAzBsB,EAAOC,QAAUvB,QAAQ,Q,uBCAzBsB,EAAOC,QAAUvB,QAAQ,O,uBCAzBsB,EAAOC,QAAUvB,QAAQ,e,uBCAzBsB,EAAOC,QAAUvB,QAAQ,yB,uBCAzBsB,EAAOC,QAAUvB,QAAQ,gB,uBCAzBsB,EAAOC,QAAUvB,QAAQ,mB,uBCAzBsB,EAAOC,QAAUvB,QAAQ,iB,uBCAzBsB,EAAOC,QAAUvB,QAAQ,iB,uBCAzBsB,EAAOC,QAAUvB,QAAQ,e,sBCAzBsB,EAAOC,QAAUvB,QAAQ,O,uBCAzBsB,EAAOC,QAAUvB,QAAQ,K,sBCAzBsB,EAAOC,QAAUvB,QAAQ,O,GCCrB4R,EAA2B,CAAC,ECE5BC,EDCJ,SAASC,EAAoBC,GAE5B,IAAIC,EAAeJ,EAAyBG,GAC5C,QAAqBE,IAAjBD,EACH,OAAOA,EAAazQ,QAGrB,IAAID,EAASsQ,EAAyBG,GAAY,CAGjDxQ,QAAS,CAAC,GAOX,OAHA2Q,EAAoBH,GAAUzQ,EAAQA,EAAOC,QAASuQ,GAG/CxQ,EAAOC,OACf,CCnB0BuQ,CAAoB,K","sources":["webpack://openapi-examples-validator/./src/application-error.js","webpack://openapi-examples-validator/./src/cli.js","webpack://openapi-examples-validator/./src/const/result-type.js","webpack://openapi-examples-validator/./src/impl/index.js","webpack://openapi-examples-validator/./src/impl/service/all-properties-required.js","webpack://openapi-examples-validator/./src/impl/service/common.js","webpack://openapi-examples-validator/./src/impl/service/no-additional-properties.js","webpack://openapi-examples-validator/./src/impl/v2/index.js","webpack://openapi-examples-validator/./src/impl/v3/index.js","webpack://openapi-examples-validator/./src/index.js","webpack://openapi-examples-validator/./src/utils/index.js","webpack://openapi-examples-validator/./src/validator.js","webpack://openapi-examples-validator/./package.json","webpack://openapi-examples-validator/external commonjs \"ajv-draft-04\"","webpack://openapi-examples-validator/external commonjs \"ajv-formats\"","webpack://openapi-examples-validator/external commonjs \"commander\"","webpack://openapi-examples-validator/external commonjs \"errno\"","webpack://openapi-examples-validator/external commonjs \"glob\"","webpack://openapi-examples-validator/external commonjs \"json-pointer\"","webpack://openapi-examples-validator/external commonjs \"json-schema-ref-parser\"","webpack://openapi-examples-validator/external commonjs \"jsonpath-plus\"","webpack://openapi-examples-validator/external commonjs \"lodash.clonedeep\"","webpack://openapi-examples-validator/external commonjs \"lodash.flatmap\"","webpack://openapi-examples-validator/external commonjs \"lodash.flatten\"","webpack://openapi-examples-validator/external commonjs \"lodash.merge\"","webpack://openapi-examples-validator/external commonjs \"yaml\"","webpack://openapi-examples-validator/external node-commonjs \"fs\"","webpack://openapi-examples-validator/external node-commonjs \"path\"","webpack://openapi-examples-validator/webpack/bootstrap","webpack://openapi-examples-validator/webpack/startup"],"sourcesContent":["const\n merge = require('lodash.merge'),\n { ENOENT } = require('errno').code;\n\n// TYPEDEFINITIONS\n\n/**\n * @typedef {{}} CustomError\n * @augments Error\n */\n\n/**\n * ApplicationErrorOptions\n * @typedef {{\n * [instancePath]: string,\n * [examplePath]: string,\n * [exampleFilePath]: string,\n * [keyword]: string,\n * [message]: string,\n * [mapFilePath]: string,\n * [params]: {\n * [path]: string,\n * [missingProperty]: string,\n * [type]: string\n * },\n * [schemaPath]: string\n * }} ApplicationErrorOptions\n */\n\n// CONSTANTS\n\nconst ErrorType = {\n jsENOENT: ENOENT.code,\n jsonPathNotFound: 'JsonPathNotFound',\n errorAndErrorsMutuallyExclusive: 'ErrorErrorsMutuallyExclusive',\n parseError: 'ParseError',\n validation: 'Validation'\n};\n\n// CLASSES\n\n/**\n * Unified application-error\n */\nclass ApplicationError {\n /**\n * Factory-function, which is able to consume validation-errors and JS-errors. If a validation error is passed, all\n * properties will be adopted.\n * @param {Error|CustomError} err Javascript-, validation- or custom-error, to create the application-error\n * from\n * @returns {ApplicationError} Unified application-error instance\n */\n static create(err) {\n const { code, message, path, cause } = err, // Certain properties of Javascript-errors\n type = code || err.type || ErrorType.validation, // If `code` is available then it's a Javascript-error\n options = { message };\n if (ErrorType.validation === type || ErrorType.errorAndErrorsMutuallyExclusive === type) {\n // For certain, created error-types, copy all properties\n merge(options, err);\n } else {\n // Copy certain properties of Javascript-error (but only if available)\n path && merge(options, { params: { path } });\n cause && merge(options, cause);\n }\n return new ApplicationError(type, options);\n }\n\n /**\n * Constructor\n * @param {string} type Type of error (see statics)\n * @param {ApplicationErrorOptions} [options] Optional properties\n */\n constructor(type, options = {}) {\n Object.assign(this, {\n type,\n ...options\n });\n }\n}\n\n// PUBLIC API\n\nmodule.exports = {\n ApplicationError,\n ErrorType\n};\n","// Shebang will be added by webpack\n//#!/usr/bin/env node --harmony\n\n/**\n * Command Line Interface for the validator\n */\n\nconst\n VERSION = require('../package.json').version,\n program = require('commander'),\n { validateFile, validateExample, validateExamplesByMap } = require('./index');\n\n// FOR AUTOMATED TESTS\n\nconst ENV_TEST = process.env.OPENAPI_EXAMPLES_VALIDATOR_TESTS === 'true';\n\n// DEFINE CLI\n\nprogram\n .version(VERSION)\n .arguments('')\n .description('Validate embedded examples in OpenAPI-specs (JSON and YAML supported).\\n'\n + ' To validate external examples, use the `-s` and `-e` option.\\n'\n + ' To pass a mapping-file, to validate multiple external examples, use the `-m` option.')\n .option('-s, --schema-jsonpath ', 'Path to OpenAPI-schema, to validate the example file against')\n .option('-e, --example-filepath ', 'file path to example file, to be validated')\n .option('-m, --mapping-filepath ', 'file path to map, containing schema-paths as key and the'\n + ' file-path(s) to examples as value. If wildcards are used, the parameter has to be put in quotes.')\n .option('-c, --cwd-to-mapping-file', \"changes to the directory of the mapping-file, before resolving the example's\"\n + ' paths. Use this option, if your mapping-files use relative paths for the examples')\n .option('-n, --no-additional-properties', 'don\\'t allow properties that are not described in the schema')\n .option('-r, --all-properties-required', 'make all the properties in the schema required')\n .option('-o, --ignore-formats ', 'Datatype formats to ignore '\n + '(to prevent \"unknown format\" message in the error-console.)')\n .action(processAction);\nprogram.on('--help', () => {\n console.log('\\n\\n Example for external example-file:\\n');\n console.log(' $ openapi-examples-validator -s $.paths./.get.responses.200.schema -e example.json'\n + ' openapi-spec.json\\n\\n');\n});\n// Execute and export promise (for automated tests)\nmodule.exports = program.parseAsync(process.argv);\n\n// IMPLEMENTATION DETAILS\n\nasync function processAction(filepath, options) {\n const { schemaJsonpath, exampleFilepath, mappingFilepath, cwdToMappingFile, allPropertiesRequired } = options,\n noAdditionalProperties = !options.additionalProperties,\n ignoreFormats = _prepareIgnoreFormats(options.ignoreFormats);\n let result;\n if (mappingFilepath) {\n console.log('Validating with mapping file');\n result = await validateExamplesByMap(filepath, mappingFilepath, {\n cwdToMappingFile,\n noAdditionalProperties,\n ignoreFormats,\n allPropertiesRequired\n });\n } else if (schemaJsonpath && exampleFilepath) {\n console.log('Validating single external example');\n result = await validateExample(filepath, schemaJsonpath, exampleFilepath, {\n noAdditionalProperties,\n ignoreFormats,\n allPropertiesRequired\n });\n } else {\n console.log('Validating examples');\n result = await validateFile(filepath, {\n noAdditionalProperties,\n ignoreFormats,\n allPropertiesRequired\n });\n }\n _handleResult(result);\n}\n\nfunction _handleResult(result) {\n const noExit = ENV_TEST;\n _printStatistics(result.statistics);\n if (result.valid) {\n process.stdout.write('\\nNo errors found.\\n\\n');\n !noExit && process.exit(0);\n return;\n }\n process.stdout.write('\\nErrors found.\\n\\n');\n process.stderr.write(JSON.stringify(result.errors, null, ' '));\n !noExit && process.exit(1);\n}\n\nfunction _printStatistics(statistics) {\n const {\n schemasWithExamples,\n examplesWithoutSchema,\n examplesTotal,\n matchingFilePathsMapping\n } = statistics,\n strStatistics = [\n `Schemas with examples found: ${ schemasWithExamples }`,\n `Examples without schema found: ${ examplesWithoutSchema }`,\n `Total examples found: ${ examplesTotal }`\n ];\n if (matchingFilePathsMapping != null) {\n strStatistics.push(`Matching mapping files found: ${ matchingFilePathsMapping }`);\n }\n process.stdout.write(`${ strStatistics.join('\\n') }\\n`);\n}\n\nfunction _prepareIgnoreFormats(ignoreFormats) {\n if (ignoreFormats == null || !Array.isArray(ignoreFormats)) { return ignoreFormats; }\n if (ignoreFormats.length !== 1) { return ignoreFormats; }\n // If only one argument has been passed, with all formats separated by newlines\n if (ignoreFormats[0].indexOf('\\n') === -1) { return ignoreFormats; }\n return ignoreFormats[0].split('\\n').filter(entry => !entry.match(/^\\s*$/));\n}\n","module.exports = {\n parent: 'parent',\n parentProperty: 'parentProperty',\n path: 'path',\n pointer: 'pointer',\n value: 'value'\n};\n","/**\n * Entry point for logic that only applies to specific versions of the OpenAPI-spec\n */\n\nconst implV2 = require('./v2/index'),\n implV3 = require('./v3/index');\n\nconst REGEX__OPEN_API = /^3\\./;\n\nmodule.exports = {\n getImplementation\n};\n\n/**\n * Get the version-specific implementation for the OpenAPI-spec. Currently v2 and v3 are supported\n * @param {Object} openapiSpec OpenAPI-spec\n * @returns {Object|null}\n */\nfunction getImplementation(openapiSpec) {\n if (typeof openapiSpec.swagger === 'string') {\n return implV2;\n }\n if (openapiSpec.openapi && openapiSpec.openapi.match(REGEX__OPEN_API)) {\n return implV3;\n }\n return null;\n}\n","const { applyCallbackToAllObjectModels } = require('./common');\n\nmodule.exports = {\n setAllPropertiesRequired\n};\n\n/**\n * Sets all properties of each object to required\n * @param {Object} openApiSpec The to-be-modified schema\n * @param {Array.} [examplePaths=[]] The paths to the examples, which's content must not be modified\n */\nfunction setAllPropertiesRequired(openApiSpec, examplePaths = []) {\n applyCallbackToAllObjectModels(openApiSpec, examplePaths,\n () => {\n return (value) => {\n if (value.hasOwnProperty('properties')) {\n value.required = Object.keys(value.properties);\n }\n };\n });\n}\n","const { JSONPath: jsonPath } = require('jsonpath-plus'),\n ResultType = require('../../const/result-type');\n\nmodule.exports = {\n applyCallbackToAllObjectModels\n};\n\n/**\n * @typedef {{\n * path: String,\n * value: Object,\n * parent: Object,\n * parentProperty: String,\n * hasArrExpr: Boolean\n * }} JsonPathMatchData\n */\n\n/**\n * Callback that is applied to a JSONPath-match.\n * @callback JsonPathMatchCallback\n * @param {Object} value Value of the matched property\n * @param {String} resultType Result-type of the query\n * @param {JsonPathMatchData} data Object that contains additional data to the match\n */\n\n/**\n * Function to build a callback that is applied to a JSONPath-match.\n * @callback JsonPathMatchCallbackBuilder\n * @param {string} jsPath Path to the property that matched\n * @return {JsonPathMatchCallback} Callback that is applied to a JSONPath-match\n */\n\n/**\n * Apply the input rule to all models of type object in the input openApiSpec\n * @param {Object} openApiSpec The to-be-modified schema\n * @param {Array.} [examplePaths] The paths to the examples, which's content must not be modified\n * @param {JsonPathMatchCallbackBuilder} [matchCallbackBuilder] Function to build a callback\n * that will be called on each match\n */\nfunction applyCallbackToAllObjectModels(openApiSpec, examplePaths, matchCallbackBuilder) {\n // Find all matches\n const paths = new Set();\n _find(openApiSpec, '$..schema..')\n .forEach(match => {\n if (_isPropertiesDefinition(match)) { return; }\n paths.add(match);\n });\n // Exclude examples\n _excludeExamples(openApiSpec, paths, examplePaths);\n // Set flag\n for (const jsPath of paths) {\n const callback = matchCallbackBuilder(jsPath);\n _find(openApiSpec, jsPath, ResultType.value, (result, resultType, data) => {\n if (!_isObjectDefinition(result)) { return; }\n callback(result, resultType, data);\n });\n }\n}\n\n/**\n * Find matching elements in JSON.\n * @param {Object} json JSON to be searched\n * @param {String} path JSON-path to search\n * @param {String} [resultType=\"path\"] Result-type of the query\n * @param {JsonPathMatchCallback} [callback] Function to be called on a match\n * @returns {any} Result of the query, depending on the `resultType`\n * @private\n */\nfunction _find(json, path, resultType = ResultType.path, callback) {\n return jsonPath({\n json,\n path,\n flatten: true,\n resultType,\n callback\n });\n}\n\n/**\n * Remove JSON-paths from `paths` that are included in `examplePaths`\n * @param {Object} openApiSpec Open-API spec to search in\n * @param {Set.} paths Paths where the examples have to be removed from\n * @param {Array.} examplePaths JSON-paths of the examples\n * @private\n */\nfunction _excludeExamples(openApiSpec, paths, examplePaths) {\n examplePaths\n .forEach(examplePath => {\n _find(openApiSpec, examplePath)\n .forEach(exampleMatch => {\n for (const jsPath of paths) {\n jsPath.startsWith(exampleMatch) && paths.delete(jsPath);\n }\n });\n });\n}\n\nfunction _isPropertiesDefinition(path) {\n // Path has to end with `properties`\n if (!path.match(/\\['properties']$/)) { return; }\n // Every second consecutive `properties` actually is not a property-definition, but a property itself\n const consecutiveMatch = path.match(/(?} [examplePaths=[]] The paths to the examples, which's content must not be modified\n */\nfunction setNoAdditionalProperties(openApiSpec, examplePaths = []) {\n // Match all combiner keywords that are not preceded by a 'properties' keyword.\n // This allow to have objects that have as property name one of the combiner keywords.\n const hasJsonCombinerParentRegex\n = new RegExp('(? {\n return (schema) => {\n // Exclude schema that have a JSON combiner as parent\n if (hasJsonCombinerParentRegex.test(path)) {\n console.warn('\"additionalProperties\" flag not set '\n + `for ${path} because it has a parent with a JSON-schema combiner keyword.`);\n return;\n }\n // Exclude schema that contains a JSON combiner\n if (JSON_SCHEMA_COMBINERS.some((combiner) => schema.hasOwnProperty(combiner))) {\n console.warn('\"additionalProperties\" flag not set '\n + `for ${path} because it contains JSON-schema combiner keyword.`);\n return;\n }\n // Exclude schema that already contains additionalProperties\n if (schema.hasOwnProperty('additionalProperties')) {\n return;\n }\n schema.additionalProperties = false;\n };\n });\n}\n","/**\n * Contains validation-logic that is specific to V2 of the OpenAPI-spec\n */\n\nconst { JSONPath: jsonPath } = require('jsonpath-plus'),\n cloneDeep = require('lodash.clonedeep'),\n { setAllPropertiesRequired } = require('../service/all-properties-required'),\n { setNoAdditionalProperties } = require('../service/no-additional-properties');\n\n// CONSTANTS\n\nconst PATH__EXAMPLES = '$..examples.application/json',\n PROP__SCHEMA = 'schema',\n PROP__EXAMPLES = 'examples';\n\nmodule.exports = {\n buildValidationMap,\n escapeExampleName,\n getJsonPathsToExamples,\n prepare,\n unescapeExampleNames\n};\n\n// IMPLEMENTATION DETAILS\n\n/**\n * Get the JSONPaths to the examples\n * @returns {Array.} JSONPaths to the examples\n */\nfunction getJsonPathsToExamples() { return [PATH__EXAMPLES]; }\n\n\n/**\n * Builds a map with the path to the repsonse-schema as key and the paths to the examples, as value. The path of the\n * schema is derived from the path to the example and doesn't necessarily mean that the schema actually exists.\n * @param {Array.} pathsExamples Paths to the examples\n * @returns {Object.} Map with schema-path as key and example-paths as value\n * @private\n */\nfunction buildValidationMap(pathsExamples) {\n return pathsExamples.reduce((validationMap, pathExample) => {\n const pathSchema = _getSchemaPathOfExample(pathExample);\n validationMap[pathSchema] = (validationMap[pathSchema] || new Set())\n .add(pathExample);\n return validationMap;\n }, {});\n}\n\n/**\n * Pre-processes the OpenAPI-spec, for further use.\n * The passed spec won't be modified. If a modification happens, a modified copy will be returned.\n * @param {Object} openapiSpec The OpenAPI-spec as JSON-schema\n * @param {boolean} [noAdditionalProperties=false] Don't allow properties that are not defined in the schema\n * @param {boolean} [allPropertiesRequired=false] Make all properties required\n * @return {Object} The prepared OpenAPI-spec\n */\nfunction prepare(openapiSpec, { noAdditionalProperties, allPropertiesRequired } = {}) {\n const openapiSpecCopy = cloneDeep(openapiSpec);\n noAdditionalProperties && setNoAdditionalProperties(openapiSpecCopy, getJsonPathsToExamples());\n allPropertiesRequired && setAllPropertiesRequired(openapiSpecCopy, getJsonPathsToExamples());\n return openapiSpecCopy;\n}\n\n/**\n * Escapes the name of the example.\n * @param {string} rawPath Unescaped path\n * @returns {string} Escaped path\n * @private\n */\nfunction escapeExampleName(rawPath) {\n // No escaping necessary in v2, as there are no named-examples\n return rawPath;\n}\n\n/**\n * Escaped example-names reflect in the result (where they shouldn't). This function reverts it.\n * @param {string} rawPath Escaped path\n * @returns {string} Unescaped path\n */\nfunction unescapeExampleNames(rawPath) {\n // No unescaping necessary in v2, as there are no named-examples\n return rawPath;\n}\n\n/**\n * Gets a JSON-path to the corresponding response-schema, based on a JSON-path to an example.\n * @param {String} pathExample JSON-path to example\n * @returns {String} JSON-path to the corresponding response-schema\n * @private\n */\nfunction _getSchemaPathOfExample(pathExample) {\n const pathSegs = jsonPath.toPathArray(pathExample).slice(),\n idxExamples = pathSegs.lastIndexOf(PROP__EXAMPLES);\n pathSegs.splice(idxExamples, pathSegs.length - idxExamples, PROP__SCHEMA);\n return jsonPath.toPathString(pathSegs);\n}\n","/**\n * Contains validation-logic that is specific to V3 of the OpenAPI-spec\n */\n\nconst { JSONPath: jsonPath } = require('jsonpath-plus'),\n cloneDeep = require('lodash.clonedeep'),\n { ApplicationError, ErrorType } = require('../../application-error'),\n { setAllPropertiesRequired } = require('../service/all-properties-required'),\n { setNoAdditionalProperties } = require('../service/no-additional-properties');\n\n// CONSTANTS\n\nconst PATH__EXAMPLE = '$..responses..content.application/json.example',\n PATH__EXAMPLES = '$..responses..content.application/json.examples.*.value',\n PATH__EXAMPLE__PARAMETER = '$..parameters..example',\n PATH__EXAMPLES__PARAMETER = '$..parameters..examples.*.value',\n PATH__EXAMPLE__REQUEST_BODY = '$..requestBody.content.application/json.example',\n PATH__EXAMPLES__REQUEST_BODY = '$..requestBody.content.application/json.examples.*.value',\n PROP__SCHEMA = 'schema',\n PROP__EXAMPLE = 'example',\n PROP__EXAMPLES = 'examples';\n\nconst ExampleType = {\n single: 'single',\n multi: 'multi'\n};\n\n// PUBLIC API\n\nmodule.exports = {\n buildValidationMap,\n escapeExampleName,\n getJsonPathsToExamples,\n prepare,\n unescapeExampleNames\n};\n\n// IMPLEMENTATION DETAILS\n\n/**\n * Get the JSONPaths to the examples\n * @returns {Array.} JSONPaths to the examples\n */\nfunction getJsonPathsToExamples() {\n return [\n PATH__EXAMPLE,\n PATH__EXAMPLES,\n PATH__EXAMPLE__PARAMETER,\n PATH__EXAMPLES__PARAMETER,\n PATH__EXAMPLE__REQUEST_BODY,\n PATH__EXAMPLES__REQUEST_BODY\n ];\n}\n\n/**\n * Builds a map with the path to the repsonse-schema as key and the paths to the examples, as value. The path of the\n * schema is derived from the path to the example and doesn't necessarily mean that the schema actually exists.\n * @param {Array.} pathsExamples Paths to the examples\n * @returns {Object.} Map with schema-path as key and example-paths as value\n * @private\n */\nfunction buildValidationMap(pathsExamples) {\n const exampleTypesOfSchemas = new Map();\n return pathsExamples.reduce((validationMap, pathExample) => {\n const { pathSchemaAsArray, exampleType } = _getSchemaPathOfExample(pathExample),\n pathSchema = jsonPath.toPathString(pathSchemaAsArray),\n exampleTypeOfSchema = exampleTypesOfSchemas.get(pathSchema);\n if (exampleTypeOfSchema) {\n exampleTypeOfSchema !== exampleType && _throwMutuallyExclusiveError(pathSchemaAsArray);\n }\n exampleTypesOfSchemas.set(pathSchema, exampleType);\n validationMap[pathSchema] = (validationMap[pathSchema] || new Set())\n .add(pathExample);\n return validationMap;\n }, {});\n}\n\n/**\n * Pre-processes the OpenAPI-spec, for further use.\n * The passed spec won't be modified. If a modification happens, a modified copy will be returned.\n * @param {Object} openapiSpec The OpenAPI-spec as JSON-schema\n * @param {boolean} [noAdditionalProperties=false] Don't allow properties that are not defined in the schema\n * @param {boolean} [allPropertiesRequired=false] Make all properties required\n * @return {Object} The prepared OpenAPI-spec\n */\nfunction prepare(openapiSpec, { noAdditionalProperties, allPropertiesRequired } = {}) {\n const openapiSpecCopy = cloneDeep(openapiSpec);\n noAdditionalProperties && setNoAdditionalProperties(openapiSpecCopy, getJsonPathsToExamples());\n allPropertiesRequired && setAllPropertiesRequired(openapiSpecCopy, getJsonPathsToExamples());\n return openapiSpecCopy;\n}\n\n/**\n * Escapes the name of the example. In order to do that, a backtick has to be added to the beginning of the key.\n * @param {string} rawPath Unescaped path\n * @returns {string} Escaped path\n * @private\n */\nfunction escapeExampleName(rawPath) {\n return rawPath.replace(/\\['examples'\\]\\['(.*)\\]\\['value'\\]$/, \"['examples']['`$1]['value']\");\n}\n\n/**\n * Escaped example-names reflect in the result (where they shouldn't). This function reverts it.\n * @param {string} rawPath Escaped path\n * @returns {string} Unescaped path\n */\nfunction unescapeExampleNames(rawPath) {\n return rawPath && rawPath.replace(/\\/examples\\/`(.*)\\/value$/, '/examples/$1/value');\n}\n\n/**\n * Gets a JSON-path to the corresponding response-schema, based on a JSON-path to an example.\n *\n * It is assumed that the JSON-path to the example is valid and existing.\n * @param {String} pathExample JSON-path to example\n * @returns {{\n * exampleType: ExampleType,\n * pathSchema: String\n * }} JSON-path to the corresponding response-schema\n * @private\n */\nfunction _getSchemaPathOfExample(pathExample) {\n const pathSegs = jsonPath.toPathArray(pathExample).slice(),\n idxExample = pathSegs.lastIndexOf(PROP__EXAMPLE),\n /** @type ExampleType */\n exampleType = idxExample > -1\n ? ExampleType.single\n : ExampleType.multi,\n idxExamples = exampleType === ExampleType.single\n ? idxExample\n : pathSegs.lastIndexOf(PROP__EXAMPLES);\n pathSegs.splice(idxExamples, pathSegs.length - idxExamples, PROP__SCHEMA);\n return {\n exampleType,\n pathSchemaAsArray: pathSegs\n };\n}\n\n/**\n * Checks if only `example` or `examples` is set for the schema, as they are mutually exclusive by OpenAPI-spec.\n * @param {Array.} pathSchemaAsArray JSON-path to the Schema, as JSON-path-array\n * @throws ApplicationError if both are set\n * @private\n */\nfunction _throwMutuallyExclusiveError(pathSchemaAsArray) {\n const pathContextAsArray = pathSchemaAsArray.slice(0, pathSchemaAsArray.length - 1); // Strip `schema` away\n throw ApplicationError.create({\n type: ErrorType.errorAndErrorsMutuallyExclusive,\n message: 'Properties \"error\" and \"errors\" are mutually exclusive',\n params: {\n pathContext: jsonPath.toPointer(pathContextAsArray)\n }\n });\n}\n","/**\n * Entry-point for the validator-API\n */\n\nconst\n merge = require('lodash.merge'),\n flatten = require('lodash.flatten'),\n flatMap = require('lodash.flatmap'),\n fs = require('fs'),\n path = require('path'),\n glob = require('glob'),\n yaml = require('yaml'),\n { JSONPath: jsonPath } = require('jsonpath-plus'),\n refParser = require('json-schema-ref-parser'),\n { createError } = require('errno').custom,\n ResultType = require('./const/result-type'),\n { getValidatorFactory, compileValidate } = require('./validator'),\n Determiner = require('./impl'),\n { ApplicationError, ErrorType } = require('./application-error'),\n { createValidationResponse, dereferenceJsonSchema } = require('./utils');\n\n// CONSTANTS\n\nconst SYM__INTERNAL = Symbol('internal'),\n PROP__SCHEMAS_WITH_EXAMPLES = 'schemasWithExamples',\n FILE_EXTENSIONS__YAML = [\n 'yaml',\n 'yml'\n ];\n\n// STATICS\n\n/**\n * ErrorJsonPathNotFound\n * @typedef {{\n * cause: {\n * [params]: {\n * [path]: string\n * }\n * }\n * }} ErrorJsonPathNotFound\n * @augments CustomError\n */\n\n/**\n * @constructor\n * @augments CustomError\n * @returns {ErrorJsonPathNotFound}\n */\nconst ErrorJsonPathNotFound = createError(ErrorType.jsonPathNotFound);\n\n// PUBLIC API\n\nmodule.exports = {\n 'default': validateExamples,\n validateFile,\n validateExample,\n validateExamplesByMap\n};\n\n// IMPLEMENTATION DETAILS\n\n// Type definitions\n\n/**\n * ValidationStatistics\n * @typedef {{\n * schemasWithExamples: number,\n * examplesTotal: number,\n * examplesWithoutSchema: number,\n * [matchingFilePathsMapping]: number\n * }} ValidationStatistics\n */\n\n/**\n * ValidationResponse\n * @typedef {{\n * valid: boolean,\n * statistics: ValidationStatistics,\n * errors: Array.\n * }} ValidationResponse\n */\n\n/**\n * @callback ValidationHandler\n * @param {ValidationStatistics} statistics\n * @returns {Array.}\n */\n\n// Public\n\n/**\n * Validates OpenAPI-spec with embedded examples.\n * @param {Object} openapiSpec OpenAPI-spec\n * @param {boolean} [noAdditionalProperties=false] Don't allow properties that are not defined in the schema\n * @param {boolean} [allPropertiesRequired=false] Make all properties required\n * @param {Array.} [ignoreFormats] List of datatype formats that shall be ignored (to prevent\n * \"unsupported format\" errors). If an Array with only one string is\n * provided where the formats are separated with `\\n`, the entries\n * will be expanded to a new array containing all entries.\n * @returns {ValidationResponse}\n */\nasync function validateExamples(openapiSpec, { noAdditionalProperties, ignoreFormats, allPropertiesRequired } = {}) {\n const impl = Determiner.getImplementation(openapiSpec);\n openapiSpec = await refParser.dereference(openapiSpec);\n openapiSpec = impl.prepare(openapiSpec, { noAdditionalProperties, allPropertiesRequired });\n let pathsExamples = impl.getJsonPathsToExamples()\n .reduce((res, pathToExamples) => {\n return res.concat(_extractExamplePaths(openapiSpec, pathToExamples));\n }, [])\n .map(impl.escapeExampleName);\n return _validateExamplesPaths({ impl }, pathsExamples, openapiSpec, { ignoreFormats });\n}\n\n/**\n * Validates OpenAPI-spec with embedded examples.\n * @param {string} filePath File-path to the OpenAPI-spec\n * @param {boolean} [noAdditionalProperties=false] Don't allow properties that are not defined in the schema\n * @param {boolean} [allPropertiesRequired=false] Make all properties required\n * @param {Array.} [ignoreFormats] List of datatype formats that shall be ignored (to prevent\n * \"unsupported format\" errors). If an Array with only one string is\n * provided where the formats are separated with `\\n`, the entries\n * will be expanded to a new array containing all entries.\n * @returns {ValidationResponse}\n */\nasync function validateFile(filePath, { noAdditionalProperties, ignoreFormats, allPropertiesRequired } = {}) {\n let openapiSpec = null;\n try {\n openapiSpec = await _parseSpec(filePath);\n } catch (err) {\n return createValidationResponse({ errors: [ApplicationError.create(err)] });\n }\n return validateExamples(openapiSpec, { noAdditionalProperties, ignoreFormats, allPropertiesRequired });\n}\n\n/**\n * Validates examples by mapping-files.\n * @param {string} filePathSchema File-path to the OpenAPI-spec\n * @param {string} globMapExternalExamples File-path (globs are supported) to the mapping-file containing JSON-\n * paths to schemas as key and a single file-path or Array of file-paths\n * to external examples\n * @param {boolean} [cwdToMappingFile=false] Change working directory for resolving the example-paths (relative to\n * the mapping-file)\n * @param {boolean} [noAdditionalProperties=false] Don't allow properties that are not defined in the schema\n * @param {boolean} [allPropertiesRequired=false] Make all properties required\n * @param {Array.} [ignoreFormats] List of datatype formats that shall be ignored (to prevent\n * \"unsupported format\" errors). If an Array with only one string is\n * provided where the formats are separated with `\\n`, the entries\n * will be expanded to a new array containing all entries.\n * @returns {ValidationResponse}\n */\nasync function validateExamplesByMap(filePathSchema, globMapExternalExamples,\n { cwdToMappingFile, noAdditionalProperties, ignoreFormats, allPropertiesRequired } = {}\n) {\n let matchingFilePathsMapping = 0;\n const filePathsMaps = glob.sync(\n globMapExternalExamples,\n // Using `nonull`-option to explicitly create an app-error if there's no match for `globMapExternalExamples`\n { nonull: true }\n );\n let responses = [];\n // for..of here, to support sequential execution of async calls. This is required, since dereferencing the\n // `openapiSpec` is not concurrency-safe\n for (const filePathMapExternalExamples of filePathsMaps) {\n let mapExternalExamples = null,\n openapiSpec = null;\n try {\n mapExternalExamples = JSON.parse(fs.readFileSync(filePathMapExternalExamples, 'utf-8'));\n openapiSpec = await _parseSpec(filePathSchema);\n openapiSpec = Determiner.getImplementation(openapiSpec)\n .prepare(openapiSpec, { noAdditionalProperties, allPropertiesRequired });\n } catch (err) {\n responses.push(createValidationResponse({ errors: [ApplicationError.create(err)] }));\n continue;\n }\n // Not using `glob`'s response-length, because it is `1` if there's no match for `globMapExternalExamples`.\n // Instead, increment on every match\n matchingFilePathsMapping++;\n responses.push(\n _validate(\n statistics => {\n return _handleExamplesByMapValidation(\n openapiSpec, mapExternalExamples, statistics, {\n cwdToMappingFile,\n dirPathMapExternalExamples: path.dirname(filePathMapExternalExamples),\n ignoreFormats\n }\n ).map(\n (/** @type ApplicationError */ error) => Object.assign(error, {\n mapFilePath: path.normalize(filePathMapExternalExamples)\n })\n );\n }\n )\n );\n }\n return merge(\n responses.reduce((res, response) => {\n if (!res) {\n return response;\n }\n return _mergeValidationResponses(res, response);\n }, null),\n { statistics: { matchingFilePathsMapping } }\n );\n}\n\n/**\n * Validates a single external example.\n * @param {String} filePathSchema File-path to the OpenAPI-spec\n * @param {String} pathSchema JSON-path to the schema\n * @param {String} filePathExample File-path to the external example-file\n * @param {boolean} [noAdditionalProperties=false] Don't allow properties that are not described in the schema\n * @param {boolean} [allPropertiesRequired=false] Make all properties required\n * @param {Array.} [ignoreFormats] List of datatype formats that shall be ignored (to prevent\n * \"unsupported format\" errors). If an Array with only one string is\n * provided where the formats are separated with `\\n`, the entries\n * will be expanded to a new array containing all entries.\n * @returns {ValidationResponse}\n */\nasync function validateExample(filePathSchema, pathSchema, filePathExample, {\n noAdditionalProperties,\n ignoreFormats,\n allPropertiesRequired\n} = {}) {\n let example = null,\n schema = null,\n openapiSpec = null;\n try {\n example = JSON.parse(fs.readFileSync(filePathExample, 'utf-8'));\n openapiSpec = await _parseSpec(filePathSchema);\n openapiSpec = Determiner.getImplementation(openapiSpec)\n .prepare(openapiSpec, { noAdditionalProperties, allPropertiesRequired });\n schema = _extractSchema(pathSchema, openapiSpec);\n } catch (err) {\n return createValidationResponse({ errors: [ApplicationError.create(err)] });\n }\n return _validate(\n statistics => _validateExample({\n createValidator: _initValidatorFactory(openapiSpec, { ignoreFormats }),\n schema,\n example,\n statistics,\n filePathExample\n })\n );\n}\n\n// Private\n\n/**\n * Parses the OpenAPI-spec (supports JSON and YAML)\n * @param {String} filePath File-path to the OpenAPI-spec\n * @returns {object} Parsed OpenAPI-spec\n * @private\n */\nasync function _parseSpec(filePath) {\n const isYaml = _isFileTypeYaml(filePath);\n let jsonSchema;\n\n if (isYaml) {\n try {\n jsonSchema = yaml.parse(fs.readFileSync(filePath, 'utf-8'));\n } catch (e) {\n const { name, message } = e;\n throw new ApplicationError(ErrorType.parseError, { message: `${name}: ${message}` });\n }\n } else {\n jsonSchema = JSON.parse(fs.readFileSync(filePath, 'utf-8'));\n }\n\n return await dereferenceJsonSchema(filePath, jsonSchema);\n}\n\n/**\n * Determines whether the filePath is pointing to a YAML-file\n * @param {String} filePath File-path to the OpenAPI-spec\n * @returns {boolean} `true`, if the file is a YAML-file\n * @private\n */\nfunction _isFileTypeYaml(filePath) {\n const extension = filePath.split('.').pop();\n return FILE_EXTENSIONS__YAML.includes(extension);\n}\n\n/**\n * Top-level validator. Prepares common values, required for the validation, then calles the validator and prepares\n * the result for the output.\n * @param {ValidationHandler} validationHandler The handler which performs the validation. It will receive the\n * statistics-object as argument and has to return an Array of\n * errors (or an empty Array, when all examples are valid)\n * @returns {ValidationResponse}\n * @private\n */\nfunction _validate(validationHandler) {\n const statistics = _initStatistics(),\n errors = validationHandler(statistics);\n return createValidationResponse({ errors, statistics });\n}\n\n/**\n * Validates examples by a mapping-file.\n * @param {Object} openapiSpec OpenAPI-spec\n * @param {Object} mapExternalExamples Mapping-file containing JSON-paths to schemas as\n * key and a single file-path or Array of file-paths\n * to external examples\n * @param {ValidationStatistics} statistics Validation-statistics\n * @param {boolean} [cwdToMappingFile=false] Change working directory for resolving the example-\n * paths (relative to the mapping-file)\n * @param {string} [dirPathMapExternalExamples] The directory-path of the mapping-file\n * @param {Array.} [ignoreFormats] List of datatype formats that shall be ignored (to prevent\n * \"unsupported format\" errors). If an Array with only one string is\n * provided where the formats are separated with `\\n`, the entries\n * will be expanded to a new array containing all entries.\n * @returns {Array.}\n * @private\n */\nfunction _handleExamplesByMapValidation(openapiSpec, mapExternalExamples, statistics,\n { cwdToMappingFile = false, dirPathMapExternalExamples, ignoreFormats }\n) {\n return flatMap(Object.entries(mapExternalExamples), ([pathSchema, filePathsExample]) => {\n let schema = null;\n try {\n schema = _extractSchema(pathSchema, openapiSpec);\n } catch (/** @type ErrorJsonPathNotFound */ err) {\n // If the schema can't be found, don't even attempt to process the examples\n return ApplicationError.create(err);\n }\n return flatMap(\n flatten([filePathsExample]),\n filePathExample => {\n let examples = [];\n try {\n const resolvedFilePathExample = cwdToMappingFile\n ? path.join(dirPathMapExternalExamples, filePathExample)\n : filePathExample;\n const globResolvedFilePathExample = glob.sync(resolvedFilePathExample);\n if (globResolvedFilePathExample.length === 0) {\n return [ApplicationError.create({\n type: ErrorType.jsENOENT,\n message: `No such file or directory: '${resolvedFilePathExample}'`,\n path: resolvedFilePathExample\n })];\n }\n for (const filePathExample of globResolvedFilePathExample) {\n examples.push({\n path: path.normalize(filePathExample),\n content: JSON.parse(fs.readFileSync(filePathExample, 'utf-8'))\n });\n }\n } catch (err) {\n return [ApplicationError.create(err)];\n }\n return flatMap(examples, example => _validateExample({\n createValidator: _initValidatorFactory(openapiSpec, { ignoreFormats }),\n schema,\n example: example.content,\n statistics,\n filePathExample: example.path\n }));\n }\n );\n });\n}\n\n/**\n * Merges two `ValidationResponses` together and returns the merged result. The passed `ValidationResponse`s won't be\n * modified.\n * @param {ValidationResponse} response1\n * @param {ValidationResponse} response2\n * @returns {ValidationResponse}\n * @private\n */\nfunction _mergeValidationResponses(response1, response2) {\n return createValidationResponse({\n errors: response1.errors.concat(response2.errors),\n statistics: Object.entries(response1.statistics)\n .reduce((res, [key, val]) => {\n if (PROP__SCHEMAS_WITH_EXAMPLES === key) {\n [\n response1,\n response2\n ].forEach(response => {\n const schemasWithExample = response.statistics[SYM__INTERNAL][PROP__SCHEMAS_WITH_EXAMPLES]\n .values();\n for (let schema of schemasWithExample) {\n res[SYM__INTERNAL][PROP__SCHEMAS_WITH_EXAMPLES].add(schema);\n }\n });\n return res;\n }\n res[key] = val + response2.statistics[key];\n return res;\n }, _initStatistics())\n });\n}\n\n/**\n * Extracts all JSON-paths to examples from a OpenAPI-spec\n * @param {Object} openapiSpec OpenAPI-spec\n * @param {String} jsonPathToExamples JSON-path to the examples, in the OpenAPI-Spec\n * @returns {Array.} JSON-paths to examples\n * @private\n */\nfunction _extractExamplePaths(openapiSpec, jsonPathToExamples) {\n return jsonPath({\n json: openapiSpec,\n path: jsonPathToExamples,\n resultType: ResultType.path\n });\n}\n\n/**\n * Validates examples at the given paths in the OpenAPI-spec.\n * @param {Object} impl Spec-dependant validator\n * @param {Array.} pathsExamples JSON-paths to examples\n * @param {Object} openapiSpec OpenAPI-spec\n * @param {Array.} [ignoreFormats] List of datatype formats that shall be ignored (to prevent\n * \"unsupported format\" errors). If an Array with only one string is\n * provided where the formats are separated with `\\n`, the entries\n * will be expanded to a new array containing all entries.\n * @returns {ValidationResponse}\n * @private\n */\nfunction _validateExamplesPaths({ impl }, pathsExamples, openapiSpec, { ignoreFormats }) {\n const statistics = _initStatistics(),\n validationResult = {\n valid: true,\n statistics,\n errors: []\n },\n createValidator = _initValidatorFactory(openapiSpec, { ignoreFormats });\n let validationMap;\n try {\n // Create mapping between JSON-schemas and examples\n validationMap = impl.buildValidationMap(pathsExamples);\n } catch (error) {\n // Throw unexpected errors\n if (!(error instanceof ApplicationError)) {\n throw error;\n }\n // Add known errors and stop\n validationResult.valid = false;\n validationResult.errors.push(error);\n return validationResult;\n }\n // Start validation\n const schemaPaths = Object.keys(validationMap);\n schemaPaths.forEach(pathSchema => {\n _validateSchema({\n openapiSpec, createValidator, pathSchema, validationMap, statistics,\n validationResult\n });\n });\n // Revert escaped example names from the results\n validationResult.errors.forEach((example) => {\n example.examplePath = impl.unescapeExampleNames(example.examplePath);\n });\n return validationResult;\n}\n\n/**\n * Validates a single schema.\n * @param {Object} openapiSpec OpenAPI-spec\n * @param {ajv} createValidator Factory, to create JSON-schema validator\n * @param {string} pathSchema JSON-path to schema (for request- or response-property)\n * @param {Object.} validationMap Map with schema-path as key and example-paths as value\n * @param {Object} statistics Object to contain statistics metrics\n * @param {Object} validationResult Container, for the validation-results\n * @private\n */\nfunction _validateSchema({\n openapiSpec, createValidator, pathSchema, validationMap, statistics,\n validationResult\n}) {\n const errors = validationResult.errors;\n validationMap[pathSchema].forEach(pathExample => {\n const example = _getObjectByPath(pathExample, openapiSpec),\n // Examples with missing schemas may occur and those are considered valid\n schema = _extractSchema(pathSchema, openapiSpec, true),\n curErrors = _validateExample({\n createValidator,\n schema,\n example,\n statistics\n }).map(error => {\n error.examplePath = jsonPath.toPointer(jsonPath.toPathArray(pathExample));\n return error;\n });\n if (!curErrors.length) {\n return;\n }\n validationResult.valid = false;\n errors.splice(errors.length - 1, 0, ...curErrors);\n });\n}\n\n/**\n * Creates a container-object for the validation statistics.\n * @returns {ValidationStatistics}\n * @private\n */\nfunction _initStatistics() {\n const statistics = {\n [SYM__INTERNAL]: {\n [PROP__SCHEMAS_WITH_EXAMPLES]: new Set()\n },\n examplesTotal: 0,\n examplesWithoutSchema: 0\n };\n Object.defineProperty(statistics, PROP__SCHEMAS_WITH_EXAMPLES, {\n enumerable: true,\n get: () => statistics[SYM__INTERNAL][PROP__SCHEMAS_WITH_EXAMPLES].size\n });\n return statistics;\n}\n\n/**\n * Extract object(s) by the given JSON-path\n * @param {String} path JSON-path\n * @param {Object} json JSON to extract the object(s) from\n * @returns {Object|Array.|undefined} All matching objects. Single object if there is only one match\n * @private\n */\nfunction _getObjectByPath(path, json) {\n return jsonPath({\n json,\n path,\n flatten: true,\n wrap: false,\n resultType: ResultType.value\n });\n}\n\n/**\n * Validates example against the schema. The precondition for this function to work is that the example exists at the\n * given path.\n * `pathExample` and `filePathExample` are exclusively mandatory.\n * itself\n * @param {Function} createValidator Factory, to create JSON-schema validator\n * @param {Object} schema JSON-schema\n * @param {Object} example Example to validate\n * @param {Object} statistics Object to contain statistics metrics\n * @param {String} [filePathExample] File-path to the example file\n * @returns {Array.} Array with errors. Empty array, if examples are valid\n * @private\n */\nfunction _validateExample({ createValidator, schema, example, statistics, filePathExample }) {\n const\n errors = [];\n statistics.examplesTotal++;\n // No schema, no validation (Examples without schema are considered valid)\n if (!schema) {\n statistics.examplesWithoutSchema++;\n return errors;\n }\n statistics[SYM__INTERNAL][PROP__SCHEMAS_WITH_EXAMPLES].add(schema);\n const validate = compileValidate(createValidator(), schema);\n if (validate(example)) {\n return errors;\n }\n return errors.concat(...validate.errors.map(ApplicationError.create))\n .map(error => {\n if (!filePathExample) {\n return error;\n }\n error.exampleFilePath = filePathExample;\n return error;\n });\n}\n\n/**\n * Create a new instance of a JSON schema validator\n * @returns {ajv}\n * @private\n */\nfunction _initValidatorFactory(specSchema, { ignoreFormats }) {\n return getValidatorFactory(specSchema, {\n schemaId: 'auto',\n discriminator: true,\n strict: false,\n allErrors: true,\n formats: ignoreFormats && ignoreFormats.reduce((result, entry) => {\n result[entry] = () => true;\n return result;\n }, {})\n });\n}\n\n/**\n * Extracts the schema in the OpenAPI-spec at the given JSON-path.\n * @param {string} pathSchema JSON-path to the schema\n * @param {Object} openapiSpec OpenAPI-spec\n * @param {boolean} [suppressErrorIfNotFound=false] Don't throw `ErrorJsonPathNotFound` if the response does not\n * exist at the given JSON-path\n * @returns {Object|Array.|undefined} Matching schema(s)\n * @throws {ErrorJsonPathNotFound} Thrown, when there is no schema at the given path and\n * `suppressErrorIfNotFound` is false\n * @private\n */\nfunction _extractSchema(pathSchema, openapiSpec, suppressErrorIfNotFound = false) {\n const schema = _getObjectByPath(pathSchema, openapiSpec);\n if (!suppressErrorIfNotFound && !schema) {\n throw new ErrorJsonPathNotFound(`Path to schema can't be found: '${pathSchema}'`, {\n params: {\n path: pathSchema\n }\n });\n }\n return schema;\n}\n","const path = require('path'),\n refParser = require('json-schema-ref-parser');\n\nmodule.exports = {\n createValidationResponse,\n dereferenceJsonSchema\n};\n\n/**\n * Creates a unified response for the validation-result\n * @param {Array.} errors\n * @param {ValidationStatistics} statistics\n * @returns {ValidationResponse}\n * @private\n */\nfunction createValidationResponse({ errors, statistics = {} }) {\n return {\n valid: !errors.length,\n statistics,\n errors\n };\n}\n\n/**\n * Includes all referenced, external schemas (by the keyword `$ref`) into the schema\n *\n * CAUTION: This function is not concurrency-safe !!\n * This function changes the working dir and sets it back. This may become an concurrency issue when there are\n * other tasks running that rely on the working dir while this function waits for the asynchronous task of\n * dereferencing to complete.\n *\n * @param {String} pathToSchema File-path to the schema\n * @param {Object} jsonSchema Schema with potential externally referenced schemas\n * @returns {Promise} Dereferenced schema\n */\nasync function dereferenceJsonSchema(pathToSchema, jsonSchema) {\n const currentWorkingDir = process.cwd();\n // Change the working dir to the schema-path, to make sure that relative paths can be resolved\n process.chdir(path.dirname(pathToSchema));\n const dereferencedSchema = await refParser.dereference(jsonSchema);\n // Restore original working dir\n process.chdir(currentWorkingDir);\n return dereferencedSchema;\n}\n","/**\n * Wrapper for the JSONSchema-validator\n */\n\nconst { JSONPath: jsonPath } = require('jsonpath-plus'),\n JsonPointer = require('json-pointer'),\n Ajv = require('ajv-draft-04'),\n addFormats = require('ajv-formats');\n\nconst PROP__ID = '$id',\n JSON_PATH__REFS = '$..\\$ref',\n ID__SPEC_SCHEMA = 'https://www.npmjs.com/package/openapi-examples-validator/defs.json',\n ID__RESPONSE_SCHEMA = 'https://www.npmjs.com/package/openapi-examples-validator/schema.json';\n\nmodule.exports = {\n getValidatorFactory,\n compileValidate\n};\n\n/**\n * Get a factory-function to create a prepared validator-instance\n * @param {Object} specSchema OpenAPI-spec of which potential local references will be extracted\n * @param {Object} [options] Options for the validator\n * @returns {function(): (ajv | ajv.Ajv)}\n */\nfunction getValidatorFactory(specSchema, options) {\n const preparedSpecSchema = _createReferenceSchema(specSchema);\n return () => {\n const validator = new Ajv(options);\n addFormats(validator);\n\n validator.addSchema(preparedSpecSchema);\n\n return validator;\n };\n}\n\n/**\n * Compiles the validator-function.\n * @param {ajv | ajv.Ajv} validator Validator-instance\n * @param {Object} responseSchema The response-schema, against the examples will be validated\n * @returns {ajv.ValidateFunction}\n */\nfunction compileValidate(validator, responseSchema) {\n const preparedResponseSchema = _prepareResponseSchema(responseSchema, ID__RESPONSE_SCHEMA);\n _replaceRefsToPreparedSpecSchema(preparedResponseSchema);\n\n let result;\n try {\n result = validator.compile(preparedResponseSchema);\n } catch (e) {\n result = () => {};\n result.errors = [e];\n }\n return result;\n}\n\n/**\n * Prepares the schema, to be used with internal-references\n * @param {Object} specSchema The schema to be prebared\n * @param {String} idSchema The unique ID for the schema\n * @returns {Object}\n * @private\n */\nfunction _prepareResponseSchema(specSchema, idSchema) {\n const preparedSchema = Object.assign({}, specSchema);\n preparedSchema[PROP__ID] = idSchema;\n return preparedSchema;\n}\n\n/**\n * Replaces all internal references to the schema, with the extracted references, based on the origin OpenAPI-spec\n * @param {Object} schema The schema, containing references have to be replaced\n * @private\n */\nfunction _replaceRefsToPreparedSpecSchema(schema) {\n jsonPath({\n path: JSON_PATH__REFS,\n json: schema,\n callback(value, type, payload) {\n if (!value.startsWith('#')) { return; }\n payload.parent[payload.parentProperty] = `${ ID__SPEC_SCHEMA }${ value }`;\n }\n });\n}\n\n/**\n * Extracts all references and returns a new schema, containing only those.\n * @param {Object} specSchema Schema, which references shall be extracted\n * @returns {Object}\n * @private\n */\nfunction _createReferenceSchema(specSchema) {\n const refSchema = {\n [PROP__ID]: ID__SPEC_SCHEMA\n };\n jsonPath({\n path: JSON_PATH__REFS,\n json: specSchema,\n callback(value) {\n if (!value.startsWith('#')) { return; }\n const pointer = value.substring(1),\n definition = JsonPointer.get(specSchema, pointer);\n JsonPointer.set(refSchema, pointer, definition);\n }\n });\n return refSchema;\n}\n","module.exports = {\"name\":\"openapi-examples-validator\",\"version\":\"5.0.0\",\"description\":\"Validates embedded examples in OpenAPI-JSONs\",\"main\":\"dist/index.js\",\"engines\":{\"node\":\">=16\"},\"bin\":{\"openapi-examples-validator\":\"dist/cli.js\"},\"standard-version\":{\"scripts\":{\"postchangelog\":\"npm run release:create-dockerfile && npm run release:stage-artifacts\"}},\"scripts\":{\"start-dev\":\"babel-node src/cli\",\"build\":\"npm run build:clean && npm run build:webpack\",\"build:clean\":\"rimraf dist\",\"build:webpack\":\"webpack --bail --progress --profile --mode production --config ./webpack/config.babel.js\",\"coverage\":\"rimraf ./coverage && nyc --reporter=lcov --reporter=text -x \\\"dist/**/*\\\" -x \\\"test/**/*.js\\\" npm test\",\"coveralls\":\"cat ./coverage/lcov.info | coveralls\",\"test\":\"npm run build && npm run test:mocha\",\"test-mutations\":\"stryker run\",\"test:mocha\":\"mocha --require \\\"./test/util/setup-tests\\\" --recursive \\\"./test/specs/**/*.js\\\"\",\"release\":\"npm run build && standard-version -a\",\"release:create-dockerfile\":\"npm run build && node etc/src/build-dockerfile.js\",\"release:stage-artifacts\":\"git add dist/*\"},\"repository\":{\"type\":\"git\",\"url\":\"git+https://github.com/codekie/openapi-examples-validator.git\"},\"keywords\":[\"swagger\",\"openapi\",\"json\",\"validate\",\"examples\"],\"author\":\"Josua Amann\",\"license\":\"MIT\",\"bugs\":{\"url\":\"https://github.com/codekie/openapi-examples-validator/issues\"},\"homepage\":\"https://github.com/codekie/openapi-examples-validator#readme\",\"devDependencies\":{\"@babel/cli\":\"^7.21.5\",\"@babel/core\":\"^7.21.8\",\"@babel/eslint-parser\":\"^7.21.8\",\"@babel/node\":\"^7.20.7\",\"@babel/preset-env\":\"^7.21.5\",\"@babel/register\":\"^7.21.0\",\"@stryker-mutator/core\":\"^6.4.2\",\"@stryker-mutator/mocha-runner\":\"^6.4.2\",\"babel-loader\":\"^9.1.2\",\"chai\":\"^4.3.6\",\"core-js-pure\":\"^3.30.2\",\"coveralls\":\"^3.1.1\",\"eslint\":\"^8.41.0\",\"eslint-webpack-plugin\":\"^4.0.1\",\"json-loader\":\"^0.5.7\",\"mocha\":\"^10.2.0\",\"mocha-lcov-reporter\":\"^1.3.0\",\"nyc\":\"^15.1.0\",\"rimraf\":\"^5.0.1\",\"standard-version\":\"^9.5.0\",\"stryker-cli\":\"^1.0.2\",\"webpack\":\"^5.83.1\",\"webpack-cli\":\"^5.1.1\"},\"dependencies\":{\"ajv\":\"^8.12.0\",\"ajv-draft-04\":\"^1.0.0\",\"ajv-formats\":\"^2.1.1\",\"commander\":\"^6.2.1\",\"errno\":\"^1.0.0\",\"glob\":\"^8.1.0\",\"json-pointer\":\"^0.6.2\",\"json-schema-ref-parser\":\"^9.0.9\",\"jsonpath-plus\":\"^7.2.0\",\"lodash.clonedeep\":\"^4.5.0\",\"lodash.flatmap\":\"^4.5.0\",\"lodash.flatten\":\"^4.4.0\",\"lodash.merge\":\"^4.6.2\",\"yaml\":\"^2.2.2\"}}","module.exports = require(\"ajv-draft-04\");","module.exports = require(\"ajv-formats\");","module.exports = require(\"commander\");","module.exports = require(\"errno\");","module.exports = require(\"glob\");","module.exports = require(\"json-pointer\");","module.exports = require(\"json-schema-ref-parser\");","module.exports = require(\"jsonpath-plus\");","module.exports = require(\"lodash.clonedeep\");","module.exports = require(\"lodash.flatmap\");","module.exports = require(\"lodash.flatten\");","module.exports = require(\"lodash.merge\");","module.exports = require(\"yaml\");","module.exports = require(\"fs\");","module.exports = require(\"path\");","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","// startup\n// Load entry module and return exports\n// This entry module is referenced by other modules so it can't be inlined\nvar __webpack_exports__ = __webpack_require__(339);\n"],"names":["merge","require","ENOENT","ErrorType","jsENOENT","code","jsonPathNotFound","errorAndErrorsMutuallyExclusive","parseError","validation","ApplicationError","static","err","message","path","cause","type","options","params","constructor","Object","assign","this","module","exports","VERSION","program","validateFile","validateExample","validateExamplesByMap","ENV_TEST","process","env","OPENAPI_EXAMPLES_VALIDATOR_TESTS","version","arguments","description","option","action","async","filepath","schemaJsonpath","exampleFilepath","mappingFilepath","cwdToMappingFile","allPropertiesRequired","noAdditionalProperties","additionalProperties","ignoreFormats","Array","isArray","length","indexOf","split","filter","entry","match","_prepareIgnoreFormats","result","console","log","noExit","statistics","schemasWithExamples","examplesWithoutSchema","examplesTotal","matchingFilePathsMapping","strStatistics","push","stdout","write","join","_printStatistics","valid","exit","stderr","JSON","stringify","errors","_handleResult","on","parseAsync","argv","parent","parentProperty","pointer","value","implV2","implV3","REGEX__OPEN_API","getImplementation","openapiSpec","swagger","openapi","applyCallbackToAllObjectModels","setAllPropertiesRequired","openApiSpec","examplePaths","hasOwnProperty","required","keys","properties","JSONPath","jsonPath","ResultType","_find","json","resultType","callback","flatten","matchCallbackBuilder","paths","Set","forEach","consecutiveMatch","_isPropertiesDefinition","add","examplePath","exampleMatch","jsPath","startsWith","delete","_excludeExamples","data","entity","setNoAdditionalProperties","hasJsonCombinerParentRegex","RegExp","JSON_SCHEMA_COMBINERS","schema","test","warn","some","combiner","cloneDeep","getJsonPathsToExamples","buildValidationMap","pathsExamples","reduce","validationMap","pathExample","pathSchema","pathSegs","toPathArray","slice","idxExamples","lastIndexOf","splice","toPathString","_getSchemaPathOfExample","escapeExampleName","rawPath","prepare","openapiSpecCopy","unescapeExampleNames","ExampleType","exampleTypesOfSchemas","Map","pathSchemaAsArray","exampleType","idxExample","exampleTypeOfSchema","get","pathContextAsArray","create","pathContext","toPointer","_throwMutuallyExclusiveError","set","replace","flatMap","fs","glob","yaml","refParser","createError","getValidatorFactory","compileValidate","Determiner","createValidationResponse","dereferenceJsonSchema","SYM__INTERNAL","Symbol","PROP__SCHEMAS_WITH_EXAMPLES","FILE_EXTENSIONS__YAML","ErrorJsonPathNotFound","validateExamples","impl","dereference","res","pathToExamples","concat","jsonPathToExamples","_extractExamplePaths","map","_initStatistics","validationResult","createValidator","_initValidatorFactory","error","example","_getObjectByPath","_extractSchema","curErrors","_validateExample","_validateSchema","_validateExamplesPaths","_parseSpec","filePath","isYaml","extension","pop","includes","_isFileTypeYaml","jsonSchema","parse","readFileSync","e","name","_validate","validationHandler","_handleExamplesByMapValidation","mapExternalExamples","dirPathMapExternalExamples","entries","filePathsExample","filePathExample","examples","resolvedFilePathExample","globResolvedFilePathExample","sync","normalize","content","defineProperty","enumerable","size","wrap","validate","exampleFilePath","specSchema","schemaId","discriminator","strict","allErrors","formats","suppressErrorIfNotFound","filePathSchema","globMapExternalExamples","filePathsMaps","nonull","responses","filePathMapExternalExamples","dirname","mapFilePath","response","response2","response1","key","val","schemasWithExample","values","pathToSchema","currentWorkingDir","cwd","chdir","dereferencedSchema","JsonPointer","Ajv","addFormats","JSON_PATH__REFS","ID__SPEC_SCHEMA","preparedSpecSchema","refSchema","substring","definition","_createReferenceSchema","validator","addSchema","responseSchema","preparedResponseSchema","idSchema","preparedSchema","_prepareResponseSchema","payload","compile","__webpack_module_cache__","__webpack_exports__","__webpack_require__","moduleId","cachedModule","undefined","__webpack_modules__"],"sourceRoot":""} \ No newline at end of file +{"version":3,"file":"cli.js","mappings":";2BAAA,MACIA,EAAQC,EAAQ,MAChB,OAAEC,GAAWD,EAAAA,KAAAA,KA6BXE,EAAY,CACdC,SAAUF,EAAOG,KACjBC,iBAAkB,mBAClBC,gCAAiC,+BACjCC,WAAY,aACZC,WAAY,cAQhB,MAAMC,EAQFC,cAAcC,GACV,MAAM,KAAEP,EAAI,QAAEQ,EAAO,KAAEC,EAAI,MAAEC,GAAUH,EACnCI,EAAOX,GAAQO,EAAII,MAAQb,EAAUM,WACrCQ,EAAU,CAAEJ,WAShB,OARIV,EAAUM,aAAeO,GAAQb,EAAUI,kCAAoCS,EAE/EhB,EAAMiB,EAASL,IAGfE,GAAQd,EAAMiB,EAAS,CAAEC,OAAQ,CAAEJ,UACnCC,GAASf,EAAMiB,EAASF,IAErB,IAAIL,EAAiBM,EAAMC,EACtC,CAOAE,YAAYH,EAAMC,EAAU,CAAC,GACzBG,OAAOC,OAAOC,KAAM,CAChBN,UACGC,GAEX,EAKJM,EAAOC,QAAU,CACbd,mBACAP,Y,gBC7EJ,MACIsB,EAAUxB,EAAAA,KAAAA,QACVyB,EAAUzB,EAAQ,MAClB,aAAE0B,EAAY,gBAAEC,EAAe,sBAAEC,GAA0B5B,EAAQ,KAIjE6B,EAA4D,SAAjDC,QAAQC,IAAIC,iCAI7BP,EACKQ,QAAQT,GACRU,UAAU,cACVC,YAAY,kOAGZC,OAAO,0CAA2C,gEAClDA,OAAO,4CAA6C,8CACpDA,OAAO,4CAA6C,6JAEpDA,OAAO,4BAA6B,k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vB,QAAQ,mB,uBCAzBsB,EAAOC,QAAUvB,QAAQ,iB,uBCAzBsB,EAAOC,QAAUvB,QAAQ,iB,uBCAzBsB,EAAOC,QAAUvB,QAAQ,e,sBCAzBsB,EAAOC,QAAUvB,QAAQ,O,uBCAzBsB,EAAOC,QAAUvB,QAAQ,K,sBCAzBsB,EAAOC,QAAUvB,QAAQ,O,GCCrBwS,EAA2B,CAAC,ECE5BC,EDCJ,SAASC,EAAoBC,GAE5B,IAAIC,EAAeJ,EAAyBG,GAC5C,QAAqBE,IAAjBD,EACH,OAAOA,EAAarR,QAGrB,IAAID,EAASkR,EAAyBG,GAAY,CAGjDpR,QAAS,CAAC,GAOX,OAHAuR,EAAoBH,GAAUrR,EAAQA,EAAOC,QAASmR,GAG/CpR,EAAOC,OACf,CCnB0BmR,CAAoB,K","sources":["webpack://openapi-examples-validator/./src/application-error.js","webpack://openapi-examples-validator/./src/cli.js","webpack://openapi-examples-validator/./src/const/result-type.js","webpack://openapi-examples-validator/./src/impl/index.js","webpack://openapi-examples-validator/./src/impl/service/all-properties-required.js","webpack://openapi-examples-validator/./src/impl/service/common.js","webpack://openapi-examples-validator/./src/impl/service/no-additional-properties.js","webpack://openapi-examples-validator/./src/impl/v2/index.js","webpack://openapi-examples-validator/./src/impl/v3/index.js","webpack://openapi-examples-validator/./src/index.js","webpack://openapi-examples-validator/./src/utils/index.js","webpack://openapi-examples-validator/./src/validator.js","webpack://openapi-examples-validator/./package.json","webpack://openapi-examples-validator/external commonjs \"ajv-draft-04\"","webpack://openapi-examples-validator/external commonjs \"ajv-formats\"","webpack://openapi-examples-validator/external commonjs \"commander\"","webpack://openapi-examples-validator/external commonjs \"errno\"","webpack://openapi-examples-validator/external commonjs \"glob\"","webpack://openapi-examples-validator/external commonjs \"json-pointer\"","webpack://openapi-examples-validator/external commonjs \"json-schema-ref-parser\"","webpack://openapi-examples-validator/external commonjs \"jsonpath-plus\"","webpack://openapi-examples-validator/external commonjs \"lodash.clonedeep\"","webpack://openapi-examples-validator/external commonjs \"lodash.flatmap\"","webpack://openapi-examples-validator/external commonjs \"lodash.flatten\"","webpack://openapi-examples-validator/external commonjs \"lodash.merge\"","webpack://openapi-examples-validator/external commonjs \"yaml\"","webpack://openapi-examples-validator/external node-commonjs \"fs\"","webpack://openapi-examples-validator/external node-commonjs \"path\"","webpack://openapi-examples-validator/webpack/bootstrap","webpack://openapi-examples-validator/webpack/startup"],"sourcesContent":["const\n merge = require('lodash.merge'),\n { ENOENT } = require('errno').code;\n\n// TYPEDEFINITIONS\n\n/**\n * @typedef {{}} CustomError\n * @augments Error\n */\n\n/**\n * ApplicationErrorOptions\n * @typedef {{\n * [instancePath]: string,\n * [examplePath]: string,\n * [exampleFilePath]: string,\n * [keyword]: string,\n * [message]: string,\n * [mapFilePath]: string,\n * [params]: {\n * [path]: string,\n * [missingProperty]: string,\n * [type]: string\n * },\n * [schemaPath]: string\n * }} ApplicationErrorOptions\n */\n\n// CONSTANTS\n\nconst ErrorType = {\n jsENOENT: ENOENT.code,\n jsonPathNotFound: 'JsonPathNotFound',\n errorAndErrorsMutuallyExclusive: 'ErrorErrorsMutuallyExclusive',\n parseError: 'ParseError',\n validation: 'Validation'\n};\n\n// CLASSES\n\n/**\n * Unified application-error\n */\nclass ApplicationError {\n /**\n * Factory-function, which is able to consume validation-errors and JS-errors. If a validation error is passed, all\n * properties will be adopted.\n * @param {Error|CustomError} err Javascript-, validation- or custom-error, to create the application-error\n * from\n * @returns {ApplicationError} Unified application-error instance\n */\n static create(err) {\n const { code, message, path, cause } = err, // Certain properties of Javascript-errors\n type = code || err.type || ErrorType.validation, // If `code` is available then it's a Javascript-error\n options = { message };\n if (ErrorType.validation === type || ErrorType.errorAndErrorsMutuallyExclusive === type) {\n // For certain, created error-types, copy all properties\n merge(options, err);\n } else {\n // Copy certain properties of Javascript-error (but only if available)\n path && merge(options, { params: { path } });\n cause && merge(options, cause);\n }\n return new ApplicationError(type, options);\n }\n\n /**\n * Constructor\n * @param {string} type Type of error (see statics)\n * @param {ApplicationErrorOptions} [options] Optional properties\n */\n constructor(type, options = {}) {\n Object.assign(this, {\n type,\n ...options\n });\n }\n}\n\n// PUBLIC API\n\nmodule.exports = {\n ApplicationError,\n ErrorType\n};\n","// Shebang will be added by webpack\n//#!/usr/bin/env node --harmony\n\n/**\n * Command Line Interface for the validator\n */\n\nconst\n VERSION = require('../package.json').version,\n program = require('commander'),\n { validateFile, validateExample, validateExamplesByMap } = require('./index');\n\n// FOR AUTOMATED TESTS\n\nconst ENV_TEST = process.env.OPENAPI_EXAMPLES_VALIDATOR_TESTS === 'true';\n\n// DEFINE CLI\n\nprogram\n .version(VERSION)\n .arguments('')\n .description('Validate embedded examples in OpenAPI-specs (JSON and YAML supported).\\n'\n + ' To validate external examples, use the `-s` and `-e` option.\\n'\n + ' To pass a mapping-file, to validate multiple external examples, use the `-m` option.')\n .option('-s, --schema-jsonpath ', 'Path to OpenAPI-schema, to validate the example file against')\n .option('-e, --example-filepath ', 'file path to example file, to be validated')\n .option('-m, --mapping-filepath ', 'file path to map, containing schema-paths as key and the'\n + ' file-path(s) to examples as value. If wildcards are used, the parameter has to be put in quotes.')\n .option('-c, --cwd-to-mapping-file', \"changes to the directory of the mapping-file, before resolving the example's\"\n + ' paths. Use this option, if your mapping-files use relative paths for the examples')\n .option('-n, --no-additional-properties', 'don\\'t allow properties that are not described in the schema')\n .option('-r, --all-properties-required', 'make all the properties in the schema required')\n .option('-o, --ignore-formats ', 'Datatype formats to ignore '\n + '(to prevent \"unknown format\" message in the error-console.)')\n .action(processAction);\nprogram.on('--help', () => {\n console.log('\\n\\n Example for external example-file:\\n');\n console.log(' $ openapi-examples-validator -s $.paths./.get.responses.200.schema -e example.json'\n + ' openapi-spec.json\\n\\n');\n});\n// Execute and export promise (for automated tests)\nmodule.exports = program.parseAsync(process.argv);\n\n// IMPLEMENTATION DETAILS\n\nasync function processAction(filepath, options) {\n const { schemaJsonpath, exampleFilepath, mappingFilepath, cwdToMappingFile, allPropertiesRequired } = options,\n noAdditionalProperties = !options.additionalProperties,\n ignoreFormats = _prepareIgnoreFormats(options.ignoreFormats);\n let result;\n if (mappingFilepath) {\n console.log('Validating with mapping file');\n result = await validateExamplesByMap(filepath, mappingFilepath, {\n cwdToMappingFile,\n noAdditionalProperties,\n ignoreFormats,\n allPropertiesRequired\n });\n } else if (schemaJsonpath && exampleFilepath) {\n console.log('Validating single external example');\n result = await validateExample(filepath, schemaJsonpath, exampleFilepath, {\n noAdditionalProperties,\n ignoreFormats,\n allPropertiesRequired\n });\n } else {\n console.log('Validating examples');\n result = await validateFile(filepath, {\n noAdditionalProperties,\n ignoreFormats,\n allPropertiesRequired\n });\n }\n _handleResult(result);\n}\n\nfunction _handleResult(result) {\n const noExit = ENV_TEST;\n _printStatistics(result.statistics);\n if (result.valid) {\n process.stdout.write('\\nNo errors found.\\n\\n');\n !noExit && process.exit(0);\n return;\n }\n process.stdout.write('\\nErrors found.\\n\\n');\n process.stderr.write(JSON.stringify(result.errors, null, ' '));\n !noExit && process.exit(1);\n}\n\nfunction _printStatistics(statistics) {\n const {\n schemasWithExamples,\n examplesWithoutSchema,\n examplesTotal,\n matchingFilePathsMapping\n } = statistics,\n strStatistics = [\n `Schemas with examples found: ${ schemasWithExamples }`,\n `Examples without schema found: ${ examplesWithoutSchema }`,\n `Total examples found: ${ examplesTotal }`\n ];\n if (matchingFilePathsMapping != null) {\n strStatistics.push(`Matching mapping files found: ${ matchingFilePathsMapping }`);\n }\n process.stdout.write(`${ strStatistics.join('\\n') }\\n`);\n}\n\nfunction _prepareIgnoreFormats(ignoreFormats) {\n if (ignoreFormats == null || !Array.isArray(ignoreFormats)) { return ignoreFormats; }\n if (ignoreFormats.length !== 1) { return ignoreFormats; }\n // If only one argument has been passed, with all formats separated by newlines\n if (ignoreFormats[0].indexOf('\\n') === -1) { return ignoreFormats; }\n return ignoreFormats[0].split('\\n').filter(entry => !entry.match(/^\\s*$/));\n}\n","module.exports = {\n parent: 'parent',\n parentProperty: 'parentProperty',\n path: 'path',\n pointer: 'pointer',\n value: 'value'\n};\n","/**\n * Entry point for logic that only applies to specific versions of the OpenAPI-spec\n */\n\nconst implV2 = require('./v2/index'),\n implV3 = require('./v3/index');\n\nconst REGEX__OPEN_API = /^3\\./;\n\nmodule.exports = {\n getImplementation\n};\n\n/**\n * Get the version-specific implementation for the OpenAPI-spec. Currently v2 and v3 are supported\n * @param {Object} openapiSpec OpenAPI-spec\n * @returns {Object|null}\n */\nfunction getImplementation(openapiSpec) {\n if (typeof openapiSpec.swagger === 'string') {\n return implV2;\n }\n if (openapiSpec.openapi && openapiSpec.openapi.match(REGEX__OPEN_API)) {\n return implV3;\n }\n return null;\n}\n","const { applyCallbackToAllObjectModels } = require('./common');\n\nmodule.exports = {\n setAllPropertiesRequired\n};\n\n/**\n * Sets all properties of each object to required\n * @param {Object} openApiSpec The to-be-modified schema\n * @param {Array.} [examplePaths=[]] The paths to the examples, which's content must not be modified\n */\nfunction setAllPropertiesRequired(openApiSpec, examplePaths = []) {\n applyCallbackToAllObjectModels(openApiSpec, examplePaths,\n () => {\n return (value) => {\n if (value.hasOwnProperty('properties')) {\n value.required = Object.keys(value.properties);\n }\n };\n });\n}\n","const { JSONPath: jsonPath } = require('jsonpath-plus'),\n ResultType = require('../../const/result-type');\n\nmodule.exports = {\n applyCallbackToAllObjectModels\n};\n\n/**\n * @typedef {{\n * path: String,\n * value: Object,\n * parent: Object,\n * parentProperty: String,\n * hasArrExpr: Boolean\n * }} JsonPathMatchData\n */\n\n/**\n * Callback that is applied to a JSONPath-match.\n * @callback JsonPathMatchCallback\n * @param {Object} value Value of the matched property\n * @param {String} resultType Result-type of the query\n * @param {JsonPathMatchData} data Object that contains additional data to the match\n */\n\n/**\n * Function to build a callback that is applied to a JSONPath-match.\n * @callback JsonPathMatchCallbackBuilder\n * @param {string} jsPath Path to the property that matched\n * @return {JsonPathMatchCallback} Callback that is applied to a JSONPath-match\n */\n\n/**\n * Apply the input rule to all models of type object in the input openApiSpec\n * @param {Object} openApiSpec The to-be-modified schema\n * @param {Array.} [examplePaths] The paths to the examples, which's content must not be modified\n * @param {JsonPathMatchCallbackBuilder} [matchCallbackBuilder] Function to build a callback\n * that will be called on each match\n */\nfunction applyCallbackToAllObjectModels(openApiSpec, examplePaths, matchCallbackBuilder) {\n // Find all matches\n const paths = new Set();\n _find(openApiSpec, '$..schema..')\n .forEach(match => {\n if (_isPropertiesDefinition(match)) { return; }\n paths.add(match);\n });\n // Exclude examples\n _excludeExamples(openApiSpec, paths, examplePaths);\n // Set flag\n for (const jsPath of paths) {\n const callback = matchCallbackBuilder(jsPath);\n _find(openApiSpec, jsPath, ResultType.value, (result, resultType, data) => {\n if (!_isObjectDefinition(result)) { return; }\n callback(result, resultType, data);\n });\n }\n}\n\n/**\n * Find matching elements in JSON.\n * @param {Object} json JSON to be searched\n * @param {String} path JSON-path to search\n * @param {String} [resultType=\"path\"] Result-type of the query\n * @param {JsonPathMatchCallback} [callback] Function to be called on a match\n * @returns {any} Result of the query, depending on the `resultType`\n * @private\n */\nfunction _find(json, path, resultType = ResultType.path, callback) {\n return jsonPath({\n json,\n path,\n flatten: true,\n resultType,\n callback\n });\n}\n\n/**\n * Remove JSON-paths from `paths` that are included in `examplePaths`\n * @param {Object} openApiSpec Open-API spec to search in\n * @param {Set.} paths Paths where the examples have to be removed from\n * @param {Array.} examplePaths JSON-paths of the examples\n * @private\n */\nfunction _excludeExamples(openApiSpec, paths, examplePaths) {\n examplePaths\n .forEach(examplePath => {\n _find(openApiSpec, examplePath)\n .forEach(exampleMatch => {\n for (const jsPath of paths) {\n jsPath.startsWith(exampleMatch) && paths.delete(jsPath);\n }\n });\n });\n}\n\nfunction _isPropertiesDefinition(path) {\n // Path has to end with `properties`\n if (!path.match(/\\['properties']$/)) { return; }\n // Every second consecutive `properties` actually is not a property-definition, but a property itself\n const consecutiveMatch = path.match(/(?} [examplePaths=[]] The paths to the examples, which's content must not be modified\n */\nfunction setNoAdditionalProperties(openApiSpec, examplePaths = []) {\n // Match all combiner keywords that are not preceded by a 'properties' keyword.\n // This allow to have objects that have as property name one of the combiner keywords.\n const hasJsonCombinerParentRegex\n = new RegExp('(? {\n return (schema) => {\n // Exclude schema that have a JSON combiner as parent\n if (hasJsonCombinerParentRegex.test(path)) {\n console.warn('\"additionalProperties\" flag not set '\n + `for ${path} because it has a parent with a JSON-schema combiner keyword.`);\n return;\n }\n // Exclude schema that contains a JSON combiner\n if (JSON_SCHEMA_COMBINERS.some((combiner) => schema.hasOwnProperty(combiner))) {\n console.warn('\"additionalProperties\" flag not set '\n + `for ${path} because it contains JSON-schema combiner keyword.`);\n return;\n }\n // Exclude schema that already contains additionalProperties\n if (schema.hasOwnProperty('additionalProperties')) {\n return;\n }\n schema.additionalProperties = false;\n };\n });\n}\n","/**\n * Contains validation-logic that is specific to V2 of the OpenAPI-spec\n */\n\nconst cloneDeep = require('lodash.clonedeep'),\n { setAllPropertiesRequired } = require('../service/all-properties-required'),\n { setNoAdditionalProperties } = require('../service/no-additional-properties');\n\n// CONSTANTS\n\nconst PATH__EXAMPLES = '$..examples[?(@property.match(/[\\/+]json/))]',\n PROP__SCHEMA = 'schema',\n PROP__EXAMPLES = 'examples';\n\nmodule.exports = {\n buildValidationMap,\n getJsonPathsToExamples,\n prepare\n};\n\n// IMPLEMENTATION DETAILS\n\n/**\n * Get the JSONPaths to the examples\n * @returns {Array.} JSONPaths to the examples\n */\nfunction getJsonPathsToExamples() { return [PATH__EXAMPLES]; }\n\n\n\n/**\n * Builds a map with the json-pointers to the response-schema as key and the json-pointers to the examples, as value.\n * The pointer of the schema is derived from the pointer to the example and doesn't necessarily mean\n * that the schema actually exists.\n * @param {Array.} pathsExamples Paths to the examples\n * @returns {Object.} Map with schema-pointers as key and example-pointers as value\n * @private\n */\nfunction buildValidationMap(pathsExamples) {\n return pathsExamples.reduce((validationMap, pathExample) => {\n const pathSchema = _getSchemaPointerOfExample(pathExample);\n validationMap[pathSchema] = (validationMap[pathSchema] || new Set())\n .add(pathExample);\n return validationMap;\n }, {});\n}\n\n/**\n * Pre-processes the OpenAPI-spec, for further use.\n * The passed spec won't be modified. If a modification happens, a modified copy will be returned.\n * @param {Object} openapiSpec The OpenAPI-spec as JSON-schema\n * @param {boolean} [noAdditionalProperties=false] Don't allow properties that are not defined in the schema\n * @param {boolean} [allPropertiesRequired=false] Make all properties required\n * @return {Object} The prepared OpenAPI-spec\n */\nfunction prepare(openapiSpec, { noAdditionalProperties, allPropertiesRequired } = {}) {\n const openapiSpecCopy = cloneDeep(openapiSpec);\n noAdditionalProperties && setNoAdditionalProperties(openapiSpecCopy, getJsonPathsToExamples());\n allPropertiesRequired && setAllPropertiesRequired(openapiSpecCopy, getJsonPathsToExamples());\n return openapiSpecCopy;\n}\n\n/**\n * Gets a JSON-pointer to the corresponding response-schema, based on a JSON-pointer to an example.\n * @param {String} examplePointer JSON-pointer to example\n * @returns {String} JSON-pointer to the corresponding response-schema\n * @private\n */\nfunction _getSchemaPointerOfExample(examplePointer) {\n const pathSegs = examplePointer.split('/'),\n idxExamples = pathSegs.lastIndexOf(PROP__EXAMPLES);\n pathSegs.splice(idxExamples, pathSegs.length - idxExamples, PROP__SCHEMA);\n return pathSegs.join('/');\n}\n","/**\n * Contains validation-logic that is specific to V3 of the OpenAPI-spec\n */\n\nconst cloneDeep = require('lodash.clonedeep'),\n { ApplicationError, ErrorType } = require('../../application-error'),\n { setAllPropertiesRequired } = require('../service/all-properties-required'),\n { setNoAdditionalProperties } = require('../service/no-additional-properties');\n\n// CONSTANTS\n\nconst RESPONSES = '$..responses..content[?(@property.match(/[\\/+]json/))]';\nconst REQUEST = '$..requestBody.content[?(@property.match(/[\\/+]json/))]';\nconst SINGLE_EXAMPLE = '.example';\nconst MANY_EXAMPLES = '.examples.*.value';\n\nconst PATH__EXAMPLE = `${RESPONSES}${SINGLE_EXAMPLE}`,\n PATH__EXAMPLES = `${RESPONSES}${MANY_EXAMPLES}`,\n PATH__EXAMPLE__PARAMETER = '$..parameters..example',\n PATH__EXAMPLES__PARAMETER = '$..parameters..examples.*.value',\n PATH__EXAMPLE__REQUEST_BODY = `${REQUEST}${SINGLE_EXAMPLE}`,\n PATH__EXAMPLES__REQUEST_BODY = `${REQUEST}${MANY_EXAMPLES}`,\n PROP__SCHEMA = 'schema',\n PROP__EXAMPLE = 'example',\n PROP__EXAMPLES = 'examples';\n\nconst ExampleType = {\n single: 'single',\n multi: 'multi'\n};\n\n// PUBLIC API\n\nmodule.exports = {\n buildValidationMap,\n getJsonPathsToExamples,\n prepare\n};\n\n// IMPLEMENTATION DETAILS\n\n/**\n * Get the JSONPaths to the examples\n * @returns {Array.} JSONPaths to the examples\n */\nfunction getJsonPathsToExamples() {\n return [\n PATH__EXAMPLE,\n PATH__EXAMPLES,\n PATH__EXAMPLE__PARAMETER,\n PATH__EXAMPLES__PARAMETER,\n PATH__EXAMPLE__REQUEST_BODY,\n PATH__EXAMPLES__REQUEST_BODY\n ];\n}\n\n/**\n * Builds a map with the json-pointers to the response-schema as key and the json-pointers to the examples, as value.\n * The pointer of the schema is derived from the pointer to the example and doesn't necessarily mean\n * that the schema actually exists.\n * @param {Array.} pathsExamples Paths to the examples\n * @returns {Object.} Map with schema-pointers as key and example-pointers as value\n * @private\n */\nfunction buildValidationMap(pathsExamples) {\n const exampleTypesOfSchemas = new Map();\n return pathsExamples.reduce((validationMap, pathExample) => {\n const { pathSchemaAsArray, exampleType } = _getSchemaPointerOfExample(pathExample),\n pathSchema = pathSchemaAsArray.join('/'),\n exampleTypeOfSchema = exampleTypesOfSchemas.get(pathSchema);\n if (exampleTypeOfSchema) {\n exampleTypeOfSchema !== exampleType && _throwMutuallyExclusiveError(pathSchemaAsArray);\n }\n exampleTypesOfSchemas.set(pathSchema, exampleType);\n validationMap[pathSchema] = (validationMap[pathSchema] || new Set())\n .add(pathExample);\n return validationMap;\n }, {});\n}\n\n/**\n * Pre-processes the OpenAPI-spec, for further use.\n * The passed spec won't be modified. If a modification happens, a modified copy will be returned.\n * @param {Object} openapiSpec The OpenAPI-spec as JSON-schema\n * @param {boolean} [noAdditionalProperties=false] Don't allow properties that are not defined in the schema\n * @param {boolean} [allPropertiesRequired=false] Make all properties required\n * @return {Object} The prepared OpenAPI-spec\n */\nfunction prepare(openapiSpec, { noAdditionalProperties, allPropertiesRequired } = {}) {\n const openapiSpecCopy = cloneDeep(openapiSpec);\n noAdditionalProperties && setNoAdditionalProperties(openapiSpecCopy, getJsonPathsToExamples());\n allPropertiesRequired && setAllPropertiesRequired(openapiSpecCopy, getJsonPathsToExamples());\n return openapiSpecCopy;\n}\n\n/**\n * Gets a JSON-pointer to the corresponding response-schema, based on a JSON-pointer to an example.\n *\n * It is assumed that the JSON-pointer to the example is valid and existing.\n * @param {String} examplePointer JSON-pointer to example\n * @returns {{\n * exampleType: ExampleType,\n * pathSchema: String\n * }} JSON-path to the corresponding response-schema\n * @private\n */\nfunction _getSchemaPointerOfExample(examplePointer) {\n const pathSegs = examplePointer.split('/'),\n idxExample = pathSegs.lastIndexOf(PROP__EXAMPLE),\n /** @type ExampleType */\n exampleType = idxExample > -1\n ? ExampleType.single\n : ExampleType.multi,\n idxExamples = exampleType === ExampleType.single\n ? idxExample\n : pathSegs.lastIndexOf(PROP__EXAMPLES);\n pathSegs.splice(idxExamples, pathSegs.length - idxExamples, PROP__SCHEMA);\n return {\n exampleType,\n pathSchemaAsArray: pathSegs\n };\n}\n\n\n/**\n * Checks if only `example` or `examples` is set for the schema, as they are mutually exclusive by OpenAPI-spec.\n * @param {Array.} pathSchemaAsArray JSON-path to the Schema, as JSON-path-array\n * @throws ApplicationError if both are set\n * @private\n */\nfunction _throwMutuallyExclusiveError(pathSchemaAsArray) {\n const pathContextAsArray = pathSchemaAsArray.slice(0, pathSchemaAsArray.length - 1); // Strip `schema` away\n throw ApplicationError.create({\n type: ErrorType.errorAndErrorsMutuallyExclusive,\n message: 'Properties \"error\" and \"errors\" are mutually exclusive',\n params: {\n pathContext: pathContextAsArray.join('/')\n }\n });\n}\n","/**\n * Entry-point for the validator-API\n */\n\nconst\n merge = require('lodash.merge'),\n flatten = require('lodash.flatten'),\n flatMap = require('lodash.flatmap'),\n jsonPointer = require('json-pointer'),\n fs = require('fs'),\n path = require('path'),\n glob = require('glob'),\n yaml = require('yaml'),\n { JSONPath: jsonPath } = require('jsonpath-plus'),\n refParser = require('json-schema-ref-parser'),\n { createError } = require('errno').custom,\n ResultType = require('./const/result-type'),\n { getValidatorFactory, compileValidate } = require('./validator'),\n Determiner = require('./impl'),\n { ApplicationError, ErrorType } = require('./application-error'),\n { createValidationResponse, dereferenceJsonSchema } = require('./utils');\n\n// CONSTANTS\n\nconst SYM__INTERNAL = Symbol('internal'),\n PROP__SCHEMAS_WITH_EXAMPLES = 'schemasWithExamples',\n FILE_EXTENSIONS__YAML = [\n 'yaml',\n 'yml'\n ];\n\n// STATICS\n\n/**\n * ErrorJsonPathNotFound\n * @typedef {{\n * cause: {\n * [params]: {\n * [path]: string\n * }\n * }\n * }} ErrorJsonPathNotFound\n * @augments CustomError\n */\n\n/**\n * @constructor\n * @augments CustomError\n * @returns {ErrorJsonPathNotFound}\n */\nconst ErrorJsonPathNotFound = createError(ErrorType.jsonPathNotFound);\n\n// PUBLIC API\n\nmodule.exports = {\n 'default': validateExamples,\n validateFile,\n validateExample,\n validateExamplesByMap,\n getValidatorFactory\n};\n\n// IMPLEMENTATION DETAILS\n\n// Type definitions\n\n/**\n * ValidationStatistics\n * @typedef {{\n * schemasWithExamples: number,\n * examplesTotal: number,\n * examplesWithoutSchema: number,\n * [matchingFilePathsMapping]: number\n * }} ValidationStatistics\n */\n\n/**\n * ValidationResponse\n * @typedef {{\n * valid: boolean,\n * statistics: ValidationStatistics,\n * errors: Array.\n * }} ValidationResponse\n */\n\n/**\n * @callback ValidationHandler\n * @param {ValidationStatistics} statistics\n * @returns {Array.}\n */\n\n// Public\n\n/**\n * Validates OpenAPI-spec with embedded examples.\n * @param {Object} openapiSpec OpenAPI-spec\n * @param {boolean} [noAdditionalProperties=false] Don't allow properties that are not defined in the schema\n * @param {boolean} [allPropertiesRequired=false] Make all properties required\n * @param {Array.} [ignoreFormats] List of datatype formats that shall be ignored (to prevent\n * \"unsupported format\" errors). If an Array with only one string is\n * provided where the formats are separated with `\\n`, the entries\n * will be expanded to a new array containing all entries.\n * @param {Function} [specPostprocessor] Provides implementation of spec postprocessor\n * @param {Function} [validatorFactory] Validator factory provider\n * @returns {ValidationResponse}\n */\nasync function validateExamples(openapiSpec, { noAdditionalProperties, ignoreFormats, allPropertiesRequired,\n specPostprocessor = (spec) => spec,\n validatorFactory = (spec, { ignoreFormats }) => _initValidatorFactory(spec, { ignoreFormats })\n} = {}) {\n const impl = Determiner.getImplementation(openapiSpec);\n openapiSpec = await refParser.dereference(openapiSpec);\n openapiSpec = impl.prepare(openapiSpec, { noAdditionalProperties, allPropertiesRequired });\n if (typeof specPostprocessor === 'function') {\n openapiSpec = specPostprocessor(openapiSpec);\n }\n let pathsExamples = impl.getJsonPathsToExamples()\n .reduce((res, pathToExamples) => {\n return res.concat(_pathToPointer(openapiSpec, pathToExamples));\n }, [])\n .map(impl.escapeExampleName);\n const createValidator = validatorFactory(openapiSpec, { ignoreFormats });\n return _validateExamplesPaths({ impl, createValidator }, pathsExamples, openapiSpec);\n}\n\n/**\n * Validates OpenAPI-spec with embedded examples.\n * @param {string} filePath File-path to the OpenAPI-spec\n * @param {boolean} [noAdditionalProperties=false] Don't allow properties that are not defined in the schema\n * @param {boolean} [allPropertiesRequired=false] Make all properties required\n * @param {Array.} [ignoreFormats] List of datatype formats that shall be ignored (to prevent\n * \"unsupported format\" errors). If an Array with only one string is\n * provided where the formats are separated with `\\n`, the entries\n * will be expanded to a new array containing all entries.\n * @returns {ValidationResponse}\n */\nasync function validateFile(filePath, { noAdditionalProperties, ignoreFormats, allPropertiesRequired } = {}) {\n let openapiSpec = null;\n try {\n openapiSpec = await _parseSpec(filePath);\n } catch (err) {\n return createValidationResponse({ errors: [ApplicationError.create(err)] });\n }\n return validateExamples(openapiSpec, { noAdditionalProperties, ignoreFormats, allPropertiesRequired });\n}\n\n/**\n * Validates examples by mapping-files.\n * @param {string} filePathSchema File-path to the OpenAPI-spec\n * @param {string} globMapExternalExamples File-path (globs are supported) to the mapping-file containing JSON-\n * paths to schemas as key and a single file-path or Array of file-paths\n * to external examples\n * @param {boolean} [cwdToMappingFile=false] Change working directory for resolving the example-paths (relative to\n * the mapping-file)\n * @param {boolean} [noAdditionalProperties=false] Don't allow properties that are not defined in the schema\n * @param {boolean} [allPropertiesRequired=false] Make all properties required\n * @param {Array.} [ignoreFormats] List of datatype formats that shall be ignored (to prevent\n * \"unsupported format\" errors). If an Array with only one string is\n * provided where the formats are separated with `\\n`, the entries\n * will be expanded to a new array containing all entries.\n * @returns {ValidationResponse}\n */\nasync function validateExamplesByMap(filePathSchema, globMapExternalExamples,\n { cwdToMappingFile, noAdditionalProperties, ignoreFormats, allPropertiesRequired } = {}\n) {\n let matchingFilePathsMapping = 0;\n const filePathsMaps = glob.sync(\n globMapExternalExamples,\n // Using `nonull`-option to explicitly create an app-error if there's no match for `globMapExternalExamples`\n { nonull: true }\n );\n let responses = [];\n // for..of here, to support sequential execution of async calls. This is required, since dereferencing the\n // `openapiSpec` is not concurrency-safe\n for (const filePathMapExternalExamples of filePathsMaps) {\n let mapExternalExamples = null,\n openapiSpec = null;\n try {\n mapExternalExamples = JSON.parse(fs.readFileSync(filePathMapExternalExamples, 'utf-8'));\n openapiSpec = await _parseSpec(filePathSchema);\n openapiSpec = Determiner.getImplementation(openapiSpec)\n .prepare(openapiSpec, { noAdditionalProperties, allPropertiesRequired });\n } catch (err) {\n responses.push(createValidationResponse({ errors: [ApplicationError.create(err)] }));\n continue;\n }\n // Not using `glob`'s response-length, because it is `1` if there's no match for `globMapExternalExamples`.\n // Instead, increment on every match\n matchingFilePathsMapping++;\n responses.push(\n _validate(\n statistics => {\n return _handleExamplesByMapValidation(\n openapiSpec, mapExternalExamples, statistics, {\n cwdToMappingFile,\n dirPathMapExternalExamples: path.dirname(filePathMapExternalExamples),\n ignoreFormats\n }\n ).map(\n (/** @type ApplicationError */ error) => Object.assign(error, {\n mapFilePath: path.normalize(filePathMapExternalExamples)\n })\n );\n }\n )\n );\n }\n return merge(\n responses.reduce((res, response) => {\n if (!res) {\n return response;\n }\n return _mergeValidationResponses(res, response);\n }, null),\n { statistics: { matchingFilePathsMapping } }\n );\n}\n\n/**\n * Validates a single external example.\n * @param {String} filePathSchema File-path to the OpenAPI-spec\n * @param {String} pathSchema JSON-path to the schema\n * @param {String} filePathExample File-path to the external example-file\n * @param {boolean} [noAdditionalProperties=false] Don't allow properties that are not described in the schema\n * @param {boolean} [allPropertiesRequired=false] Make all properties required\n * @param {Array.} [ignoreFormats] List of datatype formats that shall be ignored (to prevent\n * \"unsupported format\" errors). If an Array with only one string is\n * provided where the formats are separated with `\\n`, the entries\n * will be expanded to a new array containing all entries.\n * @returns {ValidationResponse}\n */\nasync function validateExample(filePathSchema, pathSchema, filePathExample, {\n noAdditionalProperties,\n ignoreFormats,\n allPropertiesRequired\n} = {}) {\n let example = null,\n schema = null,\n openapiSpec = null;\n try {\n example = JSON.parse(fs.readFileSync(filePathExample, 'utf-8'));\n openapiSpec = await _parseSpec(filePathSchema);\n openapiSpec = Determiner.getImplementation(openapiSpec)\n .prepare(openapiSpec, { noAdditionalProperties, allPropertiesRequired });\n schema = _extractSchema(_getSchmaPointer(pathSchema, openapiSpec), openapiSpec);\n } catch (err) {\n return createValidationResponse({ errors: [ApplicationError.create(err)] });\n }\n return _validate(\n statistics => _validateExample({\n createValidator: _initValidatorFactory(openapiSpec, { ignoreFormats }),\n schema,\n example,\n statistics,\n filePathExample\n })\n );\n}\n\n// Private\n\n/**\n * Parses the OpenAPI-spec (supports JSON and YAML)\n * @param {String} filePath File-path to the OpenAPI-spec\n * @returns {object} Parsed OpenAPI-spec\n * @private\n */\nasync function _parseSpec(filePath) {\n const isYaml = _isFileTypeYaml(filePath);\n let jsonSchema;\n\n if (isYaml) {\n try {\n jsonSchema = yaml.parse(fs.readFileSync(filePath, 'utf-8'));\n } catch (e) {\n const { name, message } = e;\n throw new ApplicationError(ErrorType.parseError, { message: `${name}: ${message}` });\n }\n } else {\n jsonSchema = JSON.parse(fs.readFileSync(filePath, 'utf-8'));\n }\n\n return await dereferenceJsonSchema(filePath, jsonSchema);\n}\n\n/**\n * Determines whether the filePath is pointing to a YAML-file\n * @param {String} filePath File-path to the OpenAPI-spec\n * @returns {boolean} `true`, if the file is a YAML-file\n * @private\n */\nfunction _isFileTypeYaml(filePath) {\n const extension = filePath.split('.').pop();\n return FILE_EXTENSIONS__YAML.includes(extension);\n}\n\n/**\n * Top-level validator. Prepares common values, required for the validation, then calles the validator and prepares\n * the result for the output.\n * @param {ValidationHandler} validationHandler The handler which performs the validation. It will receive the\n * statistics-object as argument and has to return an Array of\n * errors (or an empty Array, when all examples are valid)\n * @returns {ValidationResponse}\n * @private\n */\nfunction _validate(validationHandler) {\n const statistics = _initStatistics(),\n errors = validationHandler(statistics);\n return createValidationResponse({ errors, statistics });\n}\n\n/**\n * Validates examples by a mapping-file.\n * @param {Object} openapiSpec OpenAPI-spec\n * @param {Object} mapExternalExamples Mapping-file containing JSON-paths to schemas as\n * key and a single file-path or Array of file-paths\n * to external examples\n * @param {ValidationStatistics} statistics Validation-statistics\n * @param {boolean} [cwdToMappingFile=false] Change working directory for resolving the example-\n * paths (relative to the mapping-file)\n * @param {string} [dirPathMapExternalExamples] The directory-path of the mapping-file\n * @param {Array.} [ignoreFormats] List of datatype formats that shall be ignored (to prevent\n * \"unsupported format\" errors). If an Array with only one string is\n * provided where the formats are separated with `\\n`, the entries\n * will be expanded to a new array containing all entries.\n * @returns {Array.}\n * @private\n */\nfunction _handleExamplesByMapValidation(openapiSpec, mapExternalExamples, statistics,\n { cwdToMappingFile = false, dirPathMapExternalExamples, ignoreFormats }\n) {\n return flatMap(Object.entries(mapExternalExamples), ([pathSchema, filePathsExample]) => {\n let schema = null;\n try {\n schema = _extractSchema(_getSchmaPointer(pathSchema, openapiSpec), openapiSpec);\n } catch (/** @type ErrorJsonPathNotFound */ err) {\n // If the schema can't be found, don't even attempt to process the examples\n return ApplicationError.create(err);\n }\n return flatMap(\n flatten([filePathsExample]),\n filePathExample => {\n let examples = [];\n try {\n const resolvedFilePathExample = cwdToMappingFile\n ? path.join(dirPathMapExternalExamples, filePathExample)\n : filePathExample;\n const globResolvedFilePathExample = glob.sync(resolvedFilePathExample);\n if (globResolvedFilePathExample.length === 0) {\n return [ApplicationError.create({\n type: ErrorType.jsENOENT,\n message: `No such file or directory: '${resolvedFilePathExample}'`,\n path: resolvedFilePathExample\n })];\n }\n for (const filePathExample of globResolvedFilePathExample) {\n examples.push({\n path: path.normalize(filePathExample),\n content: JSON.parse(fs.readFileSync(filePathExample, 'utf-8'))\n });\n }\n } catch (err) {\n return [ApplicationError.create(err)];\n }\n return flatMap(examples, example => _validateExample({\n createValidator: _initValidatorFactory(openapiSpec, { ignoreFormats }),\n schema,\n example: example.content,\n statistics,\n filePathExample: example.path\n }));\n }\n );\n });\n}\n\n\n/**\n * Merges two `ValidationResponses` together and returns the merged result. The passed `ValidationResponse`s won't be\n * modified.\n * @param {ValidationResponse} response1\n * @param {ValidationResponse} response2\n * @returns {ValidationResponse}\n * @private\n */\nfunction _mergeValidationResponses(response1, response2) {\n return createValidationResponse({\n errors: response1.errors.concat(response2.errors),\n statistics: Object.entries(response1.statistics)\n .reduce((res, [key, val]) => {\n if (PROP__SCHEMAS_WITH_EXAMPLES === key) {\n [\n response1,\n response2\n ].forEach(response => {\n const schemasWithExample = response.statistics[SYM__INTERNAL][PROP__SCHEMAS_WITH_EXAMPLES]\n .values();\n for (let schema of schemasWithExample) {\n res[SYM__INTERNAL][PROP__SCHEMAS_WITH_EXAMPLES].add(schema);\n }\n });\n return res;\n }\n res[key] = val + response2.statistics[key];\n return res;\n }, _initStatistics())\n });\n}\n\n/**\n * Extract JSON-pointer(s) for specific path from a OpenAPI-spec\n * @param {String} path JSON-path in the OpenAPI-Spec\n * @param {Object} openapiSpec OpenAPI-spec\n * @returns {Array.} JSON-pointers to matching elements\n * @private\n */\nfunction _pathToPointer(path, openapiSpec) {\n return jsonPath({\n json: openapiSpec,\n path: path,\n resultType: ResultType.pointer\n });\n}\n/**\n * Extract JSON-pointer(s) for specific path from a OpenAPI-spec\n * @param {String} path JSON-path in the OpenAPI-Spec\n * @param {Object} openapiSpec OpenAPI-spec\n * @returns {String} JSON-pointer to schema or throws error\n * @private\n */\nfunction _getSchmaPointer(pathSchema, openapiSpec) {\n const schemaPointers = _pathToPointer(pathSchema, openapiSpec);\n if (schemaPointers.length === 0) {\n _pathToSchemaNotFoundError(pathSchema);\n }\n if (schemaPointers.length > 1) {\n return [ApplicationError.create({\n type: ErrorType.jsonPathNotFound,\n message: `Path to schema cannot identify unique schema: '${pathSchema}'`,\n path: pathSchema\n })];\n }\n return schemaPointers[0];\n}\n\n/**\n * Validates examples at the given paths in the OpenAPI-spec.\n * @param {Object} impl Spec-dependant validator\n * @param {Function} createValidator Validator factory\n * @param {Array.} pathsExamples JSON-paths to examples\n * @param {Object} openapiSpec OpenAPI-spec\n * @returns {ValidationResponse}\n * @private\n */\nfunction _validateExamplesPaths({ impl, createValidator }, pathsExamples, openapiSpec) {\n const statistics = _initStatistics(),\n validationResult = {\n valid: true,\n statistics,\n errors: []\n };\n let validationMap;\n try {\n // Create mapping between JSON-schemas and examples\n validationMap = impl.buildValidationMap(pathsExamples);\n } catch (error) {\n // Throw unexpected errors\n if (!(error instanceof ApplicationError)) {\n throw error;\n }\n // Add known errors and stop\n validationResult.valid = false;\n validationResult.errors.push(error);\n return validationResult;\n }\n // Start validation\n const schemaPointers = Object.keys(validationMap);\n schemaPointers.forEach(schemaPointer => {\n _validateSchema({\n openapiSpec, createValidator, schemaPointer, validationMap, statistics,\n validationResult\n });\n });\n return validationResult;\n}\n\n/**\n * Validates a single schema.\n * @param {Object} openapiSpec OpenAPI-spec\n * @param {ajv} createValidator Factory, to create JSON-schema validator\n * @param {string} schemaPointer JSON-pointer to schema (for request- or response-property)\n * @param {Object.} validationMap Map with schema-pointers as key and example-pointers as value\n * @param {Object} statistics Object to contain statistics metrics\n * @param {Object} validationResult Container, for the validation-results\n * @private\n */\nfunction _validateSchema({\n openapiSpec, createValidator, schemaPointer, validationMap, statistics,\n validationResult\n}) {\n const errors = validationResult.errors;\n validationMap[schemaPointer].forEach(pathExample => {\n const example = _getByPointer(pathExample, openapiSpec),\n // Examples with missing schemas may occur and those are considered valid\n schema = _extractSchema(schemaPointer, openapiSpec, true);\n const curErrors = _validateExample({\n createValidator,\n schema,\n example,\n statistics\n }).map(error => {\n error.examplePath = pathExample;\n return error;\n });\n if (!curErrors.length) {\n return;\n }\n validationResult.valid = false;\n errors.splice(errors.length - 1, 0, ...curErrors);\n });\n}\n\n/**\n * Creates a container-object for the validation statistics.\n * @returns {ValidationStatistics}\n * @private\n */\nfunction _initStatistics() {\n const statistics = {\n [SYM__INTERNAL]: {\n [PROP__SCHEMAS_WITH_EXAMPLES]: new Set()\n },\n examplesTotal: 0,\n examplesWithoutSchema: 0\n };\n Object.defineProperty(statistics, PROP__SCHEMAS_WITH_EXAMPLES, {\n enumerable: true,\n get: () => statistics[SYM__INTERNAL][PROP__SCHEMAS_WITH_EXAMPLES].size\n });\n return statistics;\n}\n\n/**\n * Extract object by the given JSON-pointer\n * @param {String} pointer JSON-pointer\n * @param {Object} json JSON to extract the object(s) from\n * @returns {Object} Extracted object\n */\nfunction _getByPointer(pointer, json) {\n try {\n return jsonPointer.get(json, pointer);\n } catch (_) {\n return undefined;\n }\n}\n\n/**\n * Validates example against the schema. The precondition for this function to work is that the example exists at the\n * given path.\n * `pathExample` and `filePathExample` are exclusively mandatory.\n * itself\n * @param {Function} createValidator Factory, to create JSON-schema validator\n * @param {Object} schema JSON-schema\n * @param {Object} example Example to validate\n * @param {Object} statistics Object to contain statistics metrics\n * @param {String} [filePathExample] File-path to the example file\n * @returns {Array.} Array with errors. Empty array, if examples are valid\n * @private\n */\nfunction _validateExample({ createValidator, schema, example, statistics, filePathExample }) {\n const\n errors = [];\n statistics.examplesTotal++;\n // No schema, no validation (Examples without schema are considered valid)\n if (!schema) {\n statistics.examplesWithoutSchema++;\n return errors;\n }\n statistics[SYM__INTERNAL][PROP__SCHEMAS_WITH_EXAMPLES].add(schema);\n const validate = compileValidate(createValidator(), schema);\n if (validate(example)) {\n return errors;\n }\n return errors.concat(...validate.errors.map(ApplicationError.create))\n .map(error => {\n if (!filePathExample) {\n return error;\n }\n error.exampleFilePath = filePathExample;\n return error;\n });\n}\n\n/**\n * Create a new instance of a JSON schema validator\n * @returns {ajv}\n * @private\n */\nfunction _initValidatorFactory(specSchema, { ignoreFormats }) {\n return getValidatorFactory(specSchema, {\n schemaId: 'auto',\n discriminator: true,\n strict: false,\n allErrors: true,\n formats: ignoreFormats && ignoreFormats.reduce((result, entry) => {\n result[entry] = () => true;\n return result;\n }, {})\n });\n}\n\n/**\n * Extracts the schema in the OpenAPI-spec at the given JSON-pointer.\n * @param {string} schemaPointer JSON-pointer to the schema\n * @param {Object} openapiSpec OpenAPI-spec\n * @param {boolean} [suppressErrorIfNotFound=false] Don't throw `ErrorJsonPathNotFound` if the response does not\n * exist at the given JSON-pointer\n * @returns {Object|Array.|undefined} Matching schema(s)\n * @throws {ErrorJsonPathNotFound} Thrown, when there is no schema at the given path and\n * `suppressErrorIfNotFound` is false\n * @private\n */\nfunction _extractSchema(schemaPointer, openapiSpec, suppressErrorIfNotFound = false) {\n const schema = _getByPointer(schemaPointer, openapiSpec);\n if (!suppressErrorIfNotFound && !schema) {\n _pathToSchemaNotFoundError(schemaPointer);\n }\n return schema;\n}\n\nfunction _pathToSchemaNotFoundError(schemaPointer) {\n throw new ErrorJsonPathNotFound(`Path to schema can't be found: '${schemaPointer}'`, {\n params: {\n path: schemaPointer\n }\n });\n}\n","const path = require('path'),\n refParser = require('json-schema-ref-parser');\n\nmodule.exports = {\n createValidationResponse,\n dereferenceJsonSchema\n};\n\n/**\n * Creates a unified response for the validation-result\n * @param {Array.} errors\n * @param {ValidationStatistics} statistics\n * @returns {ValidationResponse}\n * @private\n */\nfunction createValidationResponse({ errors, statistics = {} }) {\n return {\n valid: !errors.length,\n statistics,\n errors\n };\n}\n\n/**\n * Includes all referenced, external schemas (by the keyword `$ref`) into the schema\n *\n * CAUTION: This function is not concurrency-safe !!\n * This function changes the working dir and sets it back. This may become an concurrency issue when there are\n * other tasks running that rely on the working dir while this function waits for the asynchronous task of\n * dereferencing to complete.\n *\n * @param {String} pathToSchema File-path to the schema\n * @param {Object} jsonSchema Schema with potential externally referenced schemas\n * @returns {Promise} Dereferenced schema\n */\nasync function dereferenceJsonSchema(pathToSchema, jsonSchema) {\n const currentWorkingDir = process.cwd();\n // Change the working dir to the schema-path, to make sure that relative paths can be resolved\n process.chdir(path.dirname(pathToSchema));\n const dereferencedSchema = await refParser.dereference(jsonSchema);\n // Restore original working dir\n process.chdir(currentWorkingDir);\n return dereferencedSchema;\n}\n","/**\n * Wrapper for the JSONSchema-validator\n */\n\nconst { JSONPath: jsonPath } = require('jsonpath-plus'),\n JsonPointer = require('json-pointer'),\n Ajv = require('ajv-draft-04'),\n addFormats = require('ajv-formats');\n\nconst PROP__ID = '$id',\n JSON_PATH__REFS = '$..\\$ref',\n ID__SPEC_SCHEMA = 'https://www.npmjs.com/package/openapi-examples-validator/defs.json',\n ID__RESPONSE_SCHEMA = 'https://www.npmjs.com/package/openapi-examples-validator/schema.json';\n\nmodule.exports = {\n getValidatorFactory,\n compileValidate\n};\n\n/**\n * Get a factory-function to create a prepared validator-instance\n * @param {Object} specSchema OpenAPI-spec of which potential local references will be extracted\n * @param {Object} [options] Options for the validator\n * @returns {function(): (ajv | ajv.Ajv)}\n */\nfunction getValidatorFactory(specSchema, options, { provider = (opt) => new Ajv(opt) }) {\n const preparedSpecSchema = _createReferenceSchema(specSchema);\n return () => {\n const validator = provider(options);\n addFormats(validator);\n\n validator.addSchema(preparedSpecSchema);\n\n return validator;\n };\n}\n\n/**\n * Compiles the validator-function.\n * @param {ajv | ajv.Ajv} validator Validator-instance\n * @param {Object} responseSchema The response-schema, against the examples will be validated\n * @returns {ajv.ValidateFunction}\n */\nfunction compileValidate(validator, responseSchema) {\n const preparedResponseSchema = _prepareResponseSchema(responseSchema, ID__RESPONSE_SCHEMA);\n _replaceRefsToPreparedSpecSchema(preparedResponseSchema);\n\n let result;\n try {\n result = validator.compile(preparedResponseSchema);\n } catch (e) {\n result = () => {};\n result.errors = [e];\n }\n return result;\n}\n\n/**\n * Prepares the schema, to be used with internal-references\n * @param {Object} specSchema The schema to be prebared\n * @param {String} idSchema The unique ID for the schema\n * @returns {Object}\n * @private\n */\nfunction _prepareResponseSchema(specSchema, idSchema) {\n const preparedSchema = Object.assign({}, specSchema);\n preparedSchema[PROP__ID] = idSchema;\n return preparedSchema;\n}\n\n/**\n * Replaces all internal references to the schema, with the extracted references, based on the origin OpenAPI-spec\n * @param {Object} schema The schema, containing references have to be replaced\n * @private\n */\nfunction _replaceRefsToPreparedSpecSchema(schema) {\n jsonPath({\n path: JSON_PATH__REFS,\n json: schema,\n callback(value, type, payload) {\n if (!value.startsWith('#')) { return; }\n payload.parent[payload.parentProperty] = `${ ID__SPEC_SCHEMA }${ value }`;\n }\n });\n}\n\n/**\n * Extracts all references and returns a new schema, containing only those.\n * @param {Object} specSchema Schema, which references shall be extracted\n * @returns {Object}\n * @private\n */\nfunction _createReferenceSchema(specSchema) {\n const refSchema = {\n [PROP__ID]: ID__SPEC_SCHEMA\n };\n jsonPath({\n path: JSON_PATH__REFS,\n json: specSchema,\n callback(value) {\n if (!value.startsWith('#')) { return; }\n const pointer = value.substring(1),\n definition = JsonPointer.get(specSchema, pointer);\n JsonPointer.set(refSchema, pointer, definition);\n }\n });\n return refSchema;\n}\n","module.exports = {\"name\":\"openapi-examples-validator\",\"version\":\"5.0.0\",\"description\":\"Validates embedded examples in OpenAPI-JSONs\",\"main\":\"dist/index.js\",\"engines\":{\"node\":\">=16\"},\"bin\":{\"openapi-examples-validator\":\"dist/cli.js\"},\"standard-version\":{\"scripts\":{\"postchangelog\":\"npm run release:create-dockerfile && npm run release:stage-artifacts\"}},\"scripts\":{\"start-dev\":\"babel-node src/cli\",\"build\":\"npm run build:clean && npm run build:webpack\",\"build:clean\":\"rimraf dist\",\"build:webpack\":\"webpack --bail --progress --profile --mode production --config ./webpack/config.babel.js\",\"coverage\":\"rimraf ./coverage && nyc --reporter=lcov --reporter=text -x \\\"dist/**/*\\\" -x \\\"test/**/*.js\\\" npm test\",\"coveralls\":\"cat ./coverage/lcov.info | coveralls\",\"test\":\"npm run build && npm run test:mocha\",\"test-mutations\":\"stryker run\",\"test:mocha\":\"mocha --require \\\"./test/util/setup-tests\\\" --recursive \\\"./test/specs/**/*.js\\\"\",\"release\":\"npm run build && standard-version -a\",\"release:create-dockerfile\":\"npm run build && node etc/src/build-dockerfile.js\",\"release:stage-artifacts\":\"git add dist/*\"},\"repository\":{\"type\":\"git\",\"url\":\"git+https://github.com/codekie/openapi-examples-validator.git\"},\"keywords\":[\"swagger\",\"openapi\",\"json\",\"validate\",\"examples\"],\"author\":\"Josua Amann\",\"license\":\"MIT\",\"bugs\":{\"url\":\"https://github.com/codekie/openapi-examples-validator/issues\"},\"homepage\":\"https://github.com/codekie/openapi-examples-validator#readme\",\"devDependencies\":{\"@babel/cli\":\"^7.21.5\",\"@babel/core\":\"^7.21.8\",\"@babel/eslint-parser\":\"^7.21.8\",\"@babel/node\":\"^7.20.7\",\"@babel/preset-env\":\"^7.21.5\",\"@babel/register\":\"^7.21.0\",\"@stryker-mutator/core\":\"^6.4.2\",\"@stryker-mutator/mocha-runner\":\"^6.4.2\",\"babel-loader\":\"^9.1.2\",\"chai\":\"^4.3.6\",\"chai-string\":\"^1.5.0\",\"core-js-pure\":\"^3.30.2\",\"coveralls\":\"^3.1.1\",\"eslint\":\"^8.41.0\",\"eslint-webpack-plugin\":\"^4.0.1\",\"json-loader\":\"^0.5.7\",\"mocha\":\"^10.2.0\",\"mocha-lcov-reporter\":\"^1.3.0\",\"nyc\":\"^15.1.0\",\"rimraf\":\"^5.0.1\",\"standard-version\":\"^9.5.0\",\"stryker-cli\":\"^1.0.2\",\"webpack\":\"^5.83.1\",\"webpack-cli\":\"^5.1.1\"},\"dependencies\":{\"ajv\":\"^8.12.0\",\"ajv-draft-04\":\"^1.0.0\",\"ajv-formats\":\"^2.1.1\",\"commander\":\"^6.2.1\",\"errno\":\"^1.0.0\",\"glob\":\"^8.1.0\",\"json-pointer\":\"^0.6.2\",\"json-schema-ref-parser\":\"^9.0.9\",\"jsonpath-plus\":\"^7.2.0\",\"lodash.clonedeep\":\"^4.5.0\",\"lodash.flatmap\":\"^4.5.0\",\"lodash.flatten\":\"^4.4.0\",\"lodash.merge\":\"^4.6.2\",\"yaml\":\"^2.2.2\"}}","module.exports = require(\"ajv-draft-04\");","module.exports = require(\"ajv-formats\");","module.exports = require(\"commander\");","module.exports = require(\"errno\");","module.exports = require(\"glob\");","module.exports = require(\"json-pointer\");","module.exports = require(\"json-schema-ref-parser\");","module.exports = require(\"jsonpath-plus\");","module.exports = require(\"lodash.clonedeep\");","module.exports = require(\"lodash.flatmap\");","module.exports = require(\"lodash.flatten\");","module.exports = require(\"lodash.merge\");","module.exports = require(\"yaml\");","module.exports = require(\"fs\");","module.exports = require(\"path\");","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","// startup\n// Load entry module and return exports\n// This entry module is referenced by other modules so it can't be inlined\nvar __webpack_exports__ = __webpack_require__(339);\n"],"names":["merge","require","ENOENT","ErrorType","jsENOENT","code","jsonPathNotFound","errorAndErrorsMutuallyExclusive","parseError","validation","ApplicationError","static","err","message","path","cause","type","options","params","constructor","Object","assign","this","module","exports","VERSION","program","validateFile","validateExample","validateExamplesByMap","ENV_TEST","process","env","OPENAPI_EXAMPLES_VALIDATOR_TESTS","version","arguments","description","option","action","async","filepath","schemaJsonpath","exampleFilepath","mappingFilepath","cwdToMappingFile","allPropertiesRequired","noAdditionalProperties","additionalProperties","ignoreFormats","Array","isArray","length","indexOf","split","filter","entry","match","_prepareIgnoreFormats","result","console","log","noExit","statistics","schemasWithExamples","examplesWithoutSchema","examplesTotal","matchingFilePathsMapping","strStatistics","push","stdout","write","join","_printStatistics","valid","exit","stderr","JSON","stringify","errors","_handleResult","on","parseAsync","argv","parent","parentProperty","pointer","value","implV2","implV3","REGEX__OPEN_API","getImplementation","openapiSpec","swagger","openapi","applyCallbackToAllObjectModels","setAllPropertiesRequired","openApiSpec","examplePaths","hasOwnProperty","required","keys","properties","JSONPath","jsonPath","ResultType","_find","json","resultType","callback","flatten","matchCallbackBuilder","paths","Set","forEach","consecutiveMatch","_isPropertiesDefinition","add","examplePath","exampleMatch","jsPath","startsWith","delete","_excludeExamples","data","entity","setNoAdditionalProperties","hasJsonCombinerParentRegex","RegExp","JSON_SCHEMA_COMBINERS","schema","test","warn","some","combiner","cloneDeep","getJsonPathsToExamples","buildValidationMap","pathsExamples","reduce","validationMap","pathExample","pathSchema","examplePointer","pathSegs","idxExamples","lastIndexOf","splice","_getSchemaPointerOfExample","prepare","openapiSpecCopy","RESPONSES","REQUEST","SINGLE_EXAMPLE","MANY_EXAMPLES","PATH__EXAMPLE","PATH__EXAMPLES","PATH__EXAMPLE__REQUEST_BODY","PATH__EXAMPLES__REQUEST_BODY","ExampleType","exampleTypesOfSchemas","Map","pathSchemaAsArray","exampleType","idxExample","exampleTypeOfSchema","get","pathContextAsArray","slice","create","pathContext","_throwMutuallyExclusiveError","set","flatMap","jsonPointer","fs","glob","yaml","refParser","createError","getValidatorFactory","compileValidate","Determiner","createValidationResponse","dereferenceJsonSchema","SYM__INTERNAL","Symbol","PROP__SCHEMAS_WITH_EXAMPLES","FILE_EXTENSIONS__YAML","ErrorJsonPathNotFound","validateExamples","specPostprocessor","spec","validatorFactory","_initValidatorFactory","impl","dereference","res","pathToExamples","concat","_pathToPointer","map","escapeExampleName","createValidator","_initStatistics","validationResult","error","schemaPointer","example","_getByPointer","_extractSchema","curErrors","_validateExample","_validateSchema","_validateExamplesPaths","_parseSpec","filePath","isYaml","extension","pop","includes","_isFileTypeYaml","jsonSchema","parse","readFileSync","e","name","_validate","validationHandler","_handleExamplesByMapValidation","mapExternalExamples","dirPathMapExternalExamples","entries","filePathsExample","_getSchmaPointer","filePathExample","examples","resolvedFilePathExample","globResolvedFilePathExample","sync","normalize","content","schemaPointers","_pathToSchemaNotFoundError","defineProperty","enumerable","size","_","validate","exampleFilePath","specSchema","schemaId","discriminator","strict","allErrors","formats","suppressErrorIfNotFound","filePathSchema","globMapExternalExamples","filePathsMaps","nonull","responses","filePathMapExternalExamples","dirname","mapFilePath","response","response2","response1","key","val","schemasWithExample","values","pathToSchema","currentWorkingDir","cwd","chdir","dereferencedSchema","JsonPointer","Ajv","addFormats","JSON_PATH__REFS","ID__SPEC_SCHEMA","provider","opt","preparedSpecSchema","refSchema","substring","definition","_createReferenceSchema","validator","addSchema","responseSchema","preparedResponseSchema","idSchema","preparedSchema","_prepareResponseSchema","payload","compile","__webpack_module_cache__","__webpack_exports__","__webpack_require__","moduleId","cachedModule","undefined","__webpack_modules__"],"sourceRoot":""} \ No newline at end of file diff --git a/dist/index.js b/dist/index.js index eebb65b..eb7ef0f 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1,2 +1,2 @@ -(()=>{var e={831:(e,t,r)=>{const a=r(981),{ENOENT:o}=r(373).code,s={jsENOENT:o.code,jsonPathNotFound:"JsonPathNotFound",errorAndErrorsMutuallyExclusive:"ErrorErrorsMutuallyExclusive",parseError:"ParseError",validation:"Validation"};class n{static create(e){const{code:t,message:r,path:o,cause:i}=e,p=t||e.type||s.validation,c={message:r};return s.validation===p||s.errorAndErrorsMutuallyExclusive===p?a(c,e):(o&&a(c,{params:{path:o}}),i&&a(c,i)),new n(p,c)}constructor(e,t={}){Object.assign(this,{type:e,...t})}}e.exports={ApplicationError:n,ErrorType:s}},457:e=>{e.exports={parent:"parent",parentProperty:"parentProperty",path:"path",pointer:"pointer",value:"value"}},884:(e,t,r)=>{const a=r(442),o=r(955),s=/^3\./;e.exports={getImplementation:function(e){return"string"==typeof e.swagger?a:e.openapi&&e.openapi.match(s)?o:null}}},305:(e,t,r)=>{const{applyCallbackToAllObjectModels:a}=r(818);e.exports={setAllPropertiesRequired:function(e,t=[]){a(e,t,(()=>e=>{e.hasOwnProperty("properties")&&(e.required=Object.keys(e.properties))}))}}},818:(e,t,r)=>{const{JSONPath:a}=r(166),o=r(457);function s(e,t,r=o.path,s){return a({json:e,path:t,flatten:!0,resultType:r,callback:s})}e.exports={applyCallbackToAllObjectModels:function(e,t,r){const a=new Set;s(e,"$..schema..").forEach((e=>{(function(e){if(!e.match(/\['properties']$/))return;const t=e.match(/(?{s(e,r).forEach((e=>{for(const r of t)r.startsWith(e)&&t.delete(r)}))}))}(e,a,t);for(const t of a){const a=r(t);s(e,t,o.value,((e,t,r)=>{var o;("object"===(o=e).type||o.properties)&&a(e,t,r)}))}}}},257:(e,t,r)=>{const{applyCallbackToAllObjectModels:a}=r(818);e.exports={setNoAdditionalProperties:function(e,t=[]){const r=new RegExp("(?t=>{r.test(e)?console.warn(`"additionalProperties" flag not set for ${e} because it has a parent with a JSON-schema combiner keyword.`):o.some((e=>t.hasOwnProperty(e)))?console.warn(`"additionalProperties" flag not set for ${e} because it contains JSON-schema combiner keyword.`):t.hasOwnProperty("additionalProperties")||(t.additionalProperties=!1)}))}};const o=["oneOf","allOf","anyOf","not"]},442:(e,t,r)=>{const{JSONPath:a}=r(166),o=r(548),{setAllPropertiesRequired:s}=r(305),{setNoAdditionalProperties:n}=r(257);function i(){return["$..examples.application/json"]}e.exports={buildValidationMap:function(e){return e.reduce(((e,t)=>{const r=function(e){const t=a.toPathArray(e).slice(),r=t.lastIndexOf("examples");return t.splice(r,t.length-r,"schema"),a.toPathString(t)}(t);return e[r]=(e[r]||new Set).add(t),e}),{})},escapeExampleName:function(e){return e},getJsonPathsToExamples:i,prepare:function(e,{noAdditionalProperties:t,allPropertiesRequired:r}={}){const a=o(e);return t&&n(a,["$..examples.application/json"]),r&&s(a,["$..examples.application/json"]),a},unescapeExampleNames:function(e){return e}}},955:(e,t,r)=>{const{JSONPath:a}=r(166),o=r(548),{ApplicationError:s,ErrorType:n}=r(831),{setAllPropertiesRequired:i}=r(305),{setNoAdditionalProperties:p}=r(257),c="single",l="multi";function u(){return["$..responses..content.application/json.example","$..responses..content.application/json.examples.*.value","$..parameters..example","$..parameters..examples.*.value","$..requestBody.content.application/json.example","$..requestBody.content.application/json.examples.*.value"]}e.exports={buildValidationMap:function(e){const t=new Map;return e.reduce(((e,r)=>{const{pathSchemaAsArray:o,exampleType:i}=function(e){const t=a.toPathArray(e).slice(),r=t.lastIndexOf("example"),o=r>-1?c:l,s=o===c?r:t.lastIndexOf("examples");return t.splice(s,t.length-s,"schema"),{exampleType:o,pathSchemaAsArray:t}}(r),p=a.toPathString(o),u=t.get(p);return u&&u!==i&&function(e){const t=e.slice(0,e.length-1);throw s.create({type:n.errorAndErrorsMutuallyExclusive,message:'Properties "error" and "errors" are mutually exclusive',params:{pathContext:a.toPointer(t)}})}(o),t.set(p,i),e[p]=(e[p]||new Set).add(r),e}),{})},escapeExampleName:function(e){return e.replace(/\['examples'\]\['(.*)\]\['value'\]$/,"['examples']['`$1]['value']")},getJsonPathsToExamples:u,prepare:function(e,{noAdditionalProperties:t,allPropertiesRequired:r}={}){const a=o(e);return t&&p(a,["$..responses..content.application/json.example","$..responses..content.application/json.examples.*.value","$..parameters..example","$..parameters..examples.*.value","$..requestBody.content.application/json.example","$..requestBody.content.application/json.examples.*.value"]),r&&i(a,["$..responses..content.application/json.example","$..responses..content.application/json.examples.*.value","$..parameters..example","$..parameters..examples.*.value","$..requestBody.content.application/json.example","$..requestBody.content.application/json.examples.*.value"]),a},unescapeExampleNames:function(e){return e&&e.replace(/\/examples\/`(.*)\/value$/,"/examples/$1/value")}}},579:(e,t,r)=>{const a=r(981),o=r(760),s=r(574),n=r(147),i=r(17),p=r(230),c=r(66),{JSONPath:l}=r(166),u=r(432),{createError:m}=r(373).custom,d=r(457),{getValidatorFactory:h,compileValidate:f}=r(239),x=r(884),{ApplicationError:y,ErrorType:P}=r(831),{createValidationResponse:g,dereferenceJsonSchema:E}=r(903),j=Symbol("internal"),v="schemasWithExamples",w=["yaml","yml"],$=m(P.jsonPathNotFound);async function q(e,{noAdditionalProperties:t,ignoreFormats:r,allPropertiesRequired:a}={}){const o=x.getImplementation(e);e=await u.dereference(e),e=o.prepare(e,{noAdditionalProperties:t,allPropertiesRequired:a});let s=o.getJsonPathsToExamples().reduce(((t,r)=>t.concat(function(e,t){return l({json:e,path:t,resultType:d.path})}(e,r))),[]).map(o.escapeExampleName);return function({impl:e},t,r,{ignoreFormats:a}){const o=b(),s={valid:!0,statistics:o,errors:[]},n=T(r,{ignoreFormats:a});let i;try{i=e.buildValidationMap(t)}catch(e){if(!(e instanceof y))throw e;return s.valid=!1,s.errors.push(e),s}return Object.keys(i).forEach((e=>{!function({openapiSpec:e,createValidator:t,pathSchema:r,validationMap:a,statistics:o,validationResult:s}){const n=s.errors;a[r].forEach((a=>{const i=F(a,e),p=M(r,e,!0),c=N({createValidator:t,schema:p,example:i,statistics:o}).map((e=>(e.examplePath=l.toPointer(l.toPathArray(a)),e)));c.length&&(s.valid=!1,n.splice(n.length-1,0,...c))}))}({openapiSpec:r,createValidator:n,pathSchema:e,validationMap:i,statistics:o,validationResult:s})})),s.errors.forEach((t=>{t.examplePath=e.unescapeExampleNames(t.examplePath)})),s}({impl:o},s,e,{ignoreFormats:r})}async function O(e){const t=function(e){const t=e.split(".").pop();return w.includes(t)}(e);let r;if(t)try{r=c.parse(n.readFileSync(e,"utf-8"))}catch(e){const{name:t,message:r}=e;throw new y(P.parseError,{message:`${t}: ${r}`})}else r=JSON.parse(n.readFileSync(e,"utf-8"));return await E(e,r)}function S(e){const t=b(),r=e(t);return g({errors:r,statistics:t})}function A(e,t,r,{cwdToMappingFile:a=!1,dirPathMapExternalExamples:c,ignoreFormats:l}){return s(Object.entries(t),(([t,u])=>{let m=null;try{m=M(t,e)}catch(e){return y.create(e)}return s(o([u]),(t=>{let o=[];try{const e=a?i.join(c,t):t,r=p.sync(e);if(0===r.length)return[y.create({type:P.jsENOENT,message:`No such file or directory: '${e}'`,path:e})];for(const e of r)o.push({path:i.normalize(e),content:JSON.parse(n.readFileSync(e,"utf-8"))})}catch(e){return[y.create(e)]}return s(o,(t=>N({createValidator:T(e,{ignoreFormats:l}),schema:m,example:t.content,statistics:r,filePathExample:t.path})))}))}))}function b(){const e={[j]:{[v]:new Set},examplesTotal:0,examplesWithoutSchema:0};return Object.defineProperty(e,v,{enumerable:!0,get:()=>e[j][v].size}),e}function F(e,t){return l({json:t,path:e,flatten:!0,wrap:!1,resultType:d.value})}function N({createValidator:e,schema:t,example:r,statistics:a,filePathExample:o}){const s=[];if(a.examplesTotal++,!t)return a.examplesWithoutSchema++,s;a[j][v].add(t);const n=f(e(),t);return n(r)?s:s.concat(...n.errors.map(y.create)).map((e=>o?(e.exampleFilePath=o,e):e))}function T(e,{ignoreFormats:t}){return h(e,{schemaId:"auto",discriminator:!0,strict:!1,allErrors:!0,formats:t&&t.reduce(((e,t)=>(e[t]=()=>!0,e)),{})})}function M(e,t,r=!1){const a=F(e,t);if(!r&&!a)throw new $(`Path to schema can't be found: '${e}'`,{params:{path:e}});return a}e.exports={default:q,validateFile:async function(e,{noAdditionalProperties:t,ignoreFormats:r,allPropertiesRequired:a}={}){let o=null;try{o=await O(e)}catch(e){return g({errors:[y.create(e)]})}return q(o,{noAdditionalProperties:t,ignoreFormats:r,allPropertiesRequired:a})},validateExample:async function(e,t,r,{noAdditionalProperties:a,ignoreFormats:o,allPropertiesRequired:s}={}){let i=null,p=null,c=null;try{i=JSON.parse(n.readFileSync(r,"utf-8")),c=await O(e),c=x.getImplementation(c).prepare(c,{noAdditionalProperties:a,allPropertiesRequired:s}),p=M(t,c)}catch(e){return g({errors:[y.create(e)]})}return S((e=>N({createValidator:T(c,{ignoreFormats:o}),schema:p,example:i,statistics:e,filePathExample:r})))},validateExamplesByMap:async function(e,t,{cwdToMappingFile:r,noAdditionalProperties:o,ignoreFormats:s,allPropertiesRequired:c}={}){let l=0;const u=p.sync(t,{nonull:!0});let m=[];for(const t of u){let a=null,p=null;try{a=JSON.parse(n.readFileSync(t,"utf-8")),p=await O(e),p=x.getImplementation(p).prepare(p,{noAdditionalProperties:o,allPropertiesRequired:c})}catch(e){m.push(g({errors:[y.create(e)]}));continue}l++,m.push(S((e=>A(p,a,e,{cwdToMappingFile:r,dirPathMapExternalExamples:i.dirname(t),ignoreFormats:s}).map((e=>Object.assign(e,{mapFilePath:i.normalize(t)}))))))}return a(m.reduce(((e,t)=>{return e?(a=t,g({errors:(r=e).errors.concat(a.errors),statistics:Object.entries(r.statistics).reduce(((e,[t,o])=>v===t?([r,a].forEach((t=>{const r=t.statistics[j][v].values();for(let t of r)e[j][v].add(t)})),e):(e[t]=o+a.statistics[t],e)),b())})):t;var r,a}),null),{statistics:{matchingFilePathsMapping:l}})}}},903:(e,t,r)=>{const a=r(17),o=r(432);e.exports={createValidationResponse:function({errors:e,statistics:t={}}){return{valid:!e.length,statistics:t,errors:e}},dereferenceJsonSchema:async function(e,t){const r=process.cwd();process.chdir(a.dirname(e));const s=await o.dereference(t);return process.chdir(r),s}}},239:(e,t,r)=>{const{JSONPath:a}=r(166),o=r(125),s=r(643),n=r(638),i="$..$ref",p="https://www.npmjs.com/package/openapi-examples-validator/defs.json";e.exports={getValidatorFactory:function(e,t){const r=function(e){const t={$id:p};return a({path:i,json:e,callback(r){if(!r.startsWith("#"))return;const a=r.substring(1),s=o.get(e,a);o.set(t,a,s)}}),t}(e);return()=>{const e=new s(t);return n(e),e.addSchema(r),e}},compileValidate:function(e,t){const r=function(e,t){const r=Object.assign({},e);return r.$id="https://www.npmjs.com/package/openapi-examples-validator/schema.json",r}(t);let o;a({path:i,json:r,callback(e,t,r){e.startsWith("#")&&(r.parent[r.parentProperty]=`${p}${e}`)}});try{o=e.compile(r)}catch(e){o=()=>{},o.errors=[e]}return o}}},643:e=>{"use strict";e.exports=require("ajv-draft-04")},638:e=>{"use strict";e.exports=require("ajv-formats")},373:e=>{"use strict";e.exports=require("errno")},230:e=>{"use strict";e.exports=require("glob")},125:e=>{"use strict";e.exports=require("json-pointer")},432:e=>{"use strict";e.exports=require("json-schema-ref-parser")},166:e=>{"use strict";e.exports=require("jsonpath-plus")},548:e=>{"use strict";e.exports=require("lodash.clonedeep")},574:e=>{"use strict";e.exports=require("lodash.flatmap")},760:e=>{"use strict";e.exports=require("lodash.flatten")},981:e=>{"use strict";e.exports=require("lodash.merge")},66:e=>{"use strict";e.exports=require("yaml")},147:e=>{"use strict";e.exports=require("fs")},17:e=>{"use strict";e.exports=require("path")}},t={},r=function r(a){var o=t[a];if(void 0!==o)return o.exports;var s=t[a]={exports:{}};return e[a](s,s.exports,r),s.exports}(579);module.exports=r})(); +(()=>{var e={831:(e,t,r)=>{const a=r(981),{ENOENT:o}=r(373).code,s={jsENOENT:o.code,jsonPathNotFound:"JsonPathNotFound",errorAndErrorsMutuallyExclusive:"ErrorErrorsMutuallyExclusive",parseError:"ParseError",validation:"Validation"};class n{static create(e){const{code:t,message:r,path:o,cause:i}=e,c=t||e.type||s.validation,p={message:r};return s.validation===c||s.errorAndErrorsMutuallyExclusive===c?a(p,e):(o&&a(p,{params:{path:o}}),i&&a(p,i)),new n(c,p)}constructor(e,t={}){Object.assign(this,{type:e,...t})}}e.exports={ApplicationError:n,ErrorType:s}},457:e=>{e.exports={parent:"parent",parentProperty:"parentProperty",path:"path",pointer:"pointer",value:"value"}},884:(e,t,r)=>{const a=r(442),o=r(955),s=/^3\./;e.exports={getImplementation:function(e){return"string"==typeof e.swagger?a:e.openapi&&e.openapi.match(s)?o:null}}},305:(e,t,r)=>{const{applyCallbackToAllObjectModels:a}=r(818);e.exports={setAllPropertiesRequired:function(e,t=[]){a(e,t,(()=>e=>{e.hasOwnProperty("properties")&&(e.required=Object.keys(e.properties))}))}}},818:(e,t,r)=>{const{JSONPath:a}=r(166),o=r(457);function s(e,t,r=o.path,s){return a({json:e,path:t,flatten:!0,resultType:r,callback:s})}e.exports={applyCallbackToAllObjectModels:function(e,t,r){const a=new Set;s(e,"$..schema..").forEach((e=>{(function(e){if(!e.match(/\['properties']$/))return;const t=e.match(/(?{s(e,r).forEach((e=>{for(const r of t)r.startsWith(e)&&t.delete(r)}))}))}(e,a,t);for(const t of a){const a=r(t);s(e,t,o.value,((e,t,r)=>{var o;("object"===(o=e).type||o.properties)&&a(e,t,r)}))}}}},257:(e,t,r)=>{const{applyCallbackToAllObjectModels:a}=r(818);e.exports={setNoAdditionalProperties:function(e,t=[]){const r=new RegExp("(?t=>{r.test(e)?console.warn(`"additionalProperties" flag not set for ${e} because it has a parent with a JSON-schema combiner keyword.`):o.some((e=>t.hasOwnProperty(e)))?console.warn(`"additionalProperties" flag not set for ${e} because it contains JSON-schema combiner keyword.`):t.hasOwnProperty("additionalProperties")||(t.additionalProperties=!1)}))}};const o=["oneOf","allOf","anyOf","not"]},442:(e,t,r)=>{const a=r(548),{setAllPropertiesRequired:o}=r(305),{setNoAdditionalProperties:s}=r(257);function n(){return["$..examples[?(@property.match(/[/+]json/))]"]}e.exports={buildValidationMap:function(e){return e.reduce(((e,t)=>{const r=function(e){const t=e.split("/"),r=t.lastIndexOf("examples");return t.splice(r,t.length-r,"schema"),t.join("/")}(t);return e[r]=(e[r]||new Set).add(t),e}),{})},getJsonPathsToExamples:n,prepare:function(e,{noAdditionalProperties:t,allPropertiesRequired:r}={}){const n=a(e);return t&&s(n,["$..examples[?(@property.match(/[/+]json/))]"]),r&&o(n,["$..examples[?(@property.match(/[/+]json/))]"]),n}}},955:(e,t,r)=>{const a=r(548),{ApplicationError:o,ErrorType:s}=r(831),{setAllPropertiesRequired:n}=r(305),{setNoAdditionalProperties:i}=r(257),c="$..responses..content[?(@property.match(/[/+]json/))]",p="$..requestBody.content[?(@property.match(/[/+]json/))]",l=".example",u=".examples.*.value",d=`${c}${l}`,m=`${c}${u}`,h=`${p}${l}`,f=`${p}${u}`,x="single",y="multi";function g(){return[d,m,"$..parameters..example","$..parameters..examples.*.value",h,f]}e.exports={buildValidationMap:function(e){const t=new Map;return e.reduce(((e,r)=>{const{pathSchemaAsArray:a,exampleType:n}=function(e){const t=e.split("/"),r=t.lastIndexOf("example"),a=r>-1?x:y,o=a===x?r:t.lastIndexOf("examples");return t.splice(o,t.length-o,"schema"),{exampleType:a,pathSchemaAsArray:t}}(r),i=a.join("/"),c=t.get(i);return c&&c!==n&&function(e){const t=e.slice(0,e.length-1);throw o.create({type:s.errorAndErrorsMutuallyExclusive,message:'Properties "error" and "errors" are mutually exclusive',params:{pathContext:t.join("/")}})}(a),t.set(i,n),e[i]=(e[i]||new Set).add(r),e}),{})},getJsonPathsToExamples:g,prepare:function(e,{noAdditionalProperties:t,allPropertiesRequired:r}={}){const o=a(e);return t&&i(o,g()),r&&n(o,g()),o}}},579:(e,t,r)=>{const a=r(981),o=r(760),s=r(574),n=r(125),i=r(147),c=r(17),p=r(230),l=r(66),{JSONPath:u}=r(166),d=r(432),{createError:m}=r(373).custom,h=r(457),{getValidatorFactory:f,compileValidate:x}=r(239),y=r(884),{ApplicationError:g,ErrorType:P}=r(831),{createValidationResponse:E,dereferenceJsonSchema:j}=r(903),w=Symbol("internal"),v="schemasWithExamples",F=["yaml","yml"],O=m(P.jsonPathNotFound);async function $(e,{noAdditionalProperties:t,ignoreFormats:r,allPropertiesRequired:a,specPostprocessor:o=(e=>e),validatorFactory:s=((e,{ignoreFormats:t})=>R(e,{ignoreFormats:t}))}={}){const n=y.getImplementation(e);e=await d.dereference(e),e=n.prepare(e,{noAdditionalProperties:t,allPropertiesRequired:a}),"function"==typeof o&&(e=o(e));let i=n.getJsonPathsToExamples().reduce(((t,r)=>t.concat(S(e,r))),[]).map(n.escapeExampleName);return function({impl:e,createValidator:t},r,a){const o=T(),s={valid:!0,statistics:o,errors:[]};let n;try{n=e.buildValidationMap(r)}catch(e){if(!(e instanceof g))throw e;return s.valid=!1,s.errors.push(e),s}return Object.keys(n).forEach((e=>{!function({openapiSpec:e,createValidator:t,schemaPointer:r,validationMap:a,statistics:o,validationResult:s}){const n=s.errors;a[r].forEach((a=>{const i=M(a,e),c=J(r,e,!0),p=V({createValidator:t,schema:c,example:i,statistics:o}).map((e=>(e.examplePath=a,e)));p.length&&(s.valid=!1,n.splice(n.length-1,0,...p))}))}({openapiSpec:a,createValidator:t,schemaPointer:e,validationMap:n,statistics:o,validationResult:s})})),s}({impl:n,createValidator:s(e,{ignoreFormats:r})},i,e)}async function b(e){const t=function(e){const t=e.split(".").pop();return F.includes(t)}(e);let r;if(t)try{r=l.parse(i.readFileSync(e,"utf-8"))}catch(e){const{name:t,message:r}=e;throw new g(P.parseError,{message:`${t}: ${r}`})}else r=JSON.parse(i.readFileSync(e,"utf-8"));return await j(e,r)}function q(e){const t=T(),r=e(t);return E({errors:r,statistics:t})}function A(e,t,r,{cwdToMappingFile:a=!1,dirPathMapExternalExamples:n,ignoreFormats:l}){return s(Object.entries(t),(([t,u])=>{let d=null;try{d=J(N(t,e),e)}catch(e){return g.create(e)}return s(o([u]),(t=>{let o=[];try{const e=a?c.join(n,t):t,r=p.sync(e);if(0===r.length)return[g.create({type:P.jsENOENT,message:`No such file or directory: '${e}'`,path:e})];for(const e of r)o.push({path:c.normalize(e),content:JSON.parse(i.readFileSync(e,"utf-8"))})}catch(e){return[g.create(e)]}return s(o,(t=>V({createValidator:R(e,{ignoreFormats:l}),schema:d,example:t.content,statistics:r,filePathExample:t.path})))}))}))}function S(e,t){return u({json:t,path:e,resultType:h.pointer})}function N(e,t){const r=S(e,t);return 0===r.length&&k(e),r.length>1?[g.create({type:P.jsonPathNotFound,message:`Path to schema cannot identify unique schema: '${e}'`,path:e})]:r[0]}function T(){const e={[w]:{[v]:new Set},examplesTotal:0,examplesWithoutSchema:0};return Object.defineProperty(e,v,{enumerable:!0,get:()=>e[w][v].size}),e}function M(e,t){try{return n.get(t,e)}catch(e){return}}function V({createValidator:e,schema:t,example:r,statistics:a,filePathExample:o}){const s=[];if(a.examplesTotal++,!t)return a.examplesWithoutSchema++,s;a[w][v].add(t);const n=x(e(),t);return n(r)?s:s.concat(...n.errors.map(g.create)).map((e=>o?(e.exampleFilePath=o,e):e))}function R(e,{ignoreFormats:t}){return f(e,{schemaId:"auto",discriminator:!0,strict:!1,allErrors:!0,formats:t&&t.reduce(((e,t)=>(e[t]=()=>!0,e)),{})})}function J(e,t,r=!1){const a=M(e,t);return r||a||k(e),a}function k(e){throw new O(`Path to schema can't be found: '${e}'`,{params:{path:e}})}e.exports={default:$,validateFile:async function(e,{noAdditionalProperties:t,ignoreFormats:r,allPropertiesRequired:a}={}){let o=null;try{o=await b(e)}catch(e){return E({errors:[g.create(e)]})}return $(o,{noAdditionalProperties:t,ignoreFormats:r,allPropertiesRequired:a})},validateExample:async function(e,t,r,{noAdditionalProperties:a,ignoreFormats:o,allPropertiesRequired:s}={}){let n=null,c=null,p=null;try{n=JSON.parse(i.readFileSync(r,"utf-8")),p=await b(e),p=y.getImplementation(p).prepare(p,{noAdditionalProperties:a,allPropertiesRequired:s}),c=J(N(t,p),p)}catch(e){return E({errors:[g.create(e)]})}return q((e=>V({createValidator:R(p,{ignoreFormats:o}),schema:c,example:n,statistics:e,filePathExample:r})))},validateExamplesByMap:async function(e,t,{cwdToMappingFile:r,noAdditionalProperties:o,ignoreFormats:s,allPropertiesRequired:n}={}){let l=0;const u=p.sync(t,{nonull:!0});let d=[];for(const t of u){let a=null,p=null;try{a=JSON.parse(i.readFileSync(t,"utf-8")),p=await b(e),p=y.getImplementation(p).prepare(p,{noAdditionalProperties:o,allPropertiesRequired:n})}catch(e){d.push(E({errors:[g.create(e)]}));continue}l++,d.push(q((e=>A(p,a,e,{cwdToMappingFile:r,dirPathMapExternalExamples:c.dirname(t),ignoreFormats:s}).map((e=>Object.assign(e,{mapFilePath:c.normalize(t)}))))))}return a(d.reduce(((e,t)=>{return e?(a=t,E({errors:(r=e).errors.concat(a.errors),statistics:Object.entries(r.statistics).reduce(((e,[t,o])=>v===t?([r,a].forEach((t=>{const r=t.statistics[w][v].values();for(let t of r)e[w][v].add(t)})),e):(e[t]=o+a.statistics[t],e)),T())})):t;var r,a}),null),{statistics:{matchingFilePathsMapping:l}})},getValidatorFactory:f}},903:(e,t,r)=>{const a=r(17),o=r(432);e.exports={createValidationResponse:function({errors:e,statistics:t={}}){return{valid:!e.length,statistics:t,errors:e}},dereferenceJsonSchema:async function(e,t){const r=process.cwd();process.chdir(a.dirname(e));const s=await o.dereference(t);return process.chdir(r),s}}},239:(e,t,r)=>{const{JSONPath:a}=r(166),o=r(125),s=r(643),n=r(638),i="$..$ref",c="https://www.npmjs.com/package/openapi-examples-validator/defs.json";e.exports={getValidatorFactory:function(e,t,{provider:r=(e=>new s(e))}){const p=function(e){const t={$id:c};return a({path:i,json:e,callback(r){if(!r.startsWith("#"))return;const a=r.substring(1),s=o.get(e,a);o.set(t,a,s)}}),t}(e);return()=>{const e=r(t);return n(e),e.addSchema(p),e}},compileValidate:function(e,t){const r=function(e,t){const r=Object.assign({},e);return r.$id="https://www.npmjs.com/package/openapi-examples-validator/schema.json",r}(t);let o;a({path:i,json:r,callback(e,t,r){e.startsWith("#")&&(r.parent[r.parentProperty]=`${c}${e}`)}});try{o=e.compile(r)}catch(e){o=()=>{},o.errors=[e]}return o}}},643:e=>{"use strict";e.exports=require("ajv-draft-04")},638:e=>{"use strict";e.exports=require("ajv-formats")},373:e=>{"use strict";e.exports=require("errno")},230:e=>{"use strict";e.exports=require("glob")},125:e=>{"use strict";e.exports=require("json-pointer")},432:e=>{"use strict";e.exports=require("json-schema-ref-parser")},166:e=>{"use strict";e.exports=require("jsonpath-plus")},548:e=>{"use strict";e.exports=require("lodash.clonedeep")},574:e=>{"use strict";e.exports=require("lodash.flatmap")},760:e=>{"use strict";e.exports=require("lodash.flatten")},981:e=>{"use strict";e.exports=require("lodash.merge")},66:e=>{"use strict";e.exports=require("yaml")},147:e=>{"use strict";e.exports=require("fs")},17:e=>{"use strict";e.exports=require("path")}},t={},r=function r(a){var o=t[a];if(void 0!==o)return o.exports;var s=t[a]={exports:{}};return e[a](s,s.exports,r),s.exports}(579);module.exports=r})(); //# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/dist/index.js.map b/dist/index.js.map index 30fd02f..373dc3f 100644 --- a/dist/index.js.map +++ b/dist/index.js.map @@ -1 +1 @@ -{"version":3,"file":"index.js","mappings":"2BAAA,MACIA,EAAQC,EAAQ,MAChB,OAAEC,GAAWD,EAAAA,KAAAA,KA6BXE,EAAY,CACdC,SAAUF,EAAOG,KACjBC,iBAAkB,mBAClBC,gCAAiC,+BACjCC,WAAY,aACZC,WAAY,cAQhB,MAAMC,EAQFC,cAAcC,GACV,MAAM,KAAEP,EAAI,QAAEQ,EAAO,KAAEC,EAAI,MAAEC,GAAUH,EACnCI,EAAOX,GAAQO,EAAII,MAAQb,EAAUM,WACrCQ,EAAU,CAAEJ,WAShB,OARIV,EAAUM,aAAeO,GAAQb,EAAUI,kCAAoCS,EAE/EhB,EAAMiB,EAASL,IAGfE,GAAQd,EAAMiB,EAAS,CAAEC,OAAQ,CAAEJ,UACnCC,GAASf,EAAMiB,EAASF,IAErB,IAAIL,EAAiBM,EAAMC,EACtC,CAOAE,YAAYH,EAAMC,EAAU,CAAC,GACzBG,OAAOC,OAAOC,KAAM,CAChBN,UACGC,GAEX,EAKJM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AC,ECE5BC,EDCJ,SAASC,EAAoBC,GAE5B,IAAIC,EAAeJ,EAAyBG,GAC5C,QAAqBE,IAAjBD,EACH,OAAOA,EAAaxO,QAGrB,IAAID,EAASqO,EAAyBG,GAAY,CAGjDvO,QAAS,CAAC,GAOX,OAHA0O,EAAoBH,GAAUxO,EAAQA,EAAOC,QAASsO,GAG/CvO,EAAOC,OACf,CCnB0BsO,CAAoB,K","sources":["webpack://openapi-examples-validator/./src/application-error.js","webpack://openapi-examples-validator/./src/const/result-type.js","webpack://openapi-examples-validator/./src/impl/index.js","webpack://openapi-examples-validator/./src/impl/service/all-properties-required.js","webpack://openapi-examples-validator/./src/impl/service/common.js","webpack://openapi-examples-validator/./src/impl/service/no-additional-properties.js","webpack://openapi-examples-validator/./src/impl/v2/index.js","webpack://openapi-examples-validator/./src/impl/v3/index.js","webpack://openapi-examples-validator/./src/index.js","webpack://openapi-examples-validator/./src/utils/index.js","webpack://openapi-examples-validator/./src/validator.js","webpack://openapi-examples-validator/external commonjs \"ajv-draft-04\"","webpack://openapi-examples-validator/external commonjs \"ajv-formats\"","webpack://openapi-examples-validator/external commonjs \"errno\"","webpack://openapi-examples-validator/external commonjs \"glob\"","webpack://openapi-examples-validator/external commonjs \"json-pointer\"","webpack://openapi-examples-validator/external commonjs \"json-schema-ref-parser\"","webpack://openapi-examples-validator/external commonjs \"jsonpath-plus\"","webpack://openapi-examples-validator/external commonjs \"lodash.clonedeep\"","webpack://openapi-examples-validator/external commonjs \"lodash.flatmap\"","webpack://openapi-examples-validator/external commonjs \"lodash.flatten\"","webpack://openapi-examples-validator/external commonjs \"lodash.merge\"","webpack://openapi-examples-validator/external commonjs \"yaml\"","webpack://openapi-examples-validator/external node-commonjs \"fs\"","webpack://openapi-examples-validator/external node-commonjs \"path\"","webpack://openapi-examples-validator/webpack/bootstrap","webpack://openapi-examples-validator/webpack/startup"],"sourcesContent":["const\n merge = require('lodash.merge'),\n { ENOENT } = require('errno').code;\n\n// TYPEDEFINITIONS\n\n/**\n * @typedef {{}} CustomError\n * @augments Error\n */\n\n/**\n * ApplicationErrorOptions\n * @typedef {{\n * [instancePath]: string,\n * [examplePath]: string,\n * [exampleFilePath]: string,\n * [keyword]: string,\n * [message]: string,\n * [mapFilePath]: string,\n * [params]: {\n * [path]: string,\n * [missingProperty]: string,\n * [type]: string\n * },\n * [schemaPath]: string\n * }} ApplicationErrorOptions\n */\n\n// CONSTANTS\n\nconst ErrorType = {\n jsENOENT: ENOENT.code,\n jsonPathNotFound: 'JsonPathNotFound',\n errorAndErrorsMutuallyExclusive: 'ErrorErrorsMutuallyExclusive',\n parseError: 'ParseError',\n validation: 'Validation'\n};\n\n// CLASSES\n\n/**\n * Unified application-error\n */\nclass ApplicationError {\n /**\n * Factory-function, which is able to consume validation-errors and JS-errors. If a validation error is passed, all\n * properties will be adopted.\n * @param {Error|CustomError} err Javascript-, validation- or custom-error, to create the application-error\n * from\n * @returns {ApplicationError} Unified application-error instance\n */\n static create(err) {\n const { code, message, path, cause } = err, // Certain properties of Javascript-errors\n type = code || err.type || ErrorType.validation, // If `code` is available then it's a Javascript-error\n options = { message };\n if (ErrorType.validation === type || ErrorType.errorAndErrorsMutuallyExclusive === type) {\n // For certain, created error-types, copy all properties\n merge(options, err);\n } else {\n // Copy certain properties of Javascript-error (but only if available)\n path && merge(options, { params: { path } });\n cause && merge(options, cause);\n }\n return new ApplicationError(type, options);\n }\n\n /**\n * Constructor\n * @param {string} type Type of error (see statics)\n * @param {ApplicationErrorOptions} [options] Optional properties\n */\n constructor(type, options = {}) {\n Object.assign(this, {\n type,\n ...options\n });\n }\n}\n\n// PUBLIC API\n\nmodule.exports = {\n ApplicationError,\n ErrorType\n};\n","module.exports = {\n parent: 'parent',\n parentProperty: 'parentProperty',\n path: 'path',\n pointer: 'pointer',\n value: 'value'\n};\n","/**\n * Entry point for logic that only applies to specific versions of the OpenAPI-spec\n */\n\nconst implV2 = require('./v2/index'),\n implV3 = require('./v3/index');\n\nconst REGEX__OPEN_API = /^3\\./;\n\nmodule.exports = {\n getImplementation\n};\n\n/**\n * Get the version-specific implementation for the OpenAPI-spec. Currently v2 and v3 are supported\n * @param {Object} openapiSpec OpenAPI-spec\n * @returns {Object|null}\n */\nfunction getImplementation(openapiSpec) {\n if (typeof openapiSpec.swagger === 'string') {\n return implV2;\n }\n if (openapiSpec.openapi && openapiSpec.openapi.match(REGEX__OPEN_API)) {\n return implV3;\n }\n return null;\n}\n","const { applyCallbackToAllObjectModels } = require('./common');\n\nmodule.exports = {\n setAllPropertiesRequired\n};\n\n/**\n * Sets all properties of each object to required\n * @param {Object} openApiSpec The to-be-modified schema\n * @param {Array.} [examplePaths=[]] The paths to the examples, which's content must not be modified\n */\nfunction setAllPropertiesRequired(openApiSpec, examplePaths = []) {\n applyCallbackToAllObjectModels(openApiSpec, examplePaths,\n () => {\n return (value) => {\n if (value.hasOwnProperty('properties')) {\n value.required = Object.keys(value.properties);\n }\n };\n });\n}\n","const { JSONPath: jsonPath } = require('jsonpath-plus'),\n ResultType = require('../../const/result-type');\n\nmodule.exports = {\n applyCallbackToAllObjectModels\n};\n\n/**\n * @typedef {{\n * path: String,\n * value: Object,\n * parent: Object,\n * parentProperty: String,\n * hasArrExpr: Boolean\n * }} JsonPathMatchData\n */\n\n/**\n * Callback that is applied to a JSONPath-match.\n * @callback JsonPathMatchCallback\n * @param {Object} value Value of the matched property\n * @param {String} resultType Result-type of the query\n * @param {JsonPathMatchData} data Object that contains additional data to the match\n */\n\n/**\n * Function to build a callback that is applied to a JSONPath-match.\n * @callback JsonPathMatchCallbackBuilder\n * @param {string} jsPath Path to the property that matched\n * @return {JsonPathMatchCallback} Callback that is applied to a JSONPath-match\n */\n\n/**\n * Apply the input rule to all models of type object in the input openApiSpec\n * @param {Object} openApiSpec The to-be-modified schema\n * @param {Array.} [examplePaths] The paths to the examples, which's content must not be modified\n * @param {JsonPathMatchCallbackBuilder} [matchCallbackBuilder] Function to build a callback\n * that will be called on each match\n */\nfunction applyCallbackToAllObjectModels(openApiSpec, examplePaths, matchCallbackBuilder) {\n // Find all matches\n const paths = new Set();\n _find(openApiSpec, '$..schema..')\n .forEach(match => {\n if (_isPropertiesDefinition(match)) { return; }\n paths.add(match);\n });\n // Exclude examples\n _excludeExamples(openApiSpec, paths, examplePaths);\n // Set flag\n for (const jsPath of paths) {\n const callback = matchCallbackBuilder(jsPath);\n _find(openApiSpec, jsPath, ResultType.value, (result, resultType, data) => {\n if (!_isObjectDefinition(result)) { return; }\n callback(result, resultType, data);\n });\n }\n}\n\n/**\n * Find matching elements in JSON.\n * @param {Object} json JSON to be searched\n * @param {String} path JSON-path to search\n * @param {String} [resultType=\"path\"] Result-type of the query\n * @param {JsonPathMatchCallback} [callback] Function to be called on a match\n * @returns {any} Result of the query, depending on the `resultType`\n * @private\n */\nfunction _find(json, path, resultType = ResultType.path, callback) {\n return jsonPath({\n json,\n path,\n flatten: true,\n resultType,\n callback\n });\n}\n\n/**\n * Remove JSON-paths from `paths` that are included in `examplePaths`\n * @param {Object} openApiSpec Open-API spec to search in\n * @param {Set.} paths Paths where the examples have to be removed from\n * @param {Array.} examplePaths JSON-paths of the examples\n * @private\n */\nfunction _excludeExamples(openApiSpec, paths, examplePaths) {\n examplePaths\n .forEach(examplePath => {\n _find(openApiSpec, examplePath)\n .forEach(exampleMatch => {\n for (const jsPath of paths) {\n jsPath.startsWith(exampleMatch) && paths.delete(jsPath);\n }\n });\n });\n}\n\nfunction _isPropertiesDefinition(path) {\n // Path has to end with `properties`\n if (!path.match(/\\['properties']$/)) { return; }\n // Every second consecutive `properties` actually is not a property-definition, but a property itself\n const consecutiveMatch = path.match(/(?} [examplePaths=[]] The paths to the examples, which's content must not be modified\n */\nfunction setNoAdditionalProperties(openApiSpec, examplePaths = []) {\n // Match all combiner keywords that are not preceded by a 'properties' keyword.\n // This allow to have objects that have as property name one of the combiner keywords.\n const hasJsonCombinerParentRegex\n = new RegExp('(? {\n return (schema) => {\n // Exclude schema that have a JSON combiner as parent\n if (hasJsonCombinerParentRegex.test(path)) {\n console.warn('\"additionalProperties\" flag not set '\n + `for ${path} because it has a parent with a JSON-schema combiner keyword.`);\n return;\n }\n // Exclude schema that contains a JSON combiner\n if (JSON_SCHEMA_COMBINERS.some((combiner) => schema.hasOwnProperty(combiner))) {\n console.warn('\"additionalProperties\" flag not set '\n + `for ${path} because it contains JSON-schema combiner keyword.`);\n return;\n }\n // Exclude schema that already contains additionalProperties\n if (schema.hasOwnProperty('additionalProperties')) {\n return;\n }\n schema.additionalProperties = false;\n };\n });\n}\n","/**\n * Contains validation-logic that is specific to V2 of the OpenAPI-spec\n */\n\nconst { JSONPath: jsonPath } = require('jsonpath-plus'),\n cloneDeep = require('lodash.clonedeep'),\n { setAllPropertiesRequired } = require('../service/all-properties-required'),\n { setNoAdditionalProperties } = require('../service/no-additional-properties');\n\n// CONSTANTS\n\nconst PATH__EXAMPLES = '$..examples.application/json',\n PROP__SCHEMA = 'schema',\n PROP__EXAMPLES = 'examples';\n\nmodule.exports = {\n buildValidationMap,\n escapeExampleName,\n getJsonPathsToExamples,\n prepare,\n unescapeExampleNames\n};\n\n// IMPLEMENTATION DETAILS\n\n/**\n * Get the JSONPaths to the examples\n * @returns {Array.} JSONPaths to the examples\n */\nfunction getJsonPathsToExamples() { return [PATH__EXAMPLES]; }\n\n\n/**\n * Builds a map with the path to the repsonse-schema as key and the paths to the examples, as value. The path of the\n * schema is derived from the path to the example and doesn't necessarily mean that the schema actually exists.\n * @param {Array.} pathsExamples Paths to the examples\n * @returns {Object.} Map with schema-path as key and example-paths as value\n * @private\n */\nfunction buildValidationMap(pathsExamples) {\n return pathsExamples.reduce((validationMap, pathExample) => {\n const pathSchema = _getSchemaPathOfExample(pathExample);\n validationMap[pathSchema] = (validationMap[pathSchema] || new Set())\n .add(pathExample);\n return validationMap;\n }, {});\n}\n\n/**\n * Pre-processes the OpenAPI-spec, for further use.\n * The passed spec won't be modified. If a modification happens, a modified copy will be returned.\n * @param {Object} openapiSpec The OpenAPI-spec as JSON-schema\n * @param {boolean} [noAdditionalProperties=false] Don't allow properties that are not defined in the schema\n * @param {boolean} [allPropertiesRequired=false] Make all properties required\n * @return {Object} The prepared OpenAPI-spec\n */\nfunction prepare(openapiSpec, { noAdditionalProperties, allPropertiesRequired } = {}) {\n const openapiSpecCopy = cloneDeep(openapiSpec);\n noAdditionalProperties && setNoAdditionalProperties(openapiSpecCopy, getJsonPathsToExamples());\n allPropertiesRequired && setAllPropertiesRequired(openapiSpecCopy, getJsonPathsToExamples());\n return openapiSpecCopy;\n}\n\n/**\n * Escapes the name of the example.\n * @param {string} rawPath Unescaped path\n * @returns {string} Escaped path\n * @private\n */\nfunction escapeExampleName(rawPath) {\n // No escaping necessary in v2, as there are no named-examples\n return rawPath;\n}\n\n/**\n * Escaped example-names reflect in the result (where they shouldn't). This function reverts it.\n * @param {string} rawPath Escaped path\n * @returns {string} Unescaped path\n */\nfunction unescapeExampleNames(rawPath) {\n // No unescaping necessary in v2, as there are no named-examples\n return rawPath;\n}\n\n/**\n * Gets a JSON-path to the corresponding response-schema, based on a JSON-path to an example.\n * @param {String} pathExample JSON-path to example\n * @returns {String} JSON-path to the corresponding response-schema\n * @private\n */\nfunction _getSchemaPathOfExample(pathExample) {\n const pathSegs = jsonPath.toPathArray(pathExample).slice(),\n idxExamples = pathSegs.lastIndexOf(PROP__EXAMPLES);\n pathSegs.splice(idxExamples, pathSegs.length - idxExamples, PROP__SCHEMA);\n return jsonPath.toPathString(pathSegs);\n}\n","/**\n * Contains validation-logic that is specific to V3 of the OpenAPI-spec\n */\n\nconst { JSONPath: jsonPath } = require('jsonpath-plus'),\n cloneDeep = require('lodash.clonedeep'),\n { ApplicationError, ErrorType } = require('../../application-error'),\n { setAllPropertiesRequired } = require('../service/all-properties-required'),\n { setNoAdditionalProperties } = require('../service/no-additional-properties');\n\n// CONSTANTS\n\nconst PATH__EXAMPLE = '$..responses..content.application/json.example',\n PATH__EXAMPLES = '$..responses..content.application/json.examples.*.value',\n PATH__EXAMPLE__PARAMETER = '$..parameters..example',\n PATH__EXAMPLES__PARAMETER = '$..parameters..examples.*.value',\n PATH__EXAMPLE__REQUEST_BODY = '$..requestBody.content.application/json.example',\n PATH__EXAMPLES__REQUEST_BODY = '$..requestBody.content.application/json.examples.*.value',\n PROP__SCHEMA = 'schema',\n PROP__EXAMPLE = 'example',\n PROP__EXAMPLES = 'examples';\n\nconst ExampleType = {\n single: 'single',\n multi: 'multi'\n};\n\n// PUBLIC API\n\nmodule.exports = {\n buildValidationMap,\n escapeExampleName,\n getJsonPathsToExamples,\n prepare,\n unescapeExampleNames\n};\n\n// IMPLEMENTATION DETAILS\n\n/**\n * Get the JSONPaths to the examples\n * @returns {Array.} JSONPaths to the examples\n */\nfunction getJsonPathsToExamples() {\n return [\n PATH__EXAMPLE,\n PATH__EXAMPLES,\n PATH__EXAMPLE__PARAMETER,\n PATH__EXAMPLES__PARAMETER,\n PATH__EXAMPLE__REQUEST_BODY,\n PATH__EXAMPLES__REQUEST_BODY\n ];\n}\n\n/**\n * Builds a map with the path to the repsonse-schema as key and the paths to the examples, as value. The path of the\n * schema is derived from the path to the example and doesn't necessarily mean that the schema actually exists.\n * @param {Array.} pathsExamples Paths to the examples\n * @returns {Object.} Map with schema-path as key and example-paths as value\n * @private\n */\nfunction buildValidationMap(pathsExamples) {\n const exampleTypesOfSchemas = new Map();\n return pathsExamples.reduce((validationMap, pathExample) => {\n const { pathSchemaAsArray, exampleType } = _getSchemaPathOfExample(pathExample),\n pathSchema = jsonPath.toPathString(pathSchemaAsArray),\n exampleTypeOfSchema = exampleTypesOfSchemas.get(pathSchema);\n if (exampleTypeOfSchema) {\n exampleTypeOfSchema !== exampleType && _throwMutuallyExclusiveError(pathSchemaAsArray);\n }\n exampleTypesOfSchemas.set(pathSchema, exampleType);\n validationMap[pathSchema] = (validationMap[pathSchema] || new Set())\n .add(pathExample);\n return validationMap;\n }, {});\n}\n\n/**\n * Pre-processes the OpenAPI-spec, for further use.\n * The passed spec won't be modified. If a modification happens, a modified copy will be returned.\n * @param {Object} openapiSpec The OpenAPI-spec as JSON-schema\n * @param {boolean} [noAdditionalProperties=false] Don't allow properties that are not defined in the schema\n * @param {boolean} [allPropertiesRequired=false] Make all properties required\n * @return {Object} The prepared OpenAPI-spec\n */\nfunction prepare(openapiSpec, { noAdditionalProperties, allPropertiesRequired } = {}) {\n const openapiSpecCopy = cloneDeep(openapiSpec);\n noAdditionalProperties && setNoAdditionalProperties(openapiSpecCopy, getJsonPathsToExamples());\n allPropertiesRequired && setAllPropertiesRequired(openapiSpecCopy, getJsonPathsToExamples());\n return openapiSpecCopy;\n}\n\n/**\n * Escapes the name of the example. In order to do that, a backtick has to be added to the beginning of the key.\n * @param {string} rawPath Unescaped path\n * @returns {string} Escaped path\n * @private\n */\nfunction escapeExampleName(rawPath) {\n return rawPath.replace(/\\['examples'\\]\\['(.*)\\]\\['value'\\]$/, \"['examples']['`$1]['value']\");\n}\n\n/**\n * Escaped example-names reflect in the result (where they shouldn't). This function reverts it.\n * @param {string} rawPath Escaped path\n * @returns {string} Unescaped path\n */\nfunction unescapeExampleNames(rawPath) {\n return rawPath && rawPath.replace(/\\/examples\\/`(.*)\\/value$/, '/examples/$1/value');\n}\n\n/**\n * Gets a JSON-path to the corresponding response-schema, based on a JSON-path to an example.\n *\n * It is assumed that the JSON-path to the example is valid and existing.\n * @param {String} pathExample JSON-path to example\n * @returns {{\n * exampleType: ExampleType,\n * pathSchema: String\n * }} JSON-path to the corresponding response-schema\n * @private\n */\nfunction _getSchemaPathOfExample(pathExample) {\n const pathSegs = jsonPath.toPathArray(pathExample).slice(),\n idxExample = pathSegs.lastIndexOf(PROP__EXAMPLE),\n /** @type ExampleType */\n exampleType = idxExample > -1\n ? ExampleType.single\n : ExampleType.multi,\n idxExamples = exampleType === ExampleType.single\n ? idxExample\n : pathSegs.lastIndexOf(PROP__EXAMPLES);\n pathSegs.splice(idxExamples, pathSegs.length - idxExamples, PROP__SCHEMA);\n return {\n exampleType,\n pathSchemaAsArray: pathSegs\n };\n}\n\n/**\n * Checks if only `example` or `examples` is set for the schema, as they are mutually exclusive by OpenAPI-spec.\n * @param {Array.} pathSchemaAsArray JSON-path to the Schema, as JSON-path-array\n * @throws ApplicationError if both are set\n * @private\n */\nfunction _throwMutuallyExclusiveError(pathSchemaAsArray) {\n const pathContextAsArray = pathSchemaAsArray.slice(0, pathSchemaAsArray.length - 1); // Strip `schema` away\n throw ApplicationError.create({\n type: ErrorType.errorAndErrorsMutuallyExclusive,\n message: 'Properties \"error\" and \"errors\" are mutually exclusive',\n params: {\n pathContext: jsonPath.toPointer(pathContextAsArray)\n }\n });\n}\n","/**\n * Entry-point for the validator-API\n */\n\nconst\n merge = require('lodash.merge'),\n flatten = require('lodash.flatten'),\n flatMap = require('lodash.flatmap'),\n fs = require('fs'),\n path = require('path'),\n glob = require('glob'),\n yaml = require('yaml'),\n { JSONPath: jsonPath } = require('jsonpath-plus'),\n refParser = require('json-schema-ref-parser'),\n { createError } = require('errno').custom,\n ResultType = require('./const/result-type'),\n { getValidatorFactory, compileValidate } = require('./validator'),\n Determiner = require('./impl'),\n { ApplicationError, ErrorType } = require('./application-error'),\n { createValidationResponse, dereferenceJsonSchema } = require('./utils');\n\n// CONSTANTS\n\nconst SYM__INTERNAL = Symbol('internal'),\n PROP__SCHEMAS_WITH_EXAMPLES = 'schemasWithExamples',\n FILE_EXTENSIONS__YAML = [\n 'yaml',\n 'yml'\n ];\n\n// STATICS\n\n/**\n * ErrorJsonPathNotFound\n * @typedef {{\n * cause: {\n * [params]: {\n * [path]: string\n * }\n * }\n * }} ErrorJsonPathNotFound\n * @augments CustomError\n */\n\n/**\n * @constructor\n * @augments CustomError\n * @returns {ErrorJsonPathNotFound}\n */\nconst ErrorJsonPathNotFound = createError(ErrorType.jsonPathNotFound);\n\n// PUBLIC API\n\nmodule.exports = {\n 'default': validateExamples,\n validateFile,\n validateExample,\n validateExamplesByMap\n};\n\n// IMPLEMENTATION DETAILS\n\n// Type definitions\n\n/**\n * ValidationStatistics\n * @typedef {{\n * schemasWithExamples: number,\n * examplesTotal: number,\n * examplesWithoutSchema: number,\n * [matchingFilePathsMapping]: number\n * }} ValidationStatistics\n */\n\n/**\n * ValidationResponse\n * @typedef {{\n * valid: boolean,\n * statistics: ValidationStatistics,\n * errors: Array.\n * }} ValidationResponse\n */\n\n/**\n * @callback ValidationHandler\n * @param {ValidationStatistics} statistics\n * @returns {Array.}\n */\n\n// Public\n\n/**\n * Validates OpenAPI-spec with embedded examples.\n * @param {Object} openapiSpec OpenAPI-spec\n * @param {boolean} [noAdditionalProperties=false] Don't allow properties that are not defined in the schema\n * @param {boolean} [allPropertiesRequired=false] Make all properties required\n * @param {Array.} [ignoreFormats] List of datatype formats that shall be ignored (to prevent\n * \"unsupported format\" errors). If an Array with only one string is\n * provided where the formats are separated with `\\n`, the entries\n * will be expanded to a new array containing all entries.\n * @returns {ValidationResponse}\n */\nasync function validateExamples(openapiSpec, { noAdditionalProperties, ignoreFormats, allPropertiesRequired } = {}) {\n const impl = Determiner.getImplementation(openapiSpec);\n openapiSpec = await refParser.dereference(openapiSpec);\n openapiSpec = impl.prepare(openapiSpec, { noAdditionalProperties, allPropertiesRequired });\n let pathsExamples = impl.getJsonPathsToExamples()\n .reduce((res, pathToExamples) => {\n return res.concat(_extractExamplePaths(openapiSpec, pathToExamples));\n }, [])\n .map(impl.escapeExampleName);\n return _validateExamplesPaths({ impl }, pathsExamples, openapiSpec, { ignoreFormats });\n}\n\n/**\n * Validates OpenAPI-spec with embedded examples.\n * @param {string} filePath File-path to the OpenAPI-spec\n * @param {boolean} [noAdditionalProperties=false] Don't allow properties that are not defined in the schema\n * @param {boolean} [allPropertiesRequired=false] Make all properties required\n * @param {Array.} [ignoreFormats] List of datatype formats that shall be ignored (to prevent\n * \"unsupported format\" errors). If an Array with only one string is\n * provided where the formats are separated with `\\n`, the entries\n * will be expanded to a new array containing all entries.\n * @returns {ValidationResponse}\n */\nasync function validateFile(filePath, { noAdditionalProperties, ignoreFormats, allPropertiesRequired } = {}) {\n let openapiSpec = null;\n try {\n openapiSpec = await _parseSpec(filePath);\n } catch (err) {\n return createValidationResponse({ errors: [ApplicationError.create(err)] });\n }\n return validateExamples(openapiSpec, { noAdditionalProperties, ignoreFormats, allPropertiesRequired });\n}\n\n/**\n * Validates examples by mapping-files.\n * @param {string} filePathSchema File-path to the OpenAPI-spec\n * @param {string} globMapExternalExamples File-path (globs are supported) to the mapping-file containing JSON-\n * paths to schemas as key and a single file-path or Array of file-paths\n * to external examples\n * @param {boolean} [cwdToMappingFile=false] Change working directory for resolving the example-paths (relative to\n * the mapping-file)\n * @param {boolean} [noAdditionalProperties=false] Don't allow properties that are not defined in the schema\n * @param {boolean} [allPropertiesRequired=false] Make all properties required\n * @param {Array.} [ignoreFormats] List of datatype formats that shall be ignored (to prevent\n * \"unsupported format\" errors). If an Array with only one string is\n * provided where the formats are separated with `\\n`, the entries\n * will be expanded to a new array containing all entries.\n * @returns {ValidationResponse}\n */\nasync function validateExamplesByMap(filePathSchema, globMapExternalExamples,\n { cwdToMappingFile, noAdditionalProperties, ignoreFormats, allPropertiesRequired } = {}\n) {\n let matchingFilePathsMapping = 0;\n const filePathsMaps = glob.sync(\n globMapExternalExamples,\n // Using `nonull`-option to explicitly create an app-error if there's no match for `globMapExternalExamples`\n { nonull: true }\n );\n let responses = [];\n // for..of here, to support sequential execution of async calls. This is required, since dereferencing the\n // `openapiSpec` is not concurrency-safe\n for (const filePathMapExternalExamples of filePathsMaps) {\n let mapExternalExamples = null,\n openapiSpec = null;\n try {\n mapExternalExamples = JSON.parse(fs.readFileSync(filePathMapExternalExamples, 'utf-8'));\n openapiSpec = await _parseSpec(filePathSchema);\n openapiSpec = Determiner.getImplementation(openapiSpec)\n .prepare(openapiSpec, { noAdditionalProperties, allPropertiesRequired });\n } catch (err) {\n responses.push(createValidationResponse({ errors: [ApplicationError.create(err)] }));\n continue;\n }\n // Not using `glob`'s response-length, because it is `1` if there's no match for `globMapExternalExamples`.\n // Instead, increment on every match\n matchingFilePathsMapping++;\n responses.push(\n _validate(\n statistics => {\n return _handleExamplesByMapValidation(\n openapiSpec, mapExternalExamples, statistics, {\n cwdToMappingFile,\n dirPathMapExternalExamples: path.dirname(filePathMapExternalExamples),\n ignoreFormats\n }\n ).map(\n (/** @type ApplicationError */ error) => Object.assign(error, {\n mapFilePath: path.normalize(filePathMapExternalExamples)\n })\n );\n }\n )\n );\n }\n return merge(\n responses.reduce((res, response) => {\n if (!res) {\n return response;\n }\n return _mergeValidationResponses(res, response);\n }, null),\n { statistics: { matchingFilePathsMapping } }\n );\n}\n\n/**\n * Validates a single external example.\n * @param {String} filePathSchema File-path to the OpenAPI-spec\n * @param {String} pathSchema JSON-path to the schema\n * @param {String} filePathExample File-path to the external example-file\n * @param {boolean} [noAdditionalProperties=false] Don't allow properties that are not described in the schema\n * @param {boolean} [allPropertiesRequired=false] Make all properties required\n * @param {Array.} [ignoreFormats] List of datatype formats that shall be ignored (to prevent\n * \"unsupported format\" errors). If an Array with only one string is\n * provided where the formats are separated with `\\n`, the entries\n * will be expanded to a new array containing all entries.\n * @returns {ValidationResponse}\n */\nasync function validateExample(filePathSchema, pathSchema, filePathExample, {\n noAdditionalProperties,\n ignoreFormats,\n allPropertiesRequired\n} = {}) {\n let example = null,\n schema = null,\n openapiSpec = null;\n try {\n example = JSON.parse(fs.readFileSync(filePathExample, 'utf-8'));\n openapiSpec = await _parseSpec(filePathSchema);\n openapiSpec = Determiner.getImplementation(openapiSpec)\n .prepare(openapiSpec, { noAdditionalProperties, allPropertiesRequired });\n schema = _extractSchema(pathSchema, openapiSpec);\n } catch (err) {\n return createValidationResponse({ errors: [ApplicationError.create(err)] });\n }\n return _validate(\n statistics => _validateExample({\n createValidator: _initValidatorFactory(openapiSpec, { ignoreFormats }),\n schema,\n example,\n statistics,\n filePathExample\n })\n );\n}\n\n// Private\n\n/**\n * Parses the OpenAPI-spec (supports JSON and YAML)\n * @param {String} filePath File-path to the OpenAPI-spec\n * @returns {object} Parsed OpenAPI-spec\n * @private\n */\nasync function _parseSpec(filePath) {\n const isYaml = _isFileTypeYaml(filePath);\n let jsonSchema;\n\n if (isYaml) {\n try {\n jsonSchema = yaml.parse(fs.readFileSync(filePath, 'utf-8'));\n } catch (e) {\n const { name, message } = e;\n throw new ApplicationError(ErrorType.parseError, { message: `${name}: ${message}` });\n }\n } else {\n jsonSchema = JSON.parse(fs.readFileSync(filePath, 'utf-8'));\n }\n\n return await dereferenceJsonSchema(filePath, jsonSchema);\n}\n\n/**\n * Determines whether the filePath is pointing to a YAML-file\n * @param {String} filePath File-path to the OpenAPI-spec\n * @returns {boolean} `true`, if the file is a YAML-file\n * @private\n */\nfunction _isFileTypeYaml(filePath) {\n const extension = filePath.split('.').pop();\n return FILE_EXTENSIONS__YAML.includes(extension);\n}\n\n/**\n * Top-level validator. Prepares common values, required for the validation, then calles the validator and prepares\n * the result for the output.\n * @param {ValidationHandler} validationHandler The handler which performs the validation. It will receive the\n * statistics-object as argument and has to return an Array of\n * errors (or an empty Array, when all examples are valid)\n * @returns {ValidationResponse}\n * @private\n */\nfunction _validate(validationHandler) {\n const statistics = _initStatistics(),\n errors = validationHandler(statistics);\n return createValidationResponse({ errors, statistics });\n}\n\n/**\n * Validates examples by a mapping-file.\n * @param {Object} openapiSpec OpenAPI-spec\n * @param {Object} mapExternalExamples Mapping-file containing JSON-paths to schemas as\n * key and a single file-path or Array of file-paths\n * to external examples\n * @param {ValidationStatistics} statistics Validation-statistics\n * @param {boolean} [cwdToMappingFile=false] Change working directory for resolving the example-\n * paths (relative to the mapping-file)\n * @param {string} [dirPathMapExternalExamples] The directory-path of the mapping-file\n * @param {Array.} [ignoreFormats] List of datatype formats that shall be ignored (to prevent\n * \"unsupported format\" errors). If an Array with only one string is\n * provided where the formats are separated with `\\n`, the entries\n * will be expanded to a new array containing all entries.\n * @returns {Array.}\n * @private\n */\nfunction _handleExamplesByMapValidation(openapiSpec, mapExternalExamples, statistics,\n { cwdToMappingFile = false, dirPathMapExternalExamples, ignoreFormats }\n) {\n return flatMap(Object.entries(mapExternalExamples), ([pathSchema, filePathsExample]) => {\n let schema = null;\n try {\n schema = _extractSchema(pathSchema, openapiSpec);\n } catch (/** @type ErrorJsonPathNotFound */ err) {\n // If the schema can't be found, don't even attempt to process the examples\n return ApplicationError.create(err);\n }\n return flatMap(\n flatten([filePathsExample]),\n filePathExample => {\n let examples = [];\n try {\n const resolvedFilePathExample = cwdToMappingFile\n ? path.join(dirPathMapExternalExamples, filePathExample)\n : filePathExample;\n const globResolvedFilePathExample = glob.sync(resolvedFilePathExample);\n if (globResolvedFilePathExample.length === 0) {\n return [ApplicationError.create({\n type: ErrorType.jsENOENT,\n message: `No such file or directory: '${resolvedFilePathExample}'`,\n path: resolvedFilePathExample\n })];\n }\n for (const filePathExample of globResolvedFilePathExample) {\n examples.push({\n path: path.normalize(filePathExample),\n content: JSON.parse(fs.readFileSync(filePathExample, 'utf-8'))\n });\n }\n } catch (err) {\n return [ApplicationError.create(err)];\n }\n return flatMap(examples, example => _validateExample({\n createValidator: _initValidatorFactory(openapiSpec, { ignoreFormats }),\n schema,\n example: example.content,\n statistics,\n filePathExample: example.path\n }));\n }\n );\n });\n}\n\n/**\n * Merges two `ValidationResponses` together and returns the merged result. The passed `ValidationResponse`s won't be\n * modified.\n * @param {ValidationResponse} response1\n * @param {ValidationResponse} response2\n * @returns {ValidationResponse}\n * @private\n */\nfunction _mergeValidationResponses(response1, response2) {\n return createValidationResponse({\n errors: response1.errors.concat(response2.errors),\n statistics: Object.entries(response1.statistics)\n .reduce((res, [key, val]) => {\n if (PROP__SCHEMAS_WITH_EXAMPLES === key) {\n [\n response1,\n response2\n ].forEach(response => {\n const schemasWithExample = response.statistics[SYM__INTERNAL][PROP__SCHEMAS_WITH_EXAMPLES]\n .values();\n for (let schema of schemasWithExample) {\n res[SYM__INTERNAL][PROP__SCHEMAS_WITH_EXAMPLES].add(schema);\n }\n });\n return res;\n }\n res[key] = val + response2.statistics[key];\n return res;\n }, _initStatistics())\n });\n}\n\n/**\n * Extracts all JSON-paths to examples from a OpenAPI-spec\n * @param {Object} openapiSpec OpenAPI-spec\n * @param {String} jsonPathToExamples JSON-path to the examples, in the OpenAPI-Spec\n * @returns {Array.} JSON-paths to examples\n * @private\n */\nfunction _extractExamplePaths(openapiSpec, jsonPathToExamples) {\n return jsonPath({\n json: openapiSpec,\n path: jsonPathToExamples,\n resultType: ResultType.path\n });\n}\n\n/**\n * Validates examples at the given paths in the OpenAPI-spec.\n * @param {Object} impl Spec-dependant validator\n * @param {Array.} pathsExamples JSON-paths to examples\n * @param {Object} openapiSpec OpenAPI-spec\n * @param {Array.} [ignoreFormats] List of datatype formats that shall be ignored (to prevent\n * \"unsupported format\" errors). If an Array with only one string is\n * provided where the formats are separated with `\\n`, the entries\n * will be expanded to a new array containing all entries.\n * @returns {ValidationResponse}\n * @private\n */\nfunction _validateExamplesPaths({ impl }, pathsExamples, openapiSpec, { ignoreFormats }) {\n const statistics = _initStatistics(),\n validationResult = {\n valid: true,\n statistics,\n errors: []\n },\n createValidator = _initValidatorFactory(openapiSpec, { ignoreFormats });\n let validationMap;\n try {\n // Create mapping between JSON-schemas and examples\n validationMap = impl.buildValidationMap(pathsExamples);\n } catch (error) {\n // Throw unexpected errors\n if (!(error instanceof ApplicationError)) {\n throw error;\n }\n // Add known errors and stop\n validationResult.valid = false;\n validationResult.errors.push(error);\n return validationResult;\n }\n // Start validation\n const schemaPaths = Object.keys(validationMap);\n schemaPaths.forEach(pathSchema => {\n _validateSchema({\n openapiSpec, createValidator, pathSchema, validationMap, statistics,\n validationResult\n });\n });\n // Revert escaped example names from the results\n validationResult.errors.forEach((example) => {\n example.examplePath = impl.unescapeExampleNames(example.examplePath);\n });\n return validationResult;\n}\n\n/**\n * Validates a single schema.\n * @param {Object} openapiSpec OpenAPI-spec\n * @param {ajv} createValidator Factory, to create JSON-schema validator\n * @param {string} pathSchema JSON-path to schema (for request- or response-property)\n * @param {Object.} validationMap Map with schema-path as key and example-paths as value\n * @param {Object} statistics Object to contain statistics metrics\n * @param {Object} validationResult Container, for the validation-results\n * @private\n */\nfunction _validateSchema({\n openapiSpec, createValidator, pathSchema, validationMap, statistics,\n validationResult\n}) {\n const errors = validationResult.errors;\n validationMap[pathSchema].forEach(pathExample => {\n const example = _getObjectByPath(pathExample, openapiSpec),\n // Examples with missing schemas may occur and those are considered valid\n schema = _extractSchema(pathSchema, openapiSpec, true),\n curErrors = _validateExample({\n createValidator,\n schema,\n example,\n statistics\n }).map(error => {\n error.examplePath = jsonPath.toPointer(jsonPath.toPathArray(pathExample));\n return error;\n });\n if (!curErrors.length) {\n return;\n }\n validationResult.valid = false;\n errors.splice(errors.length - 1, 0, ...curErrors);\n });\n}\n\n/**\n * Creates a container-object for the validation statistics.\n * @returns {ValidationStatistics}\n * @private\n */\nfunction _initStatistics() {\n const statistics = {\n [SYM__INTERNAL]: {\n [PROP__SCHEMAS_WITH_EXAMPLES]: new Set()\n },\n examplesTotal: 0,\n examplesWithoutSchema: 0\n };\n Object.defineProperty(statistics, PROP__SCHEMAS_WITH_EXAMPLES, {\n enumerable: true,\n get: () => statistics[SYM__INTERNAL][PROP__SCHEMAS_WITH_EXAMPLES].size\n });\n return statistics;\n}\n\n/**\n * Extract object(s) by the given JSON-path\n * @param {String} path JSON-path\n * @param {Object} json JSON to extract the object(s) from\n * @returns {Object|Array.|undefined} All matching objects. Single object if there is only one match\n * @private\n */\nfunction _getObjectByPath(path, json) {\n return jsonPath({\n json,\n path,\n flatten: true,\n wrap: false,\n resultType: ResultType.value\n });\n}\n\n/**\n * Validates example against the schema. The precondition for this function to work is that the example exists at the\n * given path.\n * `pathExample` and `filePathExample` are exclusively mandatory.\n * itself\n * @param {Function} createValidator Factory, to create JSON-schema validator\n * @param {Object} schema JSON-schema\n * @param {Object} example Example to validate\n * @param {Object} statistics Object to contain statistics metrics\n * @param {String} [filePathExample] File-path to the example file\n * @returns {Array.} Array with errors. Empty array, if examples are valid\n * @private\n */\nfunction _validateExample({ createValidator, schema, example, statistics, filePathExample }) {\n const\n errors = [];\n statistics.examplesTotal++;\n // No schema, no validation (Examples without schema are considered valid)\n if (!schema) {\n statistics.examplesWithoutSchema++;\n return errors;\n }\n statistics[SYM__INTERNAL][PROP__SCHEMAS_WITH_EXAMPLES].add(schema);\n const validate = compileValidate(createValidator(), schema);\n if (validate(example)) {\n return errors;\n }\n return errors.concat(...validate.errors.map(ApplicationError.create))\n .map(error => {\n if (!filePathExample) {\n return error;\n }\n error.exampleFilePath = filePathExample;\n return error;\n });\n}\n\n/**\n * Create a new instance of a JSON schema validator\n * @returns {ajv}\n * @private\n */\nfunction _initValidatorFactory(specSchema, { ignoreFormats }) {\n return getValidatorFactory(specSchema, {\n schemaId: 'auto',\n discriminator: true,\n strict: false,\n allErrors: true,\n formats: ignoreFormats && ignoreFormats.reduce((result, entry) => {\n result[entry] = () => true;\n return result;\n }, {})\n });\n}\n\n/**\n * Extracts the schema in the OpenAPI-spec at the given JSON-path.\n * @param {string} pathSchema JSON-path to the schema\n * @param {Object} openapiSpec OpenAPI-spec\n * @param {boolean} [suppressErrorIfNotFound=false] Don't throw `ErrorJsonPathNotFound` if the response does not\n * exist at the given JSON-path\n * @returns {Object|Array.|undefined} Matching schema(s)\n * @throws {ErrorJsonPathNotFound} Thrown, when there is no schema at the given path and\n * `suppressErrorIfNotFound` is false\n * @private\n */\nfunction _extractSchema(pathSchema, openapiSpec, suppressErrorIfNotFound = false) {\n const schema = _getObjectByPath(pathSchema, openapiSpec);\n if (!suppressErrorIfNotFound && !schema) {\n throw new ErrorJsonPathNotFound(`Path to schema can't be found: '${pathSchema}'`, {\n params: {\n path: pathSchema\n }\n });\n }\n return schema;\n}\n","const path = require('path'),\n refParser = require('json-schema-ref-parser');\n\nmodule.exports = {\n createValidationResponse,\n dereferenceJsonSchema\n};\n\n/**\n * Creates a unified response for the validation-result\n * @param {Array.} errors\n * @param {ValidationStatistics} statistics\n * @returns {ValidationResponse}\n * @private\n */\nfunction createValidationResponse({ errors, statistics = {} }) {\n return {\n valid: !errors.length,\n statistics,\n errors\n };\n}\n\n/**\n * Includes all referenced, external schemas (by the keyword `$ref`) into the schema\n *\n * CAUTION: This function is not concurrency-safe !!\n * This function changes the working dir and sets it back. This may become an concurrency issue when there are\n * other tasks running that rely on the working dir while this function waits for the asynchronous task of\n * dereferencing to complete.\n *\n * @param {String} pathToSchema File-path to the schema\n * @param {Object} jsonSchema Schema with potential externally referenced schemas\n * @returns {Promise} Dereferenced schema\n */\nasync function dereferenceJsonSchema(pathToSchema, jsonSchema) {\n const currentWorkingDir = process.cwd();\n // Change the working dir to the schema-path, to make sure that relative paths can be resolved\n process.chdir(path.dirname(pathToSchema));\n const dereferencedSchema = await refParser.dereference(jsonSchema);\n // Restore original working dir\n process.chdir(currentWorkingDir);\n return dereferencedSchema;\n}\n","/**\n * Wrapper for the JSONSchema-validator\n */\n\nconst { JSONPath: jsonPath } = require('jsonpath-plus'),\n JsonPointer = require('json-pointer'),\n Ajv = require('ajv-draft-04'),\n addFormats = require('ajv-formats');\n\nconst PROP__ID = '$id',\n JSON_PATH__REFS = '$..\\$ref',\n ID__SPEC_SCHEMA = 'https://www.npmjs.com/package/openapi-examples-validator/defs.json',\n ID__RESPONSE_SCHEMA = 'https://www.npmjs.com/package/openapi-examples-validator/schema.json';\n\nmodule.exports = {\n getValidatorFactory,\n compileValidate\n};\n\n/**\n * Get a factory-function to create a prepared validator-instance\n * @param {Object} specSchema OpenAPI-spec of which potential local references will be extracted\n * @param {Object} [options] Options for the validator\n * @returns {function(): (ajv | ajv.Ajv)}\n */\nfunction getValidatorFactory(specSchema, options) {\n const preparedSpecSchema = _createReferenceSchema(specSchema);\n return () => {\n const validator = new Ajv(options);\n addFormats(validator);\n\n validator.addSchema(preparedSpecSchema);\n\n return validator;\n };\n}\n\n/**\n * Compiles the validator-function.\n * @param {ajv | ajv.Ajv} validator Validator-instance\n * @param {Object} responseSchema The response-schema, against the examples will be validated\n * @returns {ajv.ValidateFunction}\n */\nfunction compileValidate(validator, responseSchema) {\n const preparedResponseSchema = _prepareResponseSchema(responseSchema, ID__RESPONSE_SCHEMA);\n _replaceRefsToPreparedSpecSchema(preparedResponseSchema);\n\n let result;\n try {\n result = validator.compile(preparedResponseSchema);\n } catch (e) {\n result = () => {};\n result.errors = [e];\n }\n return result;\n}\n\n/**\n * Prepares the schema, to be used with internal-references\n * @param {Object} specSchema The schema to be prebared\n * @param {String} idSchema The unique ID for the schema\n * @returns {Object}\n * @private\n */\nfunction _prepareResponseSchema(specSchema, idSchema) {\n const preparedSchema = Object.assign({}, specSchema);\n preparedSchema[PROP__ID] = idSchema;\n return preparedSchema;\n}\n\n/**\n * Replaces all internal references to the schema, with the extracted references, based on the origin OpenAPI-spec\n * @param {Object} schema The schema, containing references have to be replaced\n * @private\n */\nfunction _replaceRefsToPreparedSpecSchema(schema) {\n jsonPath({\n path: JSON_PATH__REFS,\n json: schema,\n callback(value, type, payload) {\n if (!value.startsWith('#')) { return; }\n payload.parent[payload.parentProperty] = `${ ID__SPEC_SCHEMA }${ value }`;\n }\n });\n}\n\n/**\n * Extracts all references and returns a new schema, containing only those.\n * @param {Object} specSchema Schema, which references shall be extracted\n * @returns {Object}\n * @private\n */\nfunction _createReferenceSchema(specSchema) {\n const refSchema = {\n [PROP__ID]: ID__SPEC_SCHEMA\n };\n jsonPath({\n path: JSON_PATH__REFS,\n json: specSchema,\n callback(value) {\n if (!value.startsWith('#')) { return; }\n const pointer = value.substring(1),\n definition = JsonPointer.get(specSchema, pointer);\n JsonPointer.set(refSchema, pointer, definition);\n }\n });\n return refSchema;\n}\n","module.exports = require(\"ajv-draft-04\");","module.exports = require(\"ajv-formats\");","module.exports = require(\"errno\");","module.exports = require(\"glob\");","module.exports = require(\"json-pointer\");","module.exports = require(\"json-schema-ref-parser\");","module.exports = require(\"jsonpath-plus\");","module.exports = require(\"lodash.clonedeep\");","module.exports = require(\"lodash.flatmap\");","module.exports = require(\"lodash.flatten\");","module.exports = require(\"lodash.merge\");","module.exports = require(\"yaml\");","module.exports = require(\"fs\");","module.exports = require(\"path\");","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","// startup\n// Load entry module and return exports\n// This entry module is referenced by other modules so it can't be inlined\nvar __webpack_exports__ = __webpack_require__(579);\n"],"names":["merge","require","ENOENT","ErrorType","jsENOENT","code","jsonPathNotFound","errorAndErrorsMutuallyExclusive","parseError","validation","ApplicationError","static","err","message","path","cause","type","options","params","constructor","Object","assign","this","module","exports","parent","parentProperty","pointer","value","implV2","implV3","REGEX__OPEN_API","getImplementation","openapiSpec","swagger","openapi","match","applyCallbackToAllObjectModels","setAllPropertiesRequired","openApiSpec","examplePaths","hasOwnProperty","required","keys","properties","JSONPath","jsonPath","ResultType","_find","json","resultType","callback","flatten","matchCallbackBuilder","paths","Set","forEach","consecutiveMatch","length","_isPropertiesDefinition","add","examplePath","exampleMatch","jsPath","startsWith","delete","_excludeExamples","result","data","entity","setNoAdditionalProperties","hasJsonCombinerParentRegex","RegExp","JSON_SCHEMA_COMBINERS","join","schema","test","console","warn","some","combiner","additionalProperties","cloneDeep","getJsonPathsToExamples","buildValidationMap","pathsExamples","reduce","validationMap","pathExample","pathSchema","pathSegs","toPathArray","slice","idxExamples","lastIndexOf","splice","toPathString","_getSchemaPathOfExample","escapeExampleName","rawPath","prepare","noAdditionalProperties","allPropertiesRequired","openapiSpecCopy","unescapeExampleNames","ExampleType","exampleTypesOfSchemas","Map","pathSchemaAsArray","exampleType","idxExample","exampleTypeOfSchema","get","pathContextAsArray","create","pathContext","toPointer","_throwMutuallyExclusiveError","set","replace","flatMap","fs","glob","yaml","refParser","createError","getValidatorFactory","compileValidate","Determiner","createValidationResponse","dereferenceJsonSchema","SYM__INTERNAL","Symbol","PROP__SCHEMAS_WITH_EXAMPLES","FILE_EXTENSIONS__YAML","ErrorJsonPathNotFound","async","validateExamples","ignoreFormats","impl","dereference","res","pathToExamples","concat","jsonPathToExamples","_extractExamplePaths","map","statistics","_initStatistics","validationResult","valid","errors","createValidator","_initValidatorFactory","error","push","example","_getObjectByPath","_extractSchema","curErrors","_validateExample","_validateSchema","_validateExamplesPaths","_parseSpec","filePath","isYaml","extension","split","pop","includes","_isFileTypeYaml","jsonSchema","parse","readFileSync","e","name","JSON","_validate","validationHandler","_handleExamplesByMapValidation","mapExternalExamples","cwdToMappingFile","dirPathMapExternalExamples","entries","filePathsExample","filePathExample","examples","resolvedFilePathExample","globResolvedFilePathExample","sync","normalize","content","examplesTotal","examplesWithoutSchema","defineProperty","enumerable","size","wrap","validate","exampleFilePath","specSchema","schemaId","discriminator","strict","allErrors","formats","entry","suppressErrorIfNotFound","validateFile","validateExample","filePathSchema","validateExamplesByMap","globMapExternalExamples","matchingFilePathsMapping","filePathsMaps","nonull","responses","filePathMapExternalExamples","dirname","mapFilePath","response","response2","response1","key","val","schemasWithExample","values","pathToSchema","currentWorkingDir","process","cwd","chdir","dereferencedSchema","JsonPointer","Ajv","addFormats","JSON_PATH__REFS","ID__SPEC_SCHEMA","preparedSpecSchema","refSchema","substring","definition","_createReferenceSchema","validator","addSchema","responseSchema","preparedResponseSchema","idSchema","preparedSchema","_prepareResponseSchema","payload","compile","__webpack_module_cache__","__webpack_exports__","__webpack_require__","moduleId","cachedModule","undefined","__webpack_modules__"],"sourceRoot":""} \ No newline at end of file +{"version":3,"file":"index.js","mappings":"2BAAA,MACIA,EAAQC,EAAQ,MAChB,OAAEC,GAAWD,EAAAA,KAAAA,KA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Q7O,OAAO6O,EAAQ5O,gBAAmB,GAAG6N,IAAoB3N,IACrE,IAlCJ,IACIuC,EAAS4L,EAAUQ,QAAQL,EAC/B,CAAE,MAAO7E,GACLlH,EAASA,OACTA,EAAO6F,OAAS,CAACqB,EACrB,CACA,OAAOlH,CACX,E,uBCvDA5C,EAAOC,QAAUvB,QAAQ,e,uBCAzBsB,EAAOC,QAAUvB,QAAQ,c,uBCAzBsB,EAAOC,QAAUvB,QAAQ,Q,uBCAzBsB,EAAOC,QAAUvB,QAAQ,O,uBCAzBsB,EAAOC,QAAUvB,QAAQ,e,uBCAzBsB,EAAOC,QAAUvB,QAAQ,yB,uBCAzBsB,EAAOC,QAAUvB,QAAQ,gB,uBCAzBsB,EAAOC,QAAUvB,QAAQ,mB,uBCAzBsB,EAAOC,QAAUvB,QAAQ,iB,uBCAzBsB,EAAOC,QAAUvB,QAAQ,iB,uBCAzBsB,EAAOC,QAAUvB,QAAQ,e,sBCAzBsB,EAAOC,QAAUvB,QAAQ,O,uBCAzBsB,EAAOC,QAAUvB,QAAQ,K,sBCAzBsB,EAAOC,QAAUvB,QAAQ,O,GCCrBuQ,EAA2B,CAAC,ECE5BC,EDCJ,SAASC,EAAoBC,GAE5B,IAAIC,EAAeJ,EAAyBG,GAC5C,QAAqBE,IAAjBD,EACH,OAAOA,EAAapP,QAGrB,IAAID,EAASiP,EAAyBG,GAAY,CAGjDnP,QAAS,CAAC,GAOX,OAHAsP,EAAoBH,GAAUpP,EAAQA,EAAOC,QAASkP,GAG/CnP,EAAOC,OACf,CCnB0BkP,CAAoB,K","sources":["webpack://openapi-examples-validator/./src/application-error.js","webpack://openapi-examples-validator/./src/const/result-type.js","webpack://openapi-examples-validator/./src/impl/index.js","webpack://openapi-examples-validator/./src/impl/service/all-properties-required.js","webpack://openapi-examples-validator/./src/impl/service/common.js","webpack://openapi-examples-validator/./src/impl/service/no-additional-properties.js","webpack://openapi-examples-validator/./src/impl/v2/index.js","webpack://openapi-examples-validator/./src/impl/v3/index.js","webpack://openapi-examples-validator/./src/index.js","webpack://openapi-examples-validator/./src/utils/index.js","webpack://openapi-examples-validator/./src/validator.js","webpack://openapi-examples-validator/external commonjs \"ajv-draft-04\"","webpack://openapi-examples-validator/external commonjs \"ajv-formats\"","webpack://openapi-examples-validator/external commonjs \"errno\"","webpack://openapi-examples-validator/external commonjs \"glob\"","webpack://openapi-examples-validator/external commonjs \"json-pointer\"","webpack://openapi-examples-validator/external commonjs \"json-schema-ref-parser\"","webpack://openapi-examples-validator/external commonjs \"jsonpath-plus\"","webpack://openapi-examples-validator/external commonjs \"lodash.clonedeep\"","webpack://openapi-examples-validator/external commonjs \"lodash.flatmap\"","webpack://openapi-examples-validator/external commonjs \"lodash.flatten\"","webpack://openapi-examples-validator/external commonjs \"lodash.merge\"","webpack://openapi-examples-validator/external commonjs \"yaml\"","webpack://openapi-examples-validator/external node-commonjs \"fs\"","webpack://openapi-examples-validator/external node-commonjs \"path\"","webpack://openapi-examples-validator/webpack/bootstrap","webpack://openapi-examples-validator/webpack/startup"],"sourcesContent":["const\n merge = require('lodash.merge'),\n { ENOENT } = require('errno').code;\n\n// TYPEDEFINITIONS\n\n/**\n * @typedef {{}} CustomError\n * @augments Error\n */\n\n/**\n * ApplicationErrorOptions\n * @typedef {{\n * [instancePath]: string,\n * [examplePath]: string,\n * [exampleFilePath]: string,\n * [keyword]: string,\n * [message]: string,\n * [mapFilePath]: string,\n * [params]: {\n * [path]: string,\n * [missingProperty]: string,\n * [type]: string\n * },\n * [schemaPath]: string\n * }} ApplicationErrorOptions\n */\n\n// CONSTANTS\n\nconst ErrorType = {\n jsENOENT: ENOENT.code,\n jsonPathNotFound: 'JsonPathNotFound',\n errorAndErrorsMutuallyExclusive: 'ErrorErrorsMutuallyExclusive',\n parseError: 'ParseError',\n validation: 'Validation'\n};\n\n// CLASSES\n\n/**\n * Unified application-error\n */\nclass ApplicationError {\n /**\n * Factory-function, which is able to consume validation-errors and JS-errors. If a validation error is passed, all\n * properties will be adopted.\n * @param {Error|CustomError} err Javascript-, validation- or custom-error, to create the application-error\n * from\n * @returns {ApplicationError} Unified application-error instance\n */\n static create(err) {\n const { code, message, path, cause } = err, // Certain properties of Javascript-errors\n type = code || err.type || ErrorType.validation, // If `code` is available then it's a Javascript-error\n options = { message };\n if (ErrorType.validation === type || ErrorType.errorAndErrorsMutuallyExclusive === type) {\n // For certain, created error-types, copy all properties\n merge(options, err);\n } else {\n // Copy certain properties of Javascript-error (but only if available)\n path && merge(options, { params: { path } });\n cause && merge(options, cause);\n }\n return new ApplicationError(type, options);\n }\n\n /**\n * Constructor\n * @param {string} type Type of error (see statics)\n * @param {ApplicationErrorOptions} [options] Optional properties\n */\n constructor(type, options = {}) {\n Object.assign(this, {\n type,\n ...options\n });\n }\n}\n\n// PUBLIC API\n\nmodule.exports = {\n ApplicationError,\n ErrorType\n};\n","module.exports = {\n parent: 'parent',\n parentProperty: 'parentProperty',\n path: 'path',\n pointer: 'pointer',\n value: 'value'\n};\n","/**\n * Entry point for logic that only applies to specific versions of the OpenAPI-spec\n */\n\nconst implV2 = require('./v2/index'),\n implV3 = require('./v3/index');\n\nconst REGEX__OPEN_API = /^3\\./;\n\nmodule.exports = {\n getImplementation\n};\n\n/**\n * Get the version-specific implementation for the OpenAPI-spec. Currently v2 and v3 are supported\n * @param {Object} openapiSpec OpenAPI-spec\n * @returns {Object|null}\n */\nfunction getImplementation(openapiSpec) {\n if (typeof openapiSpec.swagger === 'string') {\n return implV2;\n }\n if (openapiSpec.openapi && openapiSpec.openapi.match(REGEX__OPEN_API)) {\n return implV3;\n }\n return null;\n}\n","const { applyCallbackToAllObjectModels } = require('./common');\n\nmodule.exports = {\n setAllPropertiesRequired\n};\n\n/**\n * Sets all properties of each object to required\n * @param {Object} openApiSpec The to-be-modified schema\n * @param {Array.} [examplePaths=[]] The paths to the examples, which's content must not be modified\n */\nfunction setAllPropertiesRequired(openApiSpec, examplePaths = []) {\n applyCallbackToAllObjectModels(openApiSpec, examplePaths,\n () => {\n return (value) => {\n if (value.hasOwnProperty('properties')) {\n value.required = Object.keys(value.properties);\n }\n };\n });\n}\n","const { JSONPath: jsonPath } = require('jsonpath-plus'),\n ResultType = require('../../const/result-type');\n\nmodule.exports = {\n applyCallbackToAllObjectModels\n};\n\n/**\n * @typedef {{\n * path: String,\n * value: Object,\n * parent: Object,\n * parentProperty: String,\n * hasArrExpr: Boolean\n * }} JsonPathMatchData\n */\n\n/**\n * Callback that is applied to a JSONPath-match.\n * @callback JsonPathMatchCallback\n * @param {Object} value Value of the matched property\n * @param {String} resultType Result-type of the query\n * @param {JsonPathMatchData} data Object that contains additional data to the match\n */\n\n/**\n * Function to build a callback that is applied to a JSONPath-match.\n * @callback JsonPathMatchCallbackBuilder\n * @param {string} jsPath Path to the property that matched\n * @return {JsonPathMatchCallback} Callback that is applied to a JSONPath-match\n */\n\n/**\n * Apply the input rule to all models of type object in the input openApiSpec\n * @param {Object} openApiSpec The to-be-modified schema\n * @param {Array.} [examplePaths] The paths to the examples, which's content must not be modified\n * @param {JsonPathMatchCallbackBuilder} [matchCallbackBuilder] Function to build a callback\n * that will be called on each match\n */\nfunction applyCallbackToAllObjectModels(openApiSpec, examplePaths, matchCallbackBuilder) {\n // Find all matches\n const paths = new Set();\n _find(openApiSpec, '$..schema..')\n .forEach(match => {\n if (_isPropertiesDefinition(match)) { return; }\n paths.add(match);\n });\n // Exclude examples\n _excludeExamples(openApiSpec, paths, examplePaths);\n // Set flag\n for (const jsPath of paths) {\n const callback = matchCallbackBuilder(jsPath);\n _find(openApiSpec, jsPath, ResultType.value, (result, resultType, data) => {\n if (!_isObjectDefinition(result)) { return; }\n callback(result, resultType, data);\n });\n }\n}\n\n/**\n * Find matching elements in JSON.\n * @param {Object} json JSON to be searched\n * @param {String} path JSON-path to search\n * @param {String} [resultType=\"path\"] Result-type of the query\n * @param {JsonPathMatchCallback} [callback] Function to be called on a match\n * @returns {any} Result of the query, depending on the `resultType`\n * @private\n */\nfunction _find(json, path, resultType = ResultType.path, callback) {\n return jsonPath({\n json,\n path,\n flatten: true,\n resultType,\n callback\n });\n}\n\n/**\n * Remove JSON-paths from `paths` that are included in `examplePaths`\n * @param {Object} openApiSpec Open-API spec to search in\n * @param {Set.} paths Paths where the examples have to be removed from\n * @param {Array.} examplePaths JSON-paths of the examples\n * @private\n */\nfunction _excludeExamples(openApiSpec, paths, examplePaths) {\n examplePaths\n .forEach(examplePath => {\n _find(openApiSpec, examplePath)\n .forEach(exampleMatch => {\n for (const jsPath of paths) {\n jsPath.startsWith(exampleMatch) && paths.delete(jsPath);\n }\n });\n });\n}\n\nfunction _isPropertiesDefinition(path) {\n // Path has to end with `properties`\n if (!path.match(/\\['properties']$/)) { return; }\n // Every second consecutive `properties` actually is not a property-definition, but a property itself\n const consecutiveMatch = path.match(/(?} [examplePaths=[]] The paths to the examples, which's content must not be modified\n */\nfunction setNoAdditionalProperties(openApiSpec, examplePaths = []) {\n // Match all combiner keywords that are not preceded by a 'properties' keyword.\n // This allow to have objects that have as property name one of the combiner keywords.\n const hasJsonCombinerParentRegex\n = new RegExp('(? {\n return (schema) => {\n // Exclude schema that have a JSON combiner as parent\n if (hasJsonCombinerParentRegex.test(path)) {\n console.warn('\"additionalProperties\" flag not set '\n + `for ${path} because it has a parent with a JSON-schema combiner keyword.`);\n return;\n }\n // Exclude schema that contains a JSON combiner\n if (JSON_SCHEMA_COMBINERS.some((combiner) => schema.hasOwnProperty(combiner))) {\n console.warn('\"additionalProperties\" flag not set '\n + `for ${path} because it contains JSON-schema combiner keyword.`);\n return;\n }\n // Exclude schema that already contains additionalProperties\n if (schema.hasOwnProperty('additionalProperties')) {\n return;\n }\n schema.additionalProperties = false;\n };\n });\n}\n","/**\n * Contains validation-logic that is specific to V2 of the OpenAPI-spec\n */\n\nconst cloneDeep = require('lodash.clonedeep'),\n { setAllPropertiesRequired } = require('../service/all-properties-required'),\n { setNoAdditionalProperties } = require('../service/no-additional-properties');\n\n// CONSTANTS\n\nconst PATH__EXAMPLES = '$..examples[?(@property.match(/[\\/+]json/))]',\n PROP__SCHEMA = 'schema',\n PROP__EXAMPLES = 'examples';\n\nmodule.exports = {\n buildValidationMap,\n getJsonPathsToExamples,\n prepare\n};\n\n// IMPLEMENTATION DETAILS\n\n/**\n * Get the JSONPaths to the examples\n * @returns {Array.} JSONPaths to the examples\n */\nfunction getJsonPathsToExamples() { return [PATH__EXAMPLES]; }\n\n\n\n/**\n * Builds a map with the json-pointers to the response-schema as key and the json-pointers to the examples, as value.\n * The pointer of the schema is derived from the pointer to the example and doesn't necessarily mean\n * that the schema actually exists.\n * @param {Array.} pathsExamples Paths to the examples\n * @returns {Object.} Map with schema-pointers as key and example-pointers as value\n * @private\n */\nfunction buildValidationMap(pathsExamples) {\n return pathsExamples.reduce((validationMap, pathExample) => {\n const pathSchema = _getSchemaPointerOfExample(pathExample);\n validationMap[pathSchema] = (validationMap[pathSchema] || new Set())\n .add(pathExample);\n return validationMap;\n }, {});\n}\n\n/**\n * Pre-processes the OpenAPI-spec, for further use.\n * The passed spec won't be modified. If a modification happens, a modified copy will be returned.\n * @param {Object} openapiSpec The OpenAPI-spec as JSON-schema\n * @param {boolean} [noAdditionalProperties=false] Don't allow properties that are not defined in the schema\n * @param {boolean} [allPropertiesRequired=false] Make all properties required\n * @return {Object} The prepared OpenAPI-spec\n */\nfunction prepare(openapiSpec, { noAdditionalProperties, allPropertiesRequired } = {}) {\n const openapiSpecCopy = cloneDeep(openapiSpec);\n noAdditionalProperties && setNoAdditionalProperties(openapiSpecCopy, getJsonPathsToExamples());\n allPropertiesRequired && setAllPropertiesRequired(openapiSpecCopy, getJsonPathsToExamples());\n return openapiSpecCopy;\n}\n\n/**\n * Gets a JSON-pointer to the corresponding response-schema, based on a JSON-pointer to an example.\n * @param {String} examplePointer JSON-pointer to example\n * @returns {String} JSON-pointer to the corresponding response-schema\n * @private\n */\nfunction _getSchemaPointerOfExample(examplePointer) {\n const pathSegs = examplePointer.split('/'),\n idxExamples = pathSegs.lastIndexOf(PROP__EXAMPLES);\n pathSegs.splice(idxExamples, pathSegs.length - idxExamples, PROP__SCHEMA);\n return pathSegs.join('/');\n}\n","/**\n * Contains validation-logic that is specific to V3 of the OpenAPI-spec\n */\n\nconst cloneDeep = require('lodash.clonedeep'),\n { ApplicationError, ErrorType } = require('../../application-error'),\n { setAllPropertiesRequired } = require('../service/all-properties-required'),\n { setNoAdditionalProperties } = require('../service/no-additional-properties');\n\n// CONSTANTS\n\nconst RESPONSES = '$..responses..content[?(@property.match(/[\\/+]json/))]';\nconst REQUEST = '$..requestBody.content[?(@property.match(/[\\/+]json/))]';\nconst SINGLE_EXAMPLE = '.example';\nconst MANY_EXAMPLES = '.examples.*.value';\n\nconst PATH__EXAMPLE = `${RESPONSES}${SINGLE_EXAMPLE}`,\n PATH__EXAMPLES = `${RESPONSES}${MANY_EXAMPLES}`,\n PATH__EXAMPLE__PARAMETER = '$..parameters..example',\n PATH__EXAMPLES__PARAMETER = '$..parameters..examples.*.value',\n PATH__EXAMPLE__REQUEST_BODY = `${REQUEST}${SINGLE_EXAMPLE}`,\n PATH__EXAMPLES__REQUEST_BODY = `${REQUEST}${MANY_EXAMPLES}`,\n PROP__SCHEMA = 'schema',\n PROP__EXAMPLE = 'example',\n PROP__EXAMPLES = 'examples';\n\nconst ExampleType = {\n single: 'single',\n multi: 'multi'\n};\n\n// PUBLIC API\n\nmodule.exports = {\n buildValidationMap,\n getJsonPathsToExamples,\n prepare\n};\n\n// IMPLEMENTATION DETAILS\n\n/**\n * Get the JSONPaths to the examples\n * @returns {Array.} JSONPaths to the examples\n */\nfunction getJsonPathsToExamples() {\n return [\n PATH__EXAMPLE,\n PATH__EXAMPLES,\n PATH__EXAMPLE__PARAMETER,\n PATH__EXAMPLES__PARAMETER,\n PATH__EXAMPLE__REQUEST_BODY,\n PATH__EXAMPLES__REQUEST_BODY\n ];\n}\n\n/**\n * Builds a map with the json-pointers to the response-schema as key and the json-pointers to the examples, as value.\n * The pointer of the schema is derived from the pointer to the example and doesn't necessarily mean\n * that the schema actually exists.\n * @param {Array.} pathsExamples Paths to the examples\n * @returns {Object.} Map with schema-pointers as key and example-pointers as value\n * @private\n */\nfunction buildValidationMap(pathsExamples) {\n const exampleTypesOfSchemas = new Map();\n return pathsExamples.reduce((validationMap, pathExample) => {\n const { pathSchemaAsArray, exampleType } = _getSchemaPointerOfExample(pathExample),\n pathSchema = pathSchemaAsArray.join('/'),\n exampleTypeOfSchema = exampleTypesOfSchemas.get(pathSchema);\n if (exampleTypeOfSchema) {\n exampleTypeOfSchema !== exampleType && _throwMutuallyExclusiveError(pathSchemaAsArray);\n }\n exampleTypesOfSchemas.set(pathSchema, exampleType);\n validationMap[pathSchema] = (validationMap[pathSchema] || new Set())\n .add(pathExample);\n return validationMap;\n }, {});\n}\n\n/**\n * Pre-processes the OpenAPI-spec, for further use.\n * The passed spec won't be modified. If a modification happens, a modified copy will be returned.\n * @param {Object} openapiSpec The OpenAPI-spec as JSON-schema\n * @param {boolean} [noAdditionalProperties=false] Don't allow properties that are not defined in the schema\n * @param {boolean} [allPropertiesRequired=false] Make all properties required\n * @return {Object} The prepared OpenAPI-spec\n */\nfunction prepare(openapiSpec, { noAdditionalProperties, allPropertiesRequired } = {}) {\n const openapiSpecCopy = cloneDeep(openapiSpec);\n noAdditionalProperties && setNoAdditionalProperties(openapiSpecCopy, getJsonPathsToExamples());\n allPropertiesRequired && setAllPropertiesRequired(openapiSpecCopy, getJsonPathsToExamples());\n return openapiSpecCopy;\n}\n\n/**\n * Gets a JSON-pointer to the corresponding response-schema, based on a JSON-pointer to an example.\n *\n * It is assumed that the JSON-pointer to the example is valid and existing.\n * @param {String} examplePointer JSON-pointer to example\n * @returns {{\n * exampleType: ExampleType,\n * pathSchema: String\n * }} JSON-path to the corresponding response-schema\n * @private\n */\nfunction _getSchemaPointerOfExample(examplePointer) {\n const pathSegs = examplePointer.split('/'),\n idxExample = pathSegs.lastIndexOf(PROP__EXAMPLE),\n /** @type ExampleType */\n exampleType = idxExample > -1\n ? ExampleType.single\n : ExampleType.multi,\n idxExamples = exampleType === ExampleType.single\n ? idxExample\n : pathSegs.lastIndexOf(PROP__EXAMPLES);\n pathSegs.splice(idxExamples, pathSegs.length - idxExamples, PROP__SCHEMA);\n return {\n exampleType,\n pathSchemaAsArray: pathSegs\n };\n}\n\n\n/**\n * Checks if only `example` or `examples` is set for the schema, as they are mutually exclusive by OpenAPI-spec.\n * @param {Array.} pathSchemaAsArray JSON-path to the Schema, as JSON-path-array\n * @throws ApplicationError if both are set\n * @private\n */\nfunction _throwMutuallyExclusiveError(pathSchemaAsArray) {\n const pathContextAsArray = pathSchemaAsArray.slice(0, pathSchemaAsArray.length - 1); // Strip `schema` away\n throw ApplicationError.create({\n type: ErrorType.errorAndErrorsMutuallyExclusive,\n message: 'Properties \"error\" and \"errors\" are mutually exclusive',\n params: {\n pathContext: pathContextAsArray.join('/')\n }\n });\n}\n","/**\n * Entry-point for the validator-API\n */\n\nconst\n merge = require('lodash.merge'),\n flatten = require('lodash.flatten'),\n flatMap = require('lodash.flatmap'),\n jsonPointer = require('json-pointer'),\n fs = require('fs'),\n path = require('path'),\n glob = require('glob'),\n yaml = require('yaml'),\n { JSONPath: jsonPath } = require('jsonpath-plus'),\n refParser = require('json-schema-ref-parser'),\n { createError } = require('errno').custom,\n ResultType = require('./const/result-type'),\n { getValidatorFactory, compileValidate } = require('./validator'),\n Determiner = require('./impl'),\n { ApplicationError, ErrorType } = require('./application-error'),\n { createValidationResponse, dereferenceJsonSchema } = require('./utils');\n\n// CONSTANTS\n\nconst SYM__INTERNAL = Symbol('internal'),\n PROP__SCHEMAS_WITH_EXAMPLES = 'schemasWithExamples',\n FILE_EXTENSIONS__YAML = [\n 'yaml',\n 'yml'\n ];\n\n// STATICS\n\n/**\n * ErrorJsonPathNotFound\n * @typedef {{\n * cause: {\n * [params]: {\n * [path]: string\n * }\n * }\n * }} ErrorJsonPathNotFound\n * @augments CustomError\n */\n\n/**\n * @constructor\n * @augments CustomError\n * @returns {ErrorJsonPathNotFound}\n */\nconst ErrorJsonPathNotFound = createError(ErrorType.jsonPathNotFound);\n\n// PUBLIC API\n\nmodule.exports = {\n 'default': validateExamples,\n validateFile,\n validateExample,\n validateExamplesByMap,\n getValidatorFactory\n};\n\n// IMPLEMENTATION DETAILS\n\n// Type definitions\n\n/**\n * ValidationStatistics\n * @typedef {{\n * schemasWithExamples: number,\n * examplesTotal: number,\n * examplesWithoutSchema: number,\n * [matchingFilePathsMapping]: number\n * }} ValidationStatistics\n */\n\n/**\n * ValidationResponse\n * @typedef {{\n * valid: boolean,\n * statistics: ValidationStatistics,\n * errors: Array.\n * }} ValidationResponse\n */\n\n/**\n * @callback ValidationHandler\n * @param {ValidationStatistics} statistics\n * @returns {Array.}\n */\n\n// Public\n\n/**\n * Validates OpenAPI-spec with embedded examples.\n * @param {Object} openapiSpec OpenAPI-spec\n * @param {boolean} [noAdditionalProperties=false] Don't allow properties that are not defined in the schema\n * @param {boolean} [allPropertiesRequired=false] Make all properties required\n * @param {Array.} [ignoreFormats] List of datatype formats that shall be ignored (to prevent\n * \"unsupported format\" errors). If an Array with only one string is\n * provided where the formats are separated with `\\n`, the entries\n * will be expanded to a new array containing all entries.\n * @param {Function} [specPostprocessor] Provides implementation of spec postprocessor\n * @param {Function} [validatorFactory] Validator factory provider\n * @returns {ValidationResponse}\n */\nasync function validateExamples(openapiSpec, { noAdditionalProperties, ignoreFormats, allPropertiesRequired,\n specPostprocessor = (spec) => spec,\n validatorFactory = (spec, { ignoreFormats }) => _initValidatorFactory(spec, { ignoreFormats })\n} = {}) {\n const impl = Determiner.getImplementation(openapiSpec);\n openapiSpec = await refParser.dereference(openapiSpec);\n openapiSpec = impl.prepare(openapiSpec, { noAdditionalProperties, allPropertiesRequired });\n if (typeof specPostprocessor === 'function') {\n openapiSpec = specPostprocessor(openapiSpec);\n }\n let pathsExamples = impl.getJsonPathsToExamples()\n .reduce((res, pathToExamples) => {\n return res.concat(_pathToPointer(openapiSpec, pathToExamples));\n }, [])\n .map(impl.escapeExampleName);\n const createValidator = validatorFactory(openapiSpec, { ignoreFormats });\n return _validateExamplesPaths({ impl, createValidator }, pathsExamples, openapiSpec);\n}\n\n/**\n * Validates OpenAPI-spec with embedded examples.\n * @param {string} filePath File-path to the OpenAPI-spec\n * @param {boolean} [noAdditionalProperties=false] Don't allow properties that are not defined in the schema\n * @param {boolean} [allPropertiesRequired=false] Make all properties required\n * @param {Array.} [ignoreFormats] List of datatype formats that shall be ignored (to prevent\n * \"unsupported format\" errors). If an Array with only one string is\n * provided where the formats are separated with `\\n`, the entries\n * will be expanded to a new array containing all entries.\n * @returns {ValidationResponse}\n */\nasync function validateFile(filePath, { noAdditionalProperties, ignoreFormats, allPropertiesRequired } = {}) {\n let openapiSpec = null;\n try {\n openapiSpec = await _parseSpec(filePath);\n } catch (err) {\n return createValidationResponse({ errors: [ApplicationError.create(err)] });\n }\n return validateExamples(openapiSpec, { noAdditionalProperties, ignoreFormats, allPropertiesRequired });\n}\n\n/**\n * Validates examples by mapping-files.\n * @param {string} filePathSchema File-path to the OpenAPI-spec\n * @param {string} globMapExternalExamples File-path (globs are supported) to the mapping-file containing JSON-\n * paths to schemas as key and a single file-path or Array of file-paths\n * to external examples\n * @param {boolean} [cwdToMappingFile=false] Change working directory for resolving the example-paths (relative to\n * the mapping-file)\n * @param {boolean} [noAdditionalProperties=false] Don't allow properties that are not defined in the schema\n * @param {boolean} [allPropertiesRequired=false] Make all properties required\n * @param {Array.} [ignoreFormats] List of datatype formats that shall be ignored (to prevent\n * \"unsupported format\" errors). If an Array with only one string is\n * provided where the formats are separated with `\\n`, the entries\n * will be expanded to a new array containing all entries.\n * @returns {ValidationResponse}\n */\nasync function validateExamplesByMap(filePathSchema, globMapExternalExamples,\n { cwdToMappingFile, noAdditionalProperties, ignoreFormats, allPropertiesRequired } = {}\n) {\n let matchingFilePathsMapping = 0;\n const filePathsMaps = glob.sync(\n globMapExternalExamples,\n // Using `nonull`-option to explicitly create an app-error if there's no match for `globMapExternalExamples`\n { nonull: true }\n );\n let responses = [];\n // for..of here, to support sequential execution of async calls. This is required, since dereferencing the\n // `openapiSpec` is not concurrency-safe\n for (const filePathMapExternalExamples of filePathsMaps) {\n let mapExternalExamples = null,\n openapiSpec = null;\n try {\n mapExternalExamples = JSON.parse(fs.readFileSync(filePathMapExternalExamples, 'utf-8'));\n openapiSpec = await _parseSpec(filePathSchema);\n openapiSpec = Determiner.getImplementation(openapiSpec)\n .prepare(openapiSpec, { noAdditionalProperties, allPropertiesRequired });\n } catch (err) {\n responses.push(createValidationResponse({ errors: [ApplicationError.create(err)] }));\n continue;\n }\n // Not using `glob`'s response-length, because it is `1` if there's no match for `globMapExternalExamples`.\n // Instead, increment on every match\n matchingFilePathsMapping++;\n responses.push(\n _validate(\n statistics => {\n return _handleExamplesByMapValidation(\n openapiSpec, mapExternalExamples, statistics, {\n cwdToMappingFile,\n dirPathMapExternalExamples: path.dirname(filePathMapExternalExamples),\n ignoreFormats\n }\n ).map(\n (/** @type ApplicationError */ error) => Object.assign(error, {\n mapFilePath: path.normalize(filePathMapExternalExamples)\n })\n );\n }\n )\n );\n }\n return merge(\n responses.reduce((res, response) => {\n if (!res) {\n return response;\n }\n return _mergeValidationResponses(res, response);\n }, null),\n { statistics: { matchingFilePathsMapping } }\n );\n}\n\n/**\n * Validates a single external example.\n * @param {String} filePathSchema File-path to the OpenAPI-spec\n * @param {String} pathSchema JSON-path to the schema\n * @param {String} filePathExample File-path to the external example-file\n * @param {boolean} [noAdditionalProperties=false] Don't allow properties that are not described in the schema\n * @param {boolean} [allPropertiesRequired=false] Make all properties required\n * @param {Array.} [ignoreFormats] List of datatype formats that shall be ignored (to prevent\n * \"unsupported format\" errors). If an Array with only one string is\n * provided where the formats are separated with `\\n`, the entries\n * will be expanded to a new array containing all entries.\n * @returns {ValidationResponse}\n */\nasync function validateExample(filePathSchema, pathSchema, filePathExample, {\n noAdditionalProperties,\n ignoreFormats,\n allPropertiesRequired\n} = {}) {\n let example = null,\n schema = null,\n openapiSpec = null;\n try {\n example = JSON.parse(fs.readFileSync(filePathExample, 'utf-8'));\n openapiSpec = await _parseSpec(filePathSchema);\n openapiSpec = Determiner.getImplementation(openapiSpec)\n .prepare(openapiSpec, { noAdditionalProperties, allPropertiesRequired });\n schema = _extractSchema(_getSchmaPointer(pathSchema, openapiSpec), openapiSpec);\n } catch (err) {\n return createValidationResponse({ errors: [ApplicationError.create(err)] });\n }\n return _validate(\n statistics => _validateExample({\n createValidator: _initValidatorFactory(openapiSpec, { ignoreFormats }),\n schema,\n example,\n statistics,\n filePathExample\n })\n );\n}\n\n// Private\n\n/**\n * Parses the OpenAPI-spec (supports JSON and YAML)\n * @param {String} filePath File-path to the OpenAPI-spec\n * @returns {object} Parsed OpenAPI-spec\n * @private\n */\nasync function _parseSpec(filePath) {\n const isYaml = _isFileTypeYaml(filePath);\n let jsonSchema;\n\n if (isYaml) {\n try {\n jsonSchema = yaml.parse(fs.readFileSync(filePath, 'utf-8'));\n } catch (e) {\n const { name, message } = e;\n throw new ApplicationError(ErrorType.parseError, { message: `${name}: ${message}` });\n }\n } else {\n jsonSchema = JSON.parse(fs.readFileSync(filePath, 'utf-8'));\n }\n\n return await dereferenceJsonSchema(filePath, jsonSchema);\n}\n\n/**\n * Determines whether the filePath is pointing to a YAML-file\n * @param {String} filePath File-path to the OpenAPI-spec\n * @returns {boolean} `true`, if the file is a YAML-file\n * @private\n */\nfunction _isFileTypeYaml(filePath) {\n const extension = filePath.split('.').pop();\n return FILE_EXTENSIONS__YAML.includes(extension);\n}\n\n/**\n * Top-level validator. Prepares common values, required for the validation, then calles the validator and prepares\n * the result for the output.\n * @param {ValidationHandler} validationHandler The handler which performs the validation. It will receive the\n * statistics-object as argument and has to return an Array of\n * errors (or an empty Array, when all examples are valid)\n * @returns {ValidationResponse}\n * @private\n */\nfunction _validate(validationHandler) {\n const statistics = _initStatistics(),\n errors = validationHandler(statistics);\n return createValidationResponse({ errors, statistics });\n}\n\n/**\n * Validates examples by a mapping-file.\n * @param {Object} openapiSpec OpenAPI-spec\n * @param {Object} mapExternalExamples Mapping-file containing JSON-paths to schemas as\n * key and a single file-path or Array of file-paths\n * to external examples\n * @param {ValidationStatistics} statistics Validation-statistics\n * @param {boolean} [cwdToMappingFile=false] Change working directory for resolving the example-\n * paths (relative to the mapping-file)\n * @param {string} [dirPathMapExternalExamples] The directory-path of the mapping-file\n * @param {Array.} [ignoreFormats] List of datatype formats that shall be ignored (to prevent\n * \"unsupported format\" errors). If an Array with only one string is\n * provided where the formats are separated with `\\n`, the entries\n * will be expanded to a new array containing all entries.\n * @returns {Array.}\n * @private\n */\nfunction _handleExamplesByMapValidation(openapiSpec, mapExternalExamples, statistics,\n { cwdToMappingFile = false, dirPathMapExternalExamples, ignoreFormats }\n) {\n return flatMap(Object.entries(mapExternalExamples), ([pathSchema, filePathsExample]) => {\n let schema = null;\n try {\n schema = _extractSchema(_getSchmaPointer(pathSchema, openapiSpec), openapiSpec);\n } catch (/** @type ErrorJsonPathNotFound */ err) {\n // If the schema can't be found, don't even attempt to process the examples\n return ApplicationError.create(err);\n }\n return flatMap(\n flatten([filePathsExample]),\n filePathExample => {\n let examples = [];\n try {\n const resolvedFilePathExample = cwdToMappingFile\n ? path.join(dirPathMapExternalExamples, filePathExample)\n : filePathExample;\n const globResolvedFilePathExample = glob.sync(resolvedFilePathExample);\n if (globResolvedFilePathExample.length === 0) {\n return [ApplicationError.create({\n type: ErrorType.jsENOENT,\n message: `No such file or directory: '${resolvedFilePathExample}'`,\n path: resolvedFilePathExample\n })];\n }\n for (const filePathExample of globResolvedFilePathExample) {\n examples.push({\n path: path.normalize(filePathExample),\n content: JSON.parse(fs.readFileSync(filePathExample, 'utf-8'))\n });\n }\n } catch (err) {\n return [ApplicationError.create(err)];\n }\n return flatMap(examples, example => _validateExample({\n createValidator: _initValidatorFactory(openapiSpec, { ignoreFormats }),\n schema,\n example: example.content,\n statistics,\n filePathExample: example.path\n }));\n }\n );\n });\n}\n\n\n/**\n * Merges two `ValidationResponses` together and returns the merged result. The passed `ValidationResponse`s won't be\n * modified.\n * @param {ValidationResponse} response1\n * @param {ValidationResponse} response2\n * @returns {ValidationResponse}\n * @private\n */\nfunction _mergeValidationResponses(response1, response2) {\n return createValidationResponse({\n errors: response1.errors.concat(response2.errors),\n statistics: Object.entries(response1.statistics)\n .reduce((res, [key, val]) => {\n if (PROP__SCHEMAS_WITH_EXAMPLES === key) {\n [\n response1,\n response2\n ].forEach(response => {\n const schemasWithExample = response.statistics[SYM__INTERNAL][PROP__SCHEMAS_WITH_EXAMPLES]\n .values();\n for (let schema of schemasWithExample) {\n res[SYM__INTERNAL][PROP__SCHEMAS_WITH_EXAMPLES].add(schema);\n }\n });\n return res;\n }\n res[key] = val + response2.statistics[key];\n return res;\n }, _initStatistics())\n });\n}\n\n/**\n * Extract JSON-pointer(s) for specific path from a OpenAPI-spec\n * @param {String} path JSON-path in the OpenAPI-Spec\n * @param {Object} openapiSpec OpenAPI-spec\n * @returns {Array.} JSON-pointers to matching elements\n * @private\n */\nfunction _pathToPointer(path, openapiSpec) {\n return jsonPath({\n json: openapiSpec,\n path: path,\n resultType: ResultType.pointer\n });\n}\n/**\n * Extract JSON-pointer(s) for specific path from a OpenAPI-spec\n * @param {String} path JSON-path in the OpenAPI-Spec\n * @param {Object} openapiSpec OpenAPI-spec\n * @returns {String} JSON-pointer to schema or throws error\n * @private\n */\nfunction _getSchmaPointer(pathSchema, openapiSpec) {\n const schemaPointers = _pathToPointer(pathSchema, openapiSpec);\n if (schemaPointers.length === 0) {\n _pathToSchemaNotFoundError(pathSchema);\n }\n if (schemaPointers.length > 1) {\n return [ApplicationError.create({\n type: ErrorType.jsonPathNotFound,\n message: `Path to schema cannot identify unique schema: '${pathSchema}'`,\n path: pathSchema\n })];\n }\n return schemaPointers[0];\n}\n\n/**\n * Validates examples at the given paths in the OpenAPI-spec.\n * @param {Object} impl Spec-dependant validator\n * @param {Function} createValidator Validator factory\n * @param {Array.} pathsExamples JSON-paths to examples\n * @param {Object} openapiSpec OpenAPI-spec\n * @returns {ValidationResponse}\n * @private\n */\nfunction _validateExamplesPaths({ impl, createValidator }, pathsExamples, openapiSpec) {\n const statistics = _initStatistics(),\n validationResult = {\n valid: true,\n statistics,\n errors: []\n };\n let validationMap;\n try {\n // Create mapping between JSON-schemas and examples\n validationMap = impl.buildValidationMap(pathsExamples);\n } catch (error) {\n // Throw unexpected errors\n if (!(error instanceof ApplicationError)) {\n throw error;\n }\n // Add known errors and stop\n validationResult.valid = false;\n validationResult.errors.push(error);\n return validationResult;\n }\n // Start validation\n const schemaPointers = Object.keys(validationMap);\n schemaPointers.forEach(schemaPointer => {\n _validateSchema({\n openapiSpec, createValidator, schemaPointer, validationMap, statistics,\n validationResult\n });\n });\n return validationResult;\n}\n\n/**\n * Validates a single schema.\n * @param {Object} openapiSpec OpenAPI-spec\n * @param {ajv} createValidator Factory, to create JSON-schema validator\n * @param {string} schemaPointer JSON-pointer to schema (for request- or response-property)\n * @param {Object.} validationMap Map with schema-pointers as key and example-pointers as value\n * @param {Object} statistics Object to contain statistics metrics\n * @param {Object} validationResult Container, for the validation-results\n * @private\n */\nfunction _validateSchema({\n openapiSpec, createValidator, schemaPointer, validationMap, statistics,\n validationResult\n}) {\n const errors = validationResult.errors;\n validationMap[schemaPointer].forEach(pathExample => {\n const example = _getByPointer(pathExample, openapiSpec),\n // Examples with missing schemas may occur and those are considered valid\n schema = _extractSchema(schemaPointer, openapiSpec, true);\n const curErrors = _validateExample({\n createValidator,\n schema,\n example,\n statistics\n }).map(error => {\n error.examplePath = pathExample;\n return error;\n });\n if (!curErrors.length) {\n return;\n }\n validationResult.valid = false;\n errors.splice(errors.length - 1, 0, ...curErrors);\n });\n}\n\n/**\n * Creates a container-object for the validation statistics.\n * @returns {ValidationStatistics}\n * @private\n */\nfunction _initStatistics() {\n const statistics = {\n [SYM__INTERNAL]: {\n [PROP__SCHEMAS_WITH_EXAMPLES]: new Set()\n },\n examplesTotal: 0,\n examplesWithoutSchema: 0\n };\n Object.defineProperty(statistics, PROP__SCHEMAS_WITH_EXAMPLES, {\n enumerable: true,\n get: () => statistics[SYM__INTERNAL][PROP__SCHEMAS_WITH_EXAMPLES].size\n });\n return statistics;\n}\n\n/**\n * Extract object by the given JSON-pointer\n * @param {String} pointer JSON-pointer\n * @param {Object} json JSON to extract the object(s) from\n * @returns {Object} Extracted object\n */\nfunction _getByPointer(pointer, json) {\n try {\n return jsonPointer.get(json, pointer);\n } catch (_) {\n return undefined;\n }\n}\n\n/**\n * Validates example against the schema. The precondition for this function to work is that the example exists at the\n * given path.\n * `pathExample` and `filePathExample` are exclusively mandatory.\n * itself\n * @param {Function} createValidator Factory, to create JSON-schema validator\n * @param {Object} schema JSON-schema\n * @param {Object} example Example to validate\n * @param {Object} statistics Object to contain statistics metrics\n * @param {String} [filePathExample] File-path to the example file\n * @returns {Array.} Array with errors. Empty array, if examples are valid\n * @private\n */\nfunction _validateExample({ createValidator, schema, example, statistics, filePathExample }) {\n const\n errors = [];\n statistics.examplesTotal++;\n // No schema, no validation (Examples without schema are considered valid)\n if (!schema) {\n statistics.examplesWithoutSchema++;\n return errors;\n }\n statistics[SYM__INTERNAL][PROP__SCHEMAS_WITH_EXAMPLES].add(schema);\n const validate = compileValidate(createValidator(), schema);\n if (validate(example)) {\n return errors;\n }\n return errors.concat(...validate.errors.map(ApplicationError.create))\n .map(error => {\n if (!filePathExample) {\n return error;\n }\n error.exampleFilePath = filePathExample;\n return error;\n });\n}\n\n/**\n * Create a new instance of a JSON schema validator\n * @returns {ajv}\n * @private\n */\nfunction _initValidatorFactory(specSchema, { ignoreFormats }) {\n return getValidatorFactory(specSchema, {\n schemaId: 'auto',\n discriminator: true,\n strict: false,\n allErrors: true,\n formats: ignoreFormats && ignoreFormats.reduce((result, entry) => {\n result[entry] = () => true;\n return result;\n }, {})\n });\n}\n\n/**\n * Extracts the schema in the OpenAPI-spec at the given JSON-pointer.\n * @param {string} schemaPointer JSON-pointer to the schema\n * @param {Object} openapiSpec OpenAPI-spec\n * @param {boolean} [suppressErrorIfNotFound=false] Don't throw `ErrorJsonPathNotFound` if the response does not\n * exist at the given JSON-pointer\n * @returns {Object|Array.|undefined} Matching schema(s)\n * @throws {ErrorJsonPathNotFound} Thrown, when there is no schema at the given path and\n * `suppressErrorIfNotFound` is false\n * @private\n */\nfunction _extractSchema(schemaPointer, openapiSpec, suppressErrorIfNotFound = false) {\n const schema = _getByPointer(schemaPointer, openapiSpec);\n if (!suppressErrorIfNotFound && !schema) {\n _pathToSchemaNotFoundError(schemaPointer);\n }\n return schema;\n}\n\nfunction _pathToSchemaNotFoundError(schemaPointer) {\n throw new ErrorJsonPathNotFound(`Path to schema can't be found: '${schemaPointer}'`, {\n params: {\n path: schemaPointer\n }\n });\n}\n","const path = require('path'),\n refParser = require('json-schema-ref-parser');\n\nmodule.exports = {\n createValidationResponse,\n dereferenceJsonSchema\n};\n\n/**\n * Creates a unified response for the validation-result\n * @param {Array.} errors\n * @param {ValidationStatistics} statistics\n * @returns {ValidationResponse}\n * @private\n */\nfunction createValidationResponse({ errors, statistics = {} }) {\n return {\n valid: !errors.length,\n statistics,\n errors\n };\n}\n\n/**\n * Includes all referenced, external schemas (by the keyword `$ref`) into the schema\n *\n * CAUTION: This function is not concurrency-safe !!\n * This function changes the working dir and sets it back. This may become an concurrency issue when there are\n * other tasks running that rely on the working dir while this function waits for the asynchronous task of\n * dereferencing to complete.\n *\n * @param {String} pathToSchema File-path to the schema\n * @param {Object} jsonSchema Schema with potential externally referenced schemas\n * @returns {Promise} Dereferenced schema\n */\nasync function dereferenceJsonSchema(pathToSchema, jsonSchema) {\n const currentWorkingDir = process.cwd();\n // Change the working dir to the schema-path, to make sure that relative paths can be resolved\n process.chdir(path.dirname(pathToSchema));\n const dereferencedSchema = await refParser.dereference(jsonSchema);\n // Restore original working dir\n process.chdir(currentWorkingDir);\n return dereferencedSchema;\n}\n","/**\n * Wrapper for the JSONSchema-validator\n */\n\nconst { JSONPath: jsonPath } = require('jsonpath-plus'),\n JsonPointer = require('json-pointer'),\n Ajv = require('ajv-draft-04'),\n addFormats = require('ajv-formats');\n\nconst PROP__ID = '$id',\n JSON_PATH__REFS = '$..\\$ref',\n ID__SPEC_SCHEMA = 'https://www.npmjs.com/package/openapi-examples-validator/defs.json',\n ID__RESPONSE_SCHEMA = 'https://www.npmjs.com/package/openapi-examples-validator/schema.json';\n\nmodule.exports = {\n getValidatorFactory,\n compileValidate\n};\n\n/**\n * Get a factory-function to create a prepared validator-instance\n * @param {Object} specSchema OpenAPI-spec of which potential local references will be extracted\n * @param {Object} [options] Options for the validator\n * @returns {function(): (ajv | ajv.Ajv)}\n */\nfunction getValidatorFactory(specSchema, options, { provider = (opt) => new Ajv(opt) }) {\n const preparedSpecSchema = _createReferenceSchema(specSchema);\n return () => {\n const validator = provider(options);\n addFormats(validator);\n\n validator.addSchema(preparedSpecSchema);\n\n return validator;\n };\n}\n\n/**\n * Compiles the validator-function.\n * @param {ajv | ajv.Ajv} validator Validator-instance\n * @param {Object} responseSchema The response-schema, against the examples will be validated\n * @returns {ajv.ValidateFunction}\n */\nfunction compileValidate(validator, responseSchema) {\n const preparedResponseSchema = _prepareResponseSchema(responseSchema, ID__RESPONSE_SCHEMA);\n _replaceRefsToPreparedSpecSchema(preparedResponseSchema);\n\n let result;\n try {\n result = validator.compile(preparedResponseSchema);\n } catch (e) {\n result = () => {};\n result.errors = [e];\n }\n return result;\n}\n\n/**\n * Prepares the schema, to be used with internal-references\n * @param {Object} specSchema The schema to be prebared\n * @param {String} idSchema The unique ID for the schema\n * @returns {Object}\n * @private\n */\nfunction _prepareResponseSchema(specSchema, idSchema) {\n const preparedSchema = Object.assign({}, specSchema);\n preparedSchema[PROP__ID] = idSchema;\n return preparedSchema;\n}\n\n/**\n * Replaces all internal references to the schema, with the extracted references, based on the origin OpenAPI-spec\n * @param {Object} schema The schema, containing references have to be replaced\n * @private\n */\nfunction _replaceRefsToPreparedSpecSchema(schema) {\n jsonPath({\n path: JSON_PATH__REFS,\n json: schema,\n callback(value, type, payload) {\n if (!value.startsWith('#')) { return; }\n payload.parent[payload.parentProperty] = `${ ID__SPEC_SCHEMA }${ value }`;\n }\n });\n}\n\n/**\n * Extracts all references and returns a new schema, containing only those.\n * @param {Object} specSchema Schema, which references shall be extracted\n * @returns {Object}\n * @private\n */\nfunction _createReferenceSchema(specSchema) {\n const refSchema = {\n [PROP__ID]: ID__SPEC_SCHEMA\n };\n jsonPath({\n path: JSON_PATH__REFS,\n json: specSchema,\n callback(value) {\n if (!value.startsWith('#')) { return; }\n const pointer = value.substring(1),\n definition = JsonPointer.get(specSchema, pointer);\n JsonPointer.set(refSchema, pointer, definition);\n }\n });\n return refSchema;\n}\n","module.exports = require(\"ajv-draft-04\");","module.exports = require(\"ajv-formats\");","module.exports = require(\"errno\");","module.exports = require(\"glob\");","module.exports = require(\"json-pointer\");","module.exports = require(\"json-schema-ref-parser\");","module.exports = require(\"jsonpath-plus\");","module.exports = require(\"lodash.clonedeep\");","module.exports = require(\"lodash.flatmap\");","module.exports = require(\"lodash.flatten\");","module.exports = require(\"lodash.merge\");","module.exports = require(\"yaml\");","module.exports = require(\"fs\");","module.exports = require(\"path\");","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","// startup\n// Load entry module and return exports\n// This entry module is referenced by other modules so it can't be inlined\nvar __webpack_exports__ = __webpack_require__(579);\n"],"names":["merge","require","ENOENT","ErrorType","jsENOENT","code","jsonPathNotFound","errorAndErrorsMutuallyExclusive","parseError","validation","ApplicationError","static","err","message","path","cause","type","options","params","constructor","Object","assign","this","module","exports","parent","parentProperty","pointer","value","implV2","implV3","REGEX__OPEN_API","getImplementation","openapiSpec","swagger","openapi","match","applyCallbackToAllObjectModels","setAllPropertiesRequired","openApiSpec","examplePaths","hasOwnProperty","required","keys","properties","JSONPath","jsonPath","ResultType","_find","json","resultType","callback","flatten","matchCallbackBuilder","paths","Set","forEach","consecutiveMatch","length","_isPropertiesDefinition","add","examplePath","exampleMatch","jsPath","startsWith","delete","_excludeExamples","result","data","entity","setNoAdditionalProperties","hasJsonCombinerParentRegex","RegExp","JSON_SCHEMA_COMBINERS","join","schema","test","console","warn","some","combiner","additionalProperties","cloneDeep","getJsonPathsToExamples","buildValidationMap","pathsExamples","reduce","validationMap","pathExample","pathSchema","examplePointer","pathSegs","split","idxExamples","lastIndexOf","splice","_getSchemaPointerOfExample","prepare","noAdditionalProperties","allPropertiesRequired","openapiSpecCopy","RESPONSES","REQUEST","SINGLE_EXAMPLE","MANY_EXAMPLES","PATH__EXAMPLE","PATH__EXAMPLES","PATH__EXAMPLE__REQUEST_BODY","PATH__EXAMPLES__REQUEST_BODY","ExampleType","exampleTypesOfSchemas","Map","pathSchemaAsArray","exampleType","idxExample","exampleTypeOfSchema","get","pathContextAsArray","slice","create","pathContext","_throwMutuallyExclusiveError","set","flatMap","jsonPointer","fs","glob","yaml","refParser","createError","getValidatorFactory","compileValidate","Determiner","createValidationResponse","dereferenceJsonSchema","SYM__INTERNAL","Symbol","PROP__SCHEMAS_WITH_EXAMPLES","FILE_EXTENSIONS__YAML","ErrorJsonPathNotFound","async","validateExamples","ignoreFormats","specPostprocessor","spec","validatorFactory","_initValidatorFactory","impl","dereference","res","pathToExamples","concat","_pathToPointer","map","escapeExampleName","createValidator","statistics","_initStatistics","validationResult","valid","errors","error","push","schemaPointer","example","_getByPointer","_extractSchema","curErrors","_validateExample","_validateSchema","_validateExamplesPaths","_parseSpec","filePath","isYaml","extension","pop","includes","_isFileTypeYaml","jsonSchema","parse","readFileSync","e","name","JSON","_validate","validationHandler","_handleExamplesByMapValidation","mapExternalExamples","cwdToMappingFile","dirPathMapExternalExamples","entries","filePathsExample","_getSchmaPointer","filePathExample","examples","resolvedFilePathExample","globResolvedFilePathExample","sync","normalize","content","schemaPointers","_pathToSchemaNotFoundError","examplesTotal","examplesWithoutSchema","defineProperty","enumerable","size","_","validate","exampleFilePath","specSchema","schemaId","discriminator","strict","allErrors","formats","entry","suppressErrorIfNotFound","validateFile","validateExample","filePathSchema","validateExamplesByMap","globMapExternalExamples","matchingFilePathsMapping","filePathsMaps","nonull","responses","filePathMapExternalExamples","dirname","mapFilePath","response","response2","response1","key","val","schemasWithExample","values","pathToSchema","currentWorkingDir","process","cwd","chdir","dereferencedSchema","JsonPointer","Ajv","addFormats","JSON_PATH__REFS","ID__SPEC_SCHEMA","provider","opt","preparedSpecSchema","refSchema","substring","definition","_createReferenceSchema","validator","addSchema","responseSchema","preparedResponseSchema","idSchema","preparedSchema","_prepareResponseSchema","payload","compile","__webpack_module_cache__","__webpack_exports__","__webpack_require__","moduleId","cachedModule","undefined","__webpack_modules__"],"sourceRoot":""} \ No newline at end of file diff --git a/src/index.js b/src/index.js index e51bad3..f16bcc5 100644 --- a/src/index.js +++ b/src/index.js @@ -56,7 +56,8 @@ module.exports = { 'default': validateExamples, validateFile, validateExample, - validateExamplesByMap + validateExamplesByMap, + getValidatorFactory }; // IMPLEMENTATION DETAILS @@ -99,17 +100,27 @@ module.exports = { * "unsupported format" errors). If an Array with only one string is * provided where the formats are separated with `\n`, the entries * will be expanded to a new array containing all entries. + * @param {Function} [specPostprocessor] Provides implementation of spec postprocessor + * @param {Function} [validatorFactory] Validator factory provider * @returns {ValidationResponse} */ -async function validateExamples(openapiSpec, { noAdditionalProperties, ignoreFormats, allPropertiesRequired } = {}) { +async function validateExamples(openapiSpec, { noAdditionalProperties, ignoreFormats, allPropertiesRequired, + specPostprocessor = (spec) => spec, + validatorFactory = (spec, { ignoreFormats }) => _initValidatorFactory(spec, { ignoreFormats }) +} = {}) { const impl = Determiner.getImplementation(openapiSpec); openapiSpec = await refParser.dereference(openapiSpec); openapiSpec = impl.prepare(openapiSpec, { noAdditionalProperties, allPropertiesRequired }); + if (typeof specPostprocessor === 'function') { + openapiSpec = specPostprocessor(openapiSpec); + } let pathsExamples = impl.getJsonPathsToExamples() .reduce((res, pathToExamples) => { - return res.concat(_pathToPointer(pathToExamples, openapiSpec)); - }, []); - return _validateExamplesPaths({ impl }, pathsExamples, openapiSpec, { ignoreFormats }); + return res.concat(_pathToPointer(openapiSpec, pathToExamples)); + }, []) + .map(impl.escapeExampleName); + const createValidator = validatorFactory(openapiSpec, { ignoreFormats }); + return _validateExamplesPaths({ impl, createValidator }, pathsExamples, openapiSpec); } /** @@ -435,23 +446,19 @@ function _getSchmaPointer(pathSchema, openapiSpec) { /** * Validates examples at the given paths in the OpenAPI-spec. * @param {Object} impl Spec-dependant validator + * @param {Function} createValidator Validator factory * @param {Array.} pathsExamples JSON-paths to examples * @param {Object} openapiSpec OpenAPI-spec - * @param {Array.} [ignoreFormats] List of datatype formats that shall be ignored (to prevent - * "unsupported format" errors). If an Array with only one string is - * provided where the formats are separated with `\n`, the entries - * will be expanded to a new array containing all entries. * @returns {ValidationResponse} * @private */ -function _validateExamplesPaths({ impl }, pathsExamples, openapiSpec, { ignoreFormats }) { +function _validateExamplesPaths({ impl, createValidator }, pathsExamples, openapiSpec) { const statistics = _initStatistics(), validationResult = { valid: true, statistics, errors: [] - }, - createValidator = _initValidatorFactory(openapiSpec, { ignoreFormats }); + }; let validationMap; try { // Create mapping between JSON-schemas and examples diff --git a/src/validator.js b/src/validator.js index a42c7a7..5482714 100644 --- a/src/validator.js +++ b/src/validator.js @@ -23,10 +23,10 @@ module.exports = { * @param {Object} [options] Options for the validator * @returns {function(): (ajv | ajv.Ajv)} */ -function getValidatorFactory(specSchema, options) { +function getValidatorFactory(specSchema, options, { provider = (opt) => new Ajv(opt) }) { const preparedSpecSchema = _createReferenceSchema(specSchema); return () => { - const validator = new Ajv(options); + const validator = provider(options); addFormats(validator); validator.addSchema(preparedSpecSchema); From 1efdba76c24fcf5a7091c1ce790f64f12a8a4d75 Mon Sep 17 00:00:00 2001 From: Bartosz Michalik Date: Wed, 4 Oct 2023 11:38:37 +0200 Subject: [PATCH 2/6] enabling extensions for all public apis --- src/index.js | 82 +++++++--- src/validator.js | 7 +- .../v3/custom-postprocessing/readOnly.json | 95 +++++++++++ test/specs/extensions.js | 32 ++++ test/specs/index-custom-ajv.js | 152 ++++++++++++++++++ 5 files changed, 340 insertions(+), 28 deletions(-) create mode 100644 test/data/v3/custom-postprocessing/readOnly.json create mode 100644 test/specs/extensions.js create mode 100644 test/specs/index-custom-ajv.js diff --git a/src/index.js b/src/index.js index f16bcc5..03ab862 100644 --- a/src/index.js +++ b/src/index.js @@ -106,20 +106,18 @@ module.exports = { */ async function validateExamples(openapiSpec, { noAdditionalProperties, ignoreFormats, allPropertiesRequired, specPostprocessor = (spec) => spec, - validatorFactory = (spec, { ignoreFormats }) => _initValidatorFactory(spec, { ignoreFormats }) + validatorFactory = (spec, ignoreFormats) => _initValidatorFactory(spec, { ignoreFormats }) } = {}) { const impl = Determiner.getImplementation(openapiSpec); openapiSpec = await refParser.dereference(openapiSpec); openapiSpec = impl.prepare(openapiSpec, { noAdditionalProperties, allPropertiesRequired }); - if (typeof specPostprocessor === 'function') { - openapiSpec = specPostprocessor(openapiSpec); - } + openapiSpec = _postprocess(openapiSpec, specPostprocessor); let pathsExamples = impl.getJsonPathsToExamples() .reduce((res, pathToExamples) => { return res.concat(_pathToPointer(openapiSpec, pathToExamples)); }, []) .map(impl.escapeExampleName); - const createValidator = validatorFactory(openapiSpec, { ignoreFormats }); + const createValidator = validatorFactory(openapiSpec, ignoreFormats); return _validateExamplesPaths({ impl, createValidator }, pathsExamples, openapiSpec); } @@ -132,16 +130,24 @@ async function validateExamples(openapiSpec, { noAdditionalProperties, ignoreFor * "unsupported format" errors). If an Array with only one string is * provided where the formats are separated with `\n`, the entries * will be expanded to a new array containing all entries. + * @param {Function} [specPostprocessor] Provides implementation of spec postprocessor + * @param {Function} [validatorFactory] Validator factory provider * @returns {ValidationResponse} */ -async function validateFile(filePath, { noAdditionalProperties, ignoreFormats, allPropertiesRequired } = {}) { +async function validateFile(filePath, { noAdditionalProperties, ignoreFormats, allPropertiesRequired, + specPostprocessor = (spec) => spec, + validatorFactory = (spec, ignoreFormats) => _initValidatorFactory(spec, { ignoreFormats }) +} = {}) { let openapiSpec = null; try { openapiSpec = await _parseSpec(filePath); } catch (err) { return createValidationResponse({ errors: [ApplicationError.create(err)] }); } - return validateExamples(openapiSpec, { noAdditionalProperties, ignoreFormats, allPropertiesRequired }); + return validateExamples(openapiSpec, { + noAdditionalProperties, ignoreFormats, allPropertiesRequired, + specPostprocessor, validatorFactory + }); } /** @@ -158,11 +164,15 @@ async function validateFile(filePath, { noAdditionalProperties, ignoreFormats, a * "unsupported format" errors). If an Array with only one string is * provided where the formats are separated with `\n`, the entries * will be expanded to a new array containing all entries. + * @param {Function} [specPostprocessor] Provides implementation of spec postprocessor + * @param {Function} [validatorFactory] Validator factory provider * @returns {ValidationResponse} */ async function validateExamplesByMap(filePathSchema, globMapExternalExamples, - { cwdToMappingFile, noAdditionalProperties, ignoreFormats, allPropertiesRequired } = {} -) { + { cwdToMappingFile, noAdditionalProperties, ignoreFormats, allPropertiesRequired, + specPostprocessor = (spec) => spec, + validatorFactory = (spec, ignoreFormats) => _initValidatorFactory(spec, { ignoreFormats }) + } = {}) { let matchingFilePathsMapping = 0; const filePathsMaps = glob.sync( globMapExternalExamples, @@ -180,6 +190,7 @@ async function validateExamplesByMap(filePathSchema, globMapExternalExamples, openapiSpec = await _parseSpec(filePathSchema); openapiSpec = Determiner.getImplementation(openapiSpec) .prepare(openapiSpec, { noAdditionalProperties, allPropertiesRequired }); + openapiSpec = _postprocess(openapiSpec, specPostprocessor); } catch (err) { responses.push(createValidationResponse({ errors: [ApplicationError.create(err)] })); continue; @@ -190,13 +201,11 @@ async function validateExamplesByMap(filePathSchema, globMapExternalExamples, responses.push( _validate( statistics => { - return _handleExamplesByMapValidation( - openapiSpec, mapExternalExamples, statistics, { - cwdToMappingFile, - dirPathMapExternalExamples: path.dirname(filePathMapExternalExamples), - ignoreFormats - } - ).map( + return _handleExamplesByMapValidation(openapiSpec, mapExternalExamples, statistics, { + cwdToMappingFile, + dirPathMapExternalExamples: path.dirname(filePathMapExternalExamples), + ignoreFormats, validatorFactory + }).map( (/** @type ApplicationError */ error) => Object.assign(error, { mapFilePath: path.normalize(filePathMapExternalExamples) }) @@ -227,12 +236,16 @@ async function validateExamplesByMap(filePathSchema, globMapExternalExamples, * "unsupported format" errors). If an Array with only one string is * provided where the formats are separated with `\n`, the entries * will be expanded to a new array containing all entries. + * @param {Function} [specPostprocessor] Provides implementation of spec postprocessor + * @param {Function} [validatorFactory] Validator factory provider * @returns {ValidationResponse} */ async function validateExample(filePathSchema, pathSchema, filePathExample, { noAdditionalProperties, ignoreFormats, - allPropertiesRequired + allPropertiesRequired, + specPostprocessor = (spec) => spec, + validatorFactory = (spec, ignoreFormats) => _initValidatorFactory(spec, { ignoreFormats }) } = {}) { let example = null, schema = null, @@ -242,13 +255,15 @@ async function validateExample(filePathSchema, pathSchema, filePathExample, { openapiSpec = await _parseSpec(filePathSchema); openapiSpec = Determiner.getImplementation(openapiSpec) .prepare(openapiSpec, { noAdditionalProperties, allPropertiesRequired }); + openapiSpec = _postprocess(openapiSpec, specPostprocessor); schema = _extractSchema(_getSchmaPointer(pathSchema, openapiSpec), openapiSpec); } catch (err) { return createValidationResponse({ errors: [ApplicationError.create(err)] }); } + const createValidator = validatorFactory(openapiSpec, ignoreFormats); return _validate( statistics => _validateExample({ - createValidator: _initValidatorFactory(openapiSpec, { ignoreFormats }), + createValidator, schema, example, statistics, @@ -323,11 +338,12 @@ function _validate(validationHandler) { * "unsupported format" errors). If an Array with only one string is * provided where the formats are separated with `\n`, the entries * will be expanded to a new array containing all entries. + * @param {Function} [validatorFactory] Validator factory provider * @returns {Array.} * @private */ function _handleExamplesByMapValidation(openapiSpec, mapExternalExamples, statistics, - { cwdToMappingFile = false, dirPathMapExternalExamples, ignoreFormats } + { cwdToMappingFile = false, dirPathMapExternalExamples, ignoreFormats, validatorFactory } ) { return flatMap(Object.entries(mapExternalExamples), ([pathSchema, filePathsExample]) => { let schema = null; @@ -337,6 +353,8 @@ function _handleExamplesByMapValidation(openapiSpec, mapExternalExamples, statis // If the schema can't be found, don't even attempt to process the examples return ApplicationError.create(err); } + const createValidator = validatorFactory(openapiSpec, ignoreFormats); + return flatMap( flatten([filePathsExample]), filePathExample => { @@ -363,7 +381,7 @@ function _handleExamplesByMapValidation(openapiSpec, mapExternalExamples, statis return [ApplicationError.create(err)]; } return flatMap(examples, example => _validateExample({ - createValidator: _initValidatorFactory(openapiSpec, { ignoreFormats }), + createValidator, schema, example: example.content, statistics, @@ -452,7 +470,7 @@ function _getSchmaPointer(pathSchema, openapiSpec) { * @returns {ValidationResponse} * @private */ -function _validateExamplesPaths({ impl, createValidator }, pathsExamples, openapiSpec) { +function _validateExamplesPaths({ impl, createValidator }, pathsExamples, openapiSpec) { const statistics = _initStatistics(), validationResult = { valid: true, @@ -597,18 +615,32 @@ function _validateExample({ createValidator, schema, example, statistics, filePa * @private */ function _initValidatorFactory(specSchema, { ignoreFormats }) { + const formats = ignoreFormats && ignoreFormats.reduce((result, entry) => { + result[entry] = () => true; + return result; + }, {}); return getValidatorFactory(specSchema, { schemaId: 'auto', discriminator: true, strict: false, allErrors: true, - formats: ignoreFormats && ignoreFormats.reduce((result, entry) => { - result[entry] = () => true; - return result; - }, {}) + formats }); } +/*** + * Run spec postprocess if defined. + * @returns modified OAS spec or the original one in case of errors + */ +function _postprocess(oasSpec, specPostprocessor) { + let result = oasSpec; + if (typeof specPostprocessor === 'function') { + result = specPostprocessor(oasSpec); + if (!result) { throw new Error('Postprocessor has to be specified'); } + } + return result; +} + /** * Extracts the schema in the OpenAPI-spec at the given JSON-pointer. * @param {string} schemaPointer JSON-pointer to the schema diff --git a/src/validator.js b/src/validator.js index 5482714..43c00ba 100644 --- a/src/validator.js +++ b/src/validator.js @@ -21,9 +21,10 @@ module.exports = { * Get a factory-function to create a prepared validator-instance * @param {Object} specSchema OpenAPI-spec of which potential local references will be extracted * @param {Object} [options] Options for the validator + * @param {Function} [provider] Ajv provider * @returns {function(): (ajv | ajv.Ajv)} */ -function getValidatorFactory(specSchema, options, { provider = (opt) => new Ajv(opt) }) { +function getValidatorFactory(specSchema, options, { provider = (opt) => new Ajv(opt) } = {}) { const preparedSpecSchema = _createReferenceSchema(specSchema); return () => { const validator = provider(options); @@ -49,7 +50,7 @@ function compileValidate(validator, responseSchema) { try { result = validator.compile(preparedResponseSchema); } catch (e) { - result = () => {}; + result = () => { }; result.errors = [e]; } return result; @@ -79,7 +80,7 @@ function _replaceRefsToPreparedSpecSchema(schema) { json: schema, callback(value, type, payload) { if (!value.startsWith('#')) { return; } - payload.parent[payload.parentProperty] = `${ ID__SPEC_SCHEMA }${ value }`; + payload.parent[payload.parentProperty] = `${ID__SPEC_SCHEMA}${value}`; } }); } diff --git a/test/data/v3/custom-postprocessing/readOnly.json b/test/data/v3/custom-postprocessing/readOnly.json new file mode 100644 index 0000000..032b9e8 --- /dev/null +++ b/test/data/v3/custom-postprocessing/readOnly.json @@ -0,0 +1,95 @@ +{ + "openapi": "3.0.0", + "info": { + "version": "1.0.0", + "title": "Swagger Petstore", + "license": { + "name": "MIT" + } + }, + "tags": [ + { + "name": "foo", + "description": "Everything about your foo" + } + ], + "servers": [ + { + "url": "http://petstore.swagger.io/v1" + } + ], + "paths": { + "/foo": { + "post": { + "summary": "Add foo", + "operationId": "addFoo", + "description": "Create Foo", + "tags": [ + "foo" + ], + "requestBody": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Foo" + }, + "examples": { + "invalid1": { + "value": { + "bar": "aaa", + "baz": 0 + } + }, + "invalid2": { + "value": { + "bar": "aaa", + "xxx": "xxx" + } + } + } + } + } + }, + "responses": { + "201": { + "description": "Created", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Foo" + }, + "examples": { + "valid": { + "description": "here it should be correct", + "value": { + "bar": "aaa", + "baz": 0 + } + } + } + } + } + } + } + } + } + }, + "components": { + "schemas": { + "Foo": { + "type": "object", + "description": "Simple Foo", + "properties": { + "bar": { + "type": "string" + }, + "baz": { + "type": "integer", + "readOnly": true + } + }, + "additionalProperties": false + } + } + } +} \ No newline at end of file diff --git a/test/specs/extensions.js b/test/specs/extensions.js new file mode 100644 index 0000000..09ece46 --- /dev/null +++ b/test/specs/extensions.js @@ -0,0 +1,32 @@ +const + { 'default': validateExamples } = require('../../src'), + { loadTestData } = require('../util/setup-tests'); + // { applyCallbackToAllObjectModels } = require('../../src/impl/service/common'); +const { JSONPath: jp } = require('jsonpath-plus'); + +function removeReadOnlyFromPostModels(oasSpec) { + // please note that $RefParser.dereference used internally is reusing objectss + oasSpec = JSON.parse(JSON.stringify(oasSpec)); + const path = '$..requestBody..schema..*[?(@.readOnly)]'; + jp({ path, json: oasSpec, resultType: 'parentProperty', callback: (val, _, obj) => { + const parent = obj.parent; + if (parent[val].readOnly === true) { + delete parent[val]; + } + } }); + return oasSpec; +} + +describe('OAS postprocessor', function() { + describe('validateExamples', function() { + describe('API version 3', function() { + it('should find errors in all request examples', async function() { + const result = await validateExamples(loadTestData('v3/custom-postprocessing/readOnly'), + { specPostprocessor: removeReadOnlyFromPostModels }); + result.valid.should.equal(false); + result.errors.length.should.equal(2); + result.statistics.examplesTotal.should.equal(3); + }); + }); + }); +}); diff --git a/test/specs/index-custom-ajv.js b/test/specs/index-custom-ajv.js new file mode 100644 index 0000000..4257612 --- /dev/null +++ b/test/specs/index-custom-ajv.js @@ -0,0 +1,152 @@ +// IMPORTS + +const path = require('path'), + structuredClone = require('core-js-pure/actual/structured-clone'), + { validateFile, validateExample, 'default': validateExamples, validateExamplesByMap } = require('../../src'), + { getValidatorFactory } = require('../../src/validator'), + { + loadTestData, + getPathOfTestData + } = require('../util/setup-tests'), + { ApplicationError, ErrorType } = require('../../src/application-error'); + +const Ajv = require('ajv'); + + +function customFactory(specSchema, ignoreFormats) { + const formats = ignoreFormats && ignoreFormats.reduce((result, entry) => { + result[entry] = () => true; + return result; + }, {}); + return getValidatorFactory(specSchema, { + schemaId: 'auto', + discriminator: true, + strict: false, + allErrors: true, + formats, + provider: (opt) => new Ajv(opt) + }); +} + + + +// CONSTANTS + +// General constants +const PATH__SCHEMA_EXTERNAL_EXAMPLE = '$.paths./.get.responses.200.schema', + FILE_PATH__NOT_EXISTS = 'Mhhh, dinner', + FILE_PATH__DATA = path.join(__dirname, '..', 'data', 'v2'), + FILE_PATH__EXTERNAL_EXAMPLES_MAP__RELATIVE = path.join(FILE_PATH__DATA, 'map-external-examples-relative.json'), + FILE_PATH__EXTERNAL_EXAMPLE1_VALID = path.join(FILE_PATH__DATA, 'external-examples-valid-example1.json'), + FILE_PATH__EXTERNAL_EXAMPLES_SCHEMA = path.join(FILE_PATH__DATA, 'external-examples-schema.json'); + + +// TEST SUITES + +describe('Main API', function() { + describe('validateExamples', function() { + describe('API version 2', function() { + it('should successfully validate the file', async function() { + (await validateExamples(loadTestData('v2/valid-single-example'), + { validatorFactory: customFactory })).valid.should.equal(true); + }); + }); + }); + describe('validateExample', function() { + describe('API version 2', function() { + it('should successfully validate the file', async function() { + (await validateExample( + FILE_PATH__EXTERNAL_EXAMPLES_SCHEMA, + PATH__SCHEMA_EXTERNAL_EXAMPLE, + FILE_PATH__EXTERNAL_EXAMPLE1_VALID, + { validatorFactory: customFactory } + )).valid.should.equal(true); + }); + }); + }); + describe('validateExamplesByMap', function() { + describe('API version 2', function() { + it('should successfully validate the file', async function() { + const result = await validateExamplesByMap(FILE_PATH__EXTERNAL_EXAMPLES_SCHEMA, + FILE_PATH__EXTERNAL_EXAMPLES_MAP__RELATIVE, + { validatorFactory: customFactory, cwdToMappingFile: true }); + result.valid.should.equal(true); + }); + describe('without changing the working directory', function() { + it('should fail', async function() { + const result = await validateExamplesByMap(FILE_PATH__EXTERNAL_EXAMPLES_SCHEMA, + FILE_PATH__EXTERNAL_EXAMPLES_MAP__RELATIVE, + { validatorFactory: customFactory }); + result.valid.should.equal(false); + }); + }); + }); + }); + describe('validateFile', function() { + describe('be able to validate file', () => { + it('without errors', async() => { + (await validateFile(getPathOfTestData('v2/valid-single-example'))).valid + .should.equal(true); + }); + it('with error', async() => { + const result = await validateFile(getPathOfTestData('v2/invalid-type'), + { validatorFactory: customFactory }); + result.valid.should.equal(false); + result.errors.should.deep.equal([new ApplicationError(ErrorType.validation, { + instancePath: '/versions/0/id', + keyword: 'type', + message: 'must be string', + params: { + type: 'string' + }, + schemaPath: '#/properties/versions/items/properties/id/type', + examplePath: '/paths/~1/get/responses/200/examples/application~1json' + })]); + }); + }); + describe('collect statistics', () => { + it('with examples with missing schemas', async() => { + structuredClone(await validateFile(getPathOfTestData('v2/simple-example'), + { validatorFactory: customFactory })).statistics.should.deep + .equal({ + schemasWithExamples: 1, + examplesWithoutSchema: 3, + examplesTotal: 4 + }); + }); + it('without examples', async() => { + structuredClone(await validateFile(getPathOfTestData('v2/valid-without-examples'), + { validatorFactory: customFactory })).statistics + .should.deep.equal({ + schemasWithExamples: 1, + examplesWithoutSchema: 0, + examplesTotal: 1 + }); + }); + it('without schema', async() => { + structuredClone(await validateFile(getPathOfTestData('v2/valid-without-schema'), + { validatorFactory: customFactory })).statistics + .should.deep.equal({ + schemasWithExamples: 1, + examplesWithoutSchema: 1, + examplesTotal: 2 + }); + }); + }); + describe('should throw errors, when the files can\'t be found:', function() { + it('The schema-file', async() => { + const result = await validateFile(FILE_PATH__NOT_EXISTS, + { validatorFactory: customFactory }); + result.valid.should.equal(false); + result.errors.should.deep.equal([ + new ApplicationError(ErrorType.jsENOENT, { + message: `ENOENT: no such file or directory, open '${ FILE_PATH__NOT_EXISTS }'`, + params: { + path: FILE_PATH__NOT_EXISTS + } + }) + ]); + }); + }); + }); +}); From 4bc76617cf38f2c426101d5378fc7f84385db70d Mon Sep 17 00:00:00 2001 From: Bartosz Michalik Date: Thu, 5 Oct 2023 09:16:59 +0200 Subject: [PATCH 3/6] removing comment --- test/specs/extensions.js | 1 - 1 file changed, 1 deletion(-) diff --git a/test/specs/extensions.js b/test/specs/extensions.js index 09ece46..5c3a2ea 100644 --- a/test/specs/extensions.js +++ b/test/specs/extensions.js @@ -1,7 +1,6 @@ const { 'default': validateExamples } = require('../../src'), { loadTestData } = require('../util/setup-tests'); - // { applyCallbackToAllObjectModels } = require('../../src/impl/service/common'); const { JSONPath: jp } = require('jsonpath-plus'); function removeReadOnlyFromPostModels(oasSpec) { From 63f6934f7c352871bb41234bf36826da5e2ea1b4 Mon Sep 17 00:00:00 2001 From: Bartosz Michalik Date: Tue, 10 Oct 2023 13:32:55 +0200 Subject: [PATCH 4/6] post merge fixes --- src/index.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/index.js b/src/index.js index 03ab862..cdbbeba 100644 --- a/src/index.js +++ b/src/index.js @@ -114,9 +114,8 @@ async function validateExamples(openapiSpec, { noAdditionalProperties, ignoreFor openapiSpec = _postprocess(openapiSpec, specPostprocessor); let pathsExamples = impl.getJsonPathsToExamples() .reduce((res, pathToExamples) => { - return res.concat(_pathToPointer(openapiSpec, pathToExamples)); - }, []) - .map(impl.escapeExampleName); + return res.concat(_pathToPointer(pathToExamples, openapiSpec)); + }, []); const createValidator = validatorFactory(openapiSpec, ignoreFormats); return _validateExamplesPaths({ impl, createValidator }, pathsExamples, openapiSpec); } From 5b48146b43f7571396fa433d5e95741ecbbd1b9a Mon Sep 17 00:00:00 2001 From: Bartosz Michalik Date: Fri, 20 Oct 2023 13:03:07 +0200 Subject: [PATCH 5/6] post-processor test improvement --- test/data/v3/custom-postprocessing/readOnly.json | 6 ------ test/specs/extensions.js | 14 +++++++++++--- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/test/data/v3/custom-postprocessing/readOnly.json b/test/data/v3/custom-postprocessing/readOnly.json index 032b9e8..21983af 100644 --- a/test/data/v3/custom-postprocessing/readOnly.json +++ b/test/data/v3/custom-postprocessing/readOnly.json @@ -39,12 +39,6 @@ "bar": "aaa", "baz": 0 } - }, - "invalid2": { - "value": { - "bar": "aaa", - "xxx": "xxx" - } } } } diff --git a/test/specs/extensions.js b/test/specs/extensions.js index 5c3a2ea..1303737 100644 --- a/test/specs/extensions.js +++ b/test/specs/extensions.js @@ -17,14 +17,22 @@ function removeReadOnlyFromPostModels(oasSpec) { } describe('OAS postprocessor', function() { - describe('validateExamples', function() { + describe('validateExamples taking into readOnly flag from OAS spec', function() { describe('API version 3', function() { + it('without "readOnly" post-processor an error is not captured', async function() { + //please look into spec and check that the 'invalid1' example is not complying to OAS spec + const result = await validateExamples(loadTestData('v3/custom-postprocessing/readOnly')); + result.valid.should.equal(true); + result.statistics.examplesTotal.should.equal(2); + }); + it('should find errors in all request examples', async function() { const result = await validateExamples(loadTestData('v3/custom-postprocessing/readOnly'), { specPostprocessor: removeReadOnlyFromPostModels }); result.valid.should.equal(false); - result.errors.length.should.equal(2); - result.statistics.examplesTotal.should.equal(3); + result.errors.length.should.equal(1); + result.errors[0].examplePath.includes('invalid'); + result.statistics.examplesTotal.should.equal(2); }); }); }); From 623d0a4a39684efbae3ab3a169cd2f91e8d871f3 Mon Sep 17 00:00:00 2001 From: Bartosz Michalik Date: Fri, 20 Oct 2023 13:23:44 +0200 Subject: [PATCH 6/6] fixed error message. improved test with postprocessor chaining --- src/index.js | 2 +- test/specs/extensions.js | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/index.js b/src/index.js index cdbbeba..bb107c2 100644 --- a/src/index.js +++ b/src/index.js @@ -635,7 +635,7 @@ function _postprocess(oasSpec, specPostprocessor) { let result = oasSpec; if (typeof specPostprocessor === 'function') { result = specPostprocessor(oasSpec); - if (!result) { throw new Error('Postprocessor has to be specified'); } + if (!result) { throw new Error('Postprocessor does not return processed document'); } } return result; } diff --git a/test/specs/extensions.js b/test/specs/extensions.js index 1303737..99c7fb7 100644 --- a/test/specs/extensions.js +++ b/test/specs/extensions.js @@ -3,9 +3,12 @@ const { loadTestData } = require('../util/setup-tests'); const { JSONPath: jp } = require('jsonpath-plus'); +function deepClone(oasSpec) { + // please note that $RefParser.dereference used internally is reusing objects + return JSON.parse(JSON.stringify(oasSpec)); +} + function removeReadOnlyFromPostModels(oasSpec) { - // please note that $RefParser.dereference used internally is reusing objectss - oasSpec = JSON.parse(JSON.stringify(oasSpec)); const path = '$..requestBody..schema..*[?(@.readOnly)]'; jp({ path, json: oasSpec, resultType: 'parentProperty', callback: (val, _, obj) => { const parent = obj.parent; @@ -16,6 +19,12 @@ function removeReadOnlyFromPostModels(oasSpec) { return oasSpec; } +function chained(functions) { + return function(input) { + return functions.reduce((result, func) => func(result), input); + }; +} + describe('OAS postprocessor', function() { describe('validateExamples taking into readOnly flag from OAS spec', function() { describe('API version 3', function() { @@ -27,8 +36,9 @@ describe('OAS postprocessor', function() { }); it('should find errors in all request examples', async function() { + const postProcessor = chained([deepClone, removeReadOnlyFromPostModels]); const result = await validateExamples(loadTestData('v3/custom-postprocessing/readOnly'), - { specPostprocessor: removeReadOnlyFromPostModels }); + { specPostprocessor: postProcessor }); result.valid.should.equal(false); result.errors.length.should.equal(1); result.errors[0].examplePath.includes('invalid');