Skip to content

Add support for sets with custom OAS format field #25

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

Merged
merged 8 commits into from
Jun 26, 2023

Conversation

austinvalle
Copy link
Member

@austinvalle austinvalle commented Jun 23, 2023

RFC: https://docs.google.com/document/d/15PJokoO7mkMYsc2Z7DN1copykQgH5Kt7nnzb-mcNcTo/edit#heading=h.j9b2jaknykw

This PR adds support for:

  • SetNestedAttribute
  • SetAttribute
  • SetType (only possible under a collection type currently, ListAttribute or SetAttribute)

I also added documentation to the design doc and added unit/integration tests to cover since this is a custom field that is not present in existing OAS tests.

I wrote the integration tests first, and you can see the diff (list -> set) after implementation here: bc38b31#diff-d0cc596b04078cce090146b7654ac6f32f518ba08c68becbfcb93a07257eefdb

Notes

  • Also updated the codegen-spec package to the latest commit

@austinvalle austinvalle requested a review from a team as a code owner June 23, 2023 19:48
Copy link
Contributor

@bendbennett bendbennett left a comment

Choose a reason for hiding this comment

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

LGTM 🎸

Copy link
Contributor

@bflad bflad left a comment

Choose a reason for hiding this comment

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

Looks good to me 🚀

I presume that uniqueItems will be treated via validation over set handling? Technically, you can have an ordered list with unique items. Can create the coverage issue if you agree.

@austinvalle
Copy link
Member Author

austinvalle commented Jun 26, 2023

Looks good to me 🚀

I presume that uniqueItems will be treated via validation over set handling? Technically, you can have an ordered list with unique items. Can create the coverage issue if you agree.

I actually do not remember coming across uniqueItems during my research for the RFC, thanks for sharing that.

Yeah as you mentioned JSON schema defines arrays as "ordered", however I do see some tools that have made the decision to treat OpenAPI's uniqueItems as a Set:

So if we want to use uniqueItems instead of a custom type, that doesn't seem to be too far of a stretch 🤔

Also related: json-schema-org/json-schema-spec#1197

@austinvalle
Copy link
Member Author

After chatting in our sync today, the plan is to keep the custom format: set proposed in this PR.

JSON schema does not have a concept of unordered arrays, so we'd be making a technically invalid assumption that uniqueItems == unordered AND unique. We can support validation for ordered lists that have unique items with a custom validator.

@austinvalle
Copy link
Member Author

Opened #26 as follow-up

Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 23, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants