diff --git a/src/services/OpenAPIParser.ts b/src/services/OpenAPIParser.ts index 73867206d2..52f5e36317 100644 --- a/src/services/OpenAPIParser.ts +++ b/src/services/OpenAPIParser.ts @@ -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; } diff --git a/src/services/models/Field.ts b/src/services/models/Field.ts index 85e9d10547..fd0da09681 100644 --- a/src/services/models/Field.ts +++ b/src/services/models/Field.ts @@ -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;