diff --git a/src/utils.js b/src/utils.js index 22f08e1863..0db3ca7e77 100644 --- a/src/utils.js +++ b/src/utils.js @@ -424,7 +424,7 @@ export function optionsList(schema) { function findSchemaDefinition($ref, definitions = {}) { // Extract and use the referenced definition if we have it. - const match = /^#\/definitions\/(.*)$/.exec($ref); + const match = /^#(?:\/definitions)?\/(.*)$/.exec($ref); if (match && match[1]) { const parts = match[1].split("/"); let current = definitions; diff --git a/test/mocha.opts b/test/mocha.opts index cf80ee74bc..afbeee1278 100644 --- a/test/mocha.opts +++ b/test/mocha.opts @@ -1 +1,3 @@ --timeout 5000 +--compilers js:babel-register +--require ./test/setup-jsdom.js diff --git a/test/utils_test.js b/test/utils_test.js index 5acfcc229d..cb421bfd0c 100644 --- a/test/utils_test.js +++ b/test/utils_test.js @@ -607,6 +607,22 @@ describe("utils", () => { expect(retrieveSchema(schema, definitions)).eql(address); }); + it("should 'resolve' a schema which contains definitions not in `#/definitions`", () => { + const schema = { $ref: "#/components/schemas/address" }; + const address = { + type: "object", + properties: { + street_address: { type: "string" }, + city: { type: "string" }, + state: { type: "string" }, + }, + required: ["street_address", "city", "state"], + }; + const definitions = { components: { schemas: { address } } }; + + expect(retrieveSchema(schema, definitions)).eql(address); + }); + it("should 'resolve' escaped JSON Pointers", () => { const schema = { $ref: "#/definitions/a~0complex~1name" }; const address = { type: "string" };