Fixed parameters list issues

This commit is contained in:
Roman Gotsiy 2015-10-10 16:48:17 +03:00
parent b30bf98402
commit 01990f265a
2 changed files with 20 additions and 5 deletions

View File

@ -15,9 +15,10 @@ export class ParamsList extends BaseComponent {
prepareModel() {
this.data = {};
let params = this.componentSchema;
let pathParams = this.getPathParams();
if (pathParams) params.concat(pathParams);
let params = this.componentSchema || [];
let pathParams = this.getPathParams() || [];
params = params.concat(pathParams);
params = this.resolveRefs(params);
this.sortParams(params);
// temporary hanlde body param
@ -45,6 +46,16 @@ export class ParamsList extends BaseComponent {
return [];
}
resolveRefs(params) {
return params.map(param => {
if (param.$ref) {
return this.schemaMgr.byPointer(param.$ref);
} else {
return param;
}
});
}
sortParams(params) {
const sortOrder = {
'path' : 0,
@ -54,6 +65,6 @@ export class ParamsList extends BaseComponent {
'body': 50
};
params.sort((a, b) => sortOrder[a] - sortOrder[b]);
params.sort((a, b) => sortOrder[a.in] - sortOrder[b.in]);
}
}

View File

@ -42,7 +42,11 @@ export class JsonPointer extends JsonPointerLib {
if (ptr.charAt(0) === '#') {
ptr = ptr.substring(1);
}
return JsonPointerLib.parse(ptr);
return JsonPointerLib._origParse(ptr);
}
}
JsonPointerLib._origParse = JsonPointerLib.parse;
JsonPointerLib.parse = JsonPointer.parse;
export default JsonPointer;