UNPKG

test-openapi

Version:
56 lines (36 loc) 1.47 kB
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.checkIsSchema=void 0;var _jsonSchemaDraft=_interopRequireDefault(require("ajv/lib/refs/json-schema-draft-04")); var _lodash=require("lodash"); var _check=require("./check.js");function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}} const checkIsSchema=function(opts){ const message=getSchemaMessage(opts); (0,_check.checkSchema)({schema:jsonSchemaSchema,message,...opts}); };exports.checkIsSchema=checkIsSchema; const getSchemaMessage=function({valueProp}){ const name=valueProp===undefined?"schema":`'${valueProp}'`; return`${name} is not a valid JSON schema version 4`; }; const getJsonSchemaSchema=function(){ return SCHEMA_FIXES.reduce((schema,fix)=>fix(schema),_jsonSchemaDraft.default); }; const removeId=function(schema){ return(0,_lodash.omit)(schema,["id","$schema"]); }; const fixMultipleOf=function(schema){ const multipleOf={type:"number",exclusiveMinimum:0}; return{ ...schema, properties:{...schema.properties,multipleOf}}; }; const fixFormat=function(schema){ const format={type:"string"}; return{...schema,properties:{...schema.properties,format}}; }; const fixCustomProperties=function(schema){ return{ ...schema, patternProperties:{"^x-*":{}}, additionalProperties:false}; }; const SCHEMA_FIXES=[removeId,fixMultipleOf,fixFormat,fixCustomProperties]; const jsonSchemaSchema=getJsonSchemaSchema(); //# sourceMappingURL=meta.js.map