fix: correct pointer for the schema

This commit is contained in:
Roman Hotsiy 2017-12-07 13:54:34 +02:00
parent 57129d3f58
commit 4ae1574c6c
No known key found for this signature in database
GPG Key ID: 5CB7B3ACABA57CB0
2 changed files with 7 additions and 3 deletions

View File

@ -94,9 +94,9 @@ export class OpenAPIParser {
let res;
if (this.spec === undefined) return;
if (ref.charAt(0) !== '#') ref = '#' + ref;
ref = decodeURI(ref);
ref = decodeURIComponent(ref);
try {
res = JsonPointer.get(this.spec, decodeURIComponent(ref));
res = JsonPointer.get(this.spec, ref);
} catch (e) {
// do nothing
}
@ -107,6 +107,9 @@ export class OpenAPIParser {
* checks if the objectt is OpenAPI reference (containts $ref property)
*/
isRef(obj: any): obj is OpenAPIRef {
if (!obj) {
return false;
}
return obj.$ref !== undefined && obj.$ref !== null;
}

View File

@ -31,7 +31,8 @@ export class FieldModel {
this.name = info.name;
this.in = info.in;
this.required = !!info.required;
this.schema = new SchemaModel(parser, info.schema || {}, pointer + '/schema', options);
const schemaPointer = (parser.isRef(infoOrRef) ? infoOrRef.$ref : pointer) + '/schema';
this.schema = new SchemaModel(parser, info.schema || {}, schemaPointer, options);
this.description =
info.description === undefined ? this.schema.description || '' : info.description;
const example = info.example || this.schema.example;