diff --git a/lib/components/Method/method.js b/lib/components/Method/method.js index 1df50d25..2bf47620 100644 --- a/lib/components/Method/method.js +++ b/lib/components/Method/method.js @@ -35,7 +35,7 @@ export default class Method extends BaseComponent { } findBodyParam() { - let pathParams = this.schemaMgr.getMethodParams(JsonPointer.join(this.pointer, 'parameters'), true); + let pathParams = this.schemaMgr.getMethodParams(this.pointer, true); let bodyParam = pathParams.find(param => param.in === 'body'); return bodyParam; } diff --git a/lib/utils/SchemaManager.js b/lib/utils/SchemaManager.js index 2d1765f0..7071483b 100644 --- a/lib/utils/SchemaManager.js +++ b/lib/utils/SchemaManager.js @@ -60,7 +60,9 @@ export default class SchemaManager { resolveRefs(obj) { Object.keys(obj).forEach(key => { if (obj[key].$ref) { - obj[key] = this.byPointer(obj[key].$ref); + let resolved = this.byPointer(obj[key].$ref); + resolved._pointer = obj[key].$ref; + obj[key] = resolved; } }); return obj; @@ -76,18 +78,20 @@ export default class SchemaManager { }); } - //get path params - let ptr = JsonPointer.dirName(methodPtr, 2) + '/parameters'; - let pathParams = this.byPointer(ptr); - if (Array.isArray(pathParams)) { - pathParams = injectPointers(pathParams, ptr); - } else if (pathParams && pathParams.$ref) { - pathParams = injectPointers(this.byPointer(pathParams.$ref), pathParams.$ref); - } else { - pathParams = []; + // accept pointer directly to parameters as well + if (JsonPointer.baseName(methodPtr) === 'parameters') { + methodPtr = JsonPointer.dirName(methodPtr); } - let methodParams = injectPointers(this.byPointer(methodPtr), methodPtr) || []; + //get path params + let pathParamsPtr = JsonPointer.join(JsonPointer.dirName(methodPtr), ['parameters']); + let pathParams = this.byPointer(pathParamsPtr) || []; + + let methodParamsPtr = JsonPointer.join(methodPtr, ['parameters']); + let methodParams = this.byPointer(methodParamsPtr) || []; + pathParams = injectPointers(pathParams, pathParamsPtr); + methodParams = injectPointers(methodParams, methodParamsPtr); + if (resolveRefs) { methodParams = this.resolveRefs(methodParams); pathParams = this.resolveRefs(pathParams);