-
-
Couldn't load subscription status.
- Fork 239
feat: dereference.preservedProperties for preserving data during dereferencing
#369
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: dereference.preservedProperties for preserving data during dereferencing
#369
Conversation
| if (obj[key] !== dereferenced.value) { | ||
| // If we have properties we want to preserve from our derefernced schema then we need | ||
| // to copy them over to our new object. | ||
| const preserved: Map<string, unknown> = new Map(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: can we wrap this logic and this object allocation inside a check for if derefOptions?.preservedProperties is set? if its not set we can skip a lot of this logic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Absolutely!
Pull Request Test Coverage Report for Build 13020401245Warning: This coverage report may be inaccurate.This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.
Details
💛 - Coveralls |
|
This lgtm - if you can address the minor comment then I'll merge it in. Thanks! |
|
@jonluca I've just pushed up your recs. Thanks for the speedy review! 💨 |
|
🎉 This PR is included in version 11.9.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
This introduces a new
dereference.preservedPropertiesconfiguration that allows for custom$refdereferencing behavior to happen where if you want to preserve, and prioritize an existing, property you can.The use case for this is theOpenAPI 3.1 specification where because it allows you to define a
descriptionand/orsummaryalongside a$refpointer, and require that thatdescriptionandsummarytake precedence over any that may be inside of the referenced schema there is currently no way to handle this within the library currently.For example, the following schema:
With the existing dereferencing behavior this schema is dereferenced into the following:
However, because in an OpenAPI 3.1 definition I would want to use "Someone's secret name" instead of "Someone's name" on the
secretNameproperty, using this new configuration I can do that:swagger-parser) and conditionally feed in this config for OpenAPI 3.1 definitions.Closes #365