Skip to content
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
"publish-to-npm": "npm run build:readme && npm run dist && npm publish",
"preversion": "npm run build:playground && npm run dist && npm run build:readme && npm run cs-check && npm run lint",
"start": "node devServer.js",
"tdd": "cross-env NODE_ENV=test mocha --require babel-register --watch --require ./test/setup-jsdom.js test/**/*_test.js",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the changes for mocha config, but can you please remove these changes from this PR and make a separate PR for it?

"test": "cross-env NODE_ENV=test mocha --require babel-register --require ./test/setup-jsdom.js test/**/*_test.js"
"tdd": "cross-env NODE_ENV=test mocha --watch test/**/*_test.js",
"test": "cross-env NODE_ENV=test mocha test/**/*_test.js"
},
"prettierOptions": "--jsx-bracket-same-line --trailing-comma es5 --semi --tab-width 2",
"lint-staged": {
Expand Down
2 changes: 1 addition & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,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;
Expand Down
2 changes: 2 additions & 0 deletions test/mocha.opts
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
--timeout 5000
--compilers js:babel-register
--require ./test/setup-jsdom.js
16 changes: 16 additions & 0 deletions test/utils_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,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" };
Expand Down