Skip to content
This repository has been archived by the owner on Oct 5, 2023. It is now read-only.

feat: stop running schema dereferencing when running validation #153

Merged
merged 2 commits into from
Aug 26, 2021

Conversation

erunion
Copy link
Member

@erunion erunion commented Aug 26, 2021

🚨  This will be a breaking change!

🧰 Changes

So a fun fact: when running .validate() on a schema we first dereference it with .deref() and then when swagger-parser runs .validate() on it it also does its own dereferencing. Since all .validate() should do is validate something, this work changes it to no longer dereference. Anywhere. Ever.

I've also swapped our our usage of @apidevtools/json-schema-ref-parser for pure @apidevtools/swagger-parser as the two libraries already depend on each other and expose the same APIs.

🧬 QA & Testing

See the test changes I made.

@erunion erunion added the enhancement New feature or request label Aug 26, 2021
@erunion erunion requested a review from kanadgupta August 26, 2021 22:49
Comment on lines -40 to -43
"@apidevtools/json-schema-ref-parser": "^9.0.7",
"@apidevtools/swagger-parser": "^10.0.3",
"js-yaml": "^4.1.0",
"node-fetch": "^2.6.1",
"swagger-parser": "^10.0.1",
Copy link
Member

Choose a reason for hiding this comment

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

🎉

// on this library and our `validate()` method here just needs to tell us if the definition
// is valid or not we need to clone it before passing it over to `swagger-parser` so as to
// not run into pass-by-reference problems.
const clonedSchema = JSON.parse(JSON.stringify(schema));
Copy link
Member

Choose a reason for hiding this comment

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

(sigh)

@kanadgupta
Copy link
Member

Oh one question—is this a breaking change in any of our validate calls?

@erunion
Copy link
Member Author

erunion commented Aug 26, 2021

In the places that we use this library also call .validate() it won't but I'm still going to publish this as a breaking change/major release.

@erunion erunion merged commit 7b706db into main Aug 26, 2021
@erunion erunion deleted the feat/validate-without-deref branch August 26, 2021 22:55
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants