swagger2openapi
Advanced tools
Comparing version 2.11.10 to 2.11.11
@@ -64,3 +64,3 @@ 'use strict'; | ||
if (options.verbose) console.warn('Internal resolution',obj[key]); | ||
state.parent[state.pkey] = resolveInternal(context,obj[key]); | ||
state.parent[state.pkey] = clone(resolveInternal(context,obj[key])); | ||
} | ||
@@ -67,0 +67,0 @@ } |
42
index.js
@@ -152,3 +152,4 @@ // @ts-check | ||
function fixupRefs(obj, key, state, options) { | ||
function fixupRefs(obj, key, state) { | ||
let options = state.payload.options; | ||
if (common.isRef(obj,key)) { | ||
@@ -160,3 +161,3 @@ if (obj[key].startsWith('#/definitions/')) { | ||
if (!newKey) { | ||
throwOrWarn('Could not resolve reference '+obj[key],obj,state.payload.options); | ||
throwOrWarn('Could not resolve reference '+obj[key],obj,options); | ||
} | ||
@@ -168,10 +169,41 @@ else { | ||
} | ||
if (obj[key].startsWith('#/parameters/')) { | ||
else if (obj[key].startsWith('#/parameters/')) { | ||
// for extensions like Apigee's x-templates | ||
obj[key] = '#/components/parameters/' + common.sanitise(obj[key].replace('#/parameters/', '')); | ||
} | ||
if (obj[key].startsWith('#/responses/')) { | ||
else if (obj[key].startsWith('#/responses/')) { | ||
// for extensions like Apigee's x-templates | ||
obj[key] = '#/components/responses/' + common.sanitise(obj[key].replace('#/responses/', '')); | ||
} | ||
else if (obj[key].startsWith('#')) { | ||
// fixes up direct $refs or those created by resolvers | ||
let target = common.clone(jptr.jptr(options.openapi,obj[key])); | ||
if (target === false) throwOrWarn('direct $ref not found '+obj[key],obj,options) | ||
else { | ||
// we use a heuristic to determine what kind of thing is being referenced | ||
let oldRef = obj[key]; | ||
oldRef = oldRef.replace('/properties/headers/',''); | ||
oldRef = oldRef.replace('/properties/responses/',''); | ||
oldRef = oldRef.replace('/properties/parameters/',''); | ||
oldRef = oldRef.replace('/properties/schemas/',''); | ||
let type = 'schemas'; | ||
let schemaIndex = oldRef.lastIndexOf('/schema'); | ||
type = (oldRef.indexOf('/headers/')>schemaIndex) ? 'headers' : | ||
((oldRef.indexOf('/responses/')>schemaIndex) ? 'responses' : | ||
((oldRef.indexOf('/parameters/')>schemaIndex) ? 'parameters' : 'schemas')); | ||
// non-body/form parameters have not moved in the overall structure (like responses) | ||
// but extracting the requestBodies can cause the *number* of parameters to change | ||
if (type !== 'responses') { | ||
let prefix = type.substr(0,type.length-1); | ||
if ((prefix === 'parameter') && target.name) prefix = target.name; | ||
let suffix = 1; | ||
while (jptr.jptr(options.openapi,'#/components/'+type+'/'+prefix+suffix)) suffix++; | ||
let newRef = '#/components/'+type+'/'+prefix+suffix; | ||
jptr.jptr(options.openapi,newRef,target); | ||
obj[key] = newRef; | ||
} | ||
} | ||
} | ||
} | ||
@@ -182,3 +214,3 @@ if ((key === 'x-ms-odata') && (typeof obj[key] === 'string') && (obj[key].startsWith('#/'))) { | ||
if (!newKey) { | ||
throwOrWarn('Could not resolve reference '+obj[key],obj,state.payload.options); | ||
throwOrWarn('Could not resolve reference '+obj[key],obj,options); | ||
} | ||
@@ -185,0 +217,0 @@ else { |
{ | ||
"name": "swagger2openapi", | ||
"version": "2.11.10", | ||
"version": "2.11.11", | ||
"description": "Convert Swagger 2.0 definitions to OpenApi 3.0 and validate", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -11,3 +11,3 @@ 'use strict'; | ||
const tests = fs.readdirSync(__dirname).filter(file => { | ||
return fs.statSync(path.join(__dirname, file)).isDirectory() | ||
return fs.statSync(path.join(__dirname, file)).isDirectory() && file !== 'include'; | ||
}); | ||
@@ -24,3 +24,3 @@ | ||
options = yaml.safeLoad(fs.readFileSync(path.join(__dirname, test, 'options.yaml'),'utf8'),{json:true}); | ||
options.source = path.join(__dirname, test, 'openapi.yaml'); | ||
options.source = path.join(__dirname, test, 'swagger.yaml'); | ||
} | ||
@@ -27,0 +27,0 @@ catch (ex) {} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
377103
58
6536