-
Notifications
You must be signed in to change notification settings - Fork 351
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
fix: readOnly objects in arrays are handled correctly #2513
fix: readOnly objects in arrays are handled correctly #2513
Conversation
…Items NOT accounted for yet
…), additionalItems not implemented yet
…typed including additionalItems, as well as single typed
3007670
to
5a9e794
Compare
Thank you for opening this PR! Everything here looks great. After reviewing, we are wondering if these array changes need to be added for |
Hi Brenda, thanks for the feedback! I thought about this for a moment and realized that the existing PR actually does handle arrays with |
@brendarearden Hi! Would it be possible to get a follow up review? Thank you! |
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.
looks good!
#2519 I opened an issue to track the additionalitems bug you discovered as well! |
Addresses #2336
Summary
Currently, given an object with a readOnly required field, Prism does not handle it properly as soon as the object is embedded into an array. Specifically, the user will get an error saying they must manually specify the readOnly property. This PR fixes this issue for all possibilities of arrays: single-typed arrays specified by a single item schema, and tuple-typed arrays specified by a list of item schemas, both with and without the additionalItems schema for tuple-typed arrays.
See: https://json-schema.org/understanding-json-schema/reference/array
And also see: https://tools.ietf.org/html/draft-zyp-json-schema-03 for items type signature (sections 5.5, 6.4, and 6.9) and additionalItems type signature (sections 5.6, 6.4, and 6.10) in the code
Checklist
Screenshots
--------------------------------------------------READONLY TESTS--------------------------------------------------
Given the following schema (which includes a non-tuple-typed array):
I send the following POST request successfully:
With Prism before this fix, we get an error:
If I change the schema to include a tuple-typed array, with additionalItems specified for demonstration like so:
we see that the fix works for readonly properties in both the tuple-typed items list, and the additionalItems schema object.
With Prism before this fix, we get an error:
--------------------------------------------------WRITEONLY TESTS--------------------------------------------------
Given the following schema (which includes a non-tuple-typed array):
I send the following POST request and get a response with the writeOnly properties (including the "id" property in the array) excluded as they're supposed to be:
With Prism before this fix, we get the writeOnly property "id" from the array inappropriately included in the response:
If I change the schema to include a tuple-typed array:
we see that the fix works for writeOnly properties in the tuple-typed array -- they're appropriately excluded from the response:
With Prism before this fix, however, the writeOnly properties in the array are inappropriately returned in the response: