Added support for readOnly and writeOnly keywords with v2 APIs. #807
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
Fixes postmanlabs/postman-app-support#12255 and #98.
This PR adds correct support for resolution of readOnly and writeOnly keywords while generating collections from it. i.e. readOnly properties will not be present in request part anymore and writeOnly properties will not be present in responses.
To read up more on working of readOnly and writeOnly, take a look here.
Implementation details
To optimize the schema resolution that happens for each schema object mentioned in OpenAPI, we use function
resolveSchema
and also make sure that resolved schemas are cached for further usage.Now in case of
readOnly
andwriteOnly
properties case, if we don't resolve certain property based on where it's at within request or response, we'll end up with incorrect schema based on where it might be used again from cache.With this PR, we're adding support for caching where exactly
readOnly
andwriteOnly
properties are present and we'll be using it further to make sure correct schema is returned as return value ofresolveSchema
. To do this, we're making sure that we don't change the schema we cached and only change return value base on if there were anyreadOnly
and/orwriteOnly
properties were found or not making sure no performance overhead for usecases withoutreadOnly
andwriteOnly
props.For storing the location of
readOnly
andwriteOnly
that are cached, we're using JSON Pointer. We're also appropriately escaping and unescaping related special characters.