Skip to content
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

Refactor URIDecoder/URIParser to improve handling of the deepObject style #127

Merged
merged 11 commits into from
Nov 21, 2024

Conversation

czechboy0
Copy link
Contributor

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.

@czechboy0
Copy link
Contributor Author

PR is in draft as I need to add missing doc comments and a few polishing steps.

Copy link
Contributor

@simonjbeaumont simonjbeaumont left a comment

Choose a reason for hiding this comment

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

I'm really glad we're pushing this feature along. I've left some comments. Can I assume that all the new tests you added previously didn't work? If not, could you indicate which of them previously failed as I'd like to give those a little extra attention.

@czechboy0
Copy link
Contributor Author

All the previous tests passed previously, we just changed the tested abstractions which forced me to refractor the tests too. The only new functionality is the deepObject support, so tests related to that style are new.

Copy link
Contributor

@simonjbeaumont simonjbeaumont left a comment

Choose a reason for hiding this comment

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

LGTM, thanks! I left one more comment but it's not a requirement.

@czechboy0 czechboy0 enabled auto-merge (squash) November 21, 2024 17:17
@czechboy0 czechboy0 merged commit 5e119a3 into apple:main Nov 21, 2024
25 checks passed
@czechboy0 czechboy0 deleted the hd-uri-decoder-refactor-deepObject branch November 21, 2024 17:19
@czechboy0 czechboy0 added the semver/patch No public API change. label Nov 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver/patch No public API change.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants