Support nested arrays of primitive values inside of objects#120
Merged
czechboy0 merged 2 commits intoapple:mainfrom Oct 3, 2024
Merged
Support nested arrays of primitive values inside of objects#120czechboy0 merged 2 commits intoapple:mainfrom
czechboy0 merged 2 commits intoapple:mainfrom
Conversation
Collaborator
simonjbeaumont
left a comment
There was a problem hiding this comment.
Thanks! One question about whether we need to break out this type.
simonjbeaumont
approved these changes
Oct 3, 2024
czechboy0
added a commit
that referenced
this pull request
Nov 21, 2024
…tyle (#127) ### Motivation As part of apple/swift-openapi-generator#259, adding deepObject parameter style support, the initial PR wasn't complete. And once we dug more into it, turns out the original implementation of the URIDecoder/URIParser didn't really lend themselves well for handling deepObject, and the recent additions of supporting arrays within dictionaries (#120) further confused the implementation. ### Modifications Refactored URIParser/URIDecoder with a clearer understanding of the current requirements. It's now much easier to follow and embraces the fact that each of the 7 variants of URI coding we support (form exploded, form unexploded, simple exploded, simple unexploded, form data exploded, form data unexploded, and now deepObject exploded) are similar, but still different in subtle ways. This new implementation doesn't try as hard to share code between the implementations, so might at first sight appear to duplicate code. The original implementation had many methods with many configuration parameters and utility methods with a high cyclomatic complexity, which made it very hard to reason about. We did away with that. While there, I also made some minor improvements to the serialization path, which allows cleaner round-tripping tests. ### Result A more maintainable and more correct URI decoder/parser implementation. ### Test Plan Added many more unit tests that test the full matrix of supported styles and inputs. --------- Co-authored-by: Si Beaumont <simonjbeaumont@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Motivation
It's a useful pattern to define a single JSON schema for all your (e.g. query) parameters, and handle them as a single object in your code.
In OpenAPI, that'd be expressed like this, for example:
Until now, the
myListproperty would not be allowed, and would fail to serialize and parse, as arrays within objects were not allowed forformstyle parameters (used by query items, by default).Modifications
This PR extends the support of the
formstyle to handle single nesting in the top level objects. It does not add support for arbitrarily deep nesting.As part of this work, we also now allow the
deepObjectstyle to do the same - use arrays nested in an object.Result
The useful pattern of having an array within a "params" object works correctly now.
Test Plan
Added unit tests for all 4 components: encoder, decoder, serializer, and parser.