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

Improve handling of name collisions between parameters and top-level body fields #941

Merged
merged 2 commits into from
Oct 9, 2024

Conversation

ahl
Copy link
Collaborator

@ahl ahl commented Oct 7, 2024

In oxidecomputer/oxide.rs#853 we had a situation where a parameter (query) had the same name as a top-level field in the POST body. In this case, we prioritized the body field over the parameter. This led to the CLI subcommand being unusable. While this particular case turned out to be a mistake in the API, if such a situation were to occur, this PR causes us to ignore the body field (thus making the body required if the field was required).

This PR has a commit that introduces the new test for this condition and then a commit that contains the fix.

@ahl ahl requested a review from rcgoodfellow October 7, 2024 22:31
@rcgoodfellow
Copy link

this PR causes us to ignore the body field (thus making the body required if the field was required)

I'm trying to internalize this statement. I would have thought the body would be required if the parameter was required e.g.:

this PR causes us to ignore the body field (thus making the body required if the parameter was required)

?

@ahl
Copy link
Collaborator Author

ahl commented Oct 8, 2024

Let's say the body has a top-level, scalar field whose name conflicts with that of a parameter (query or path). In that situation we would previously just fill in that field of the body and not supply the parameter which was a big problem! (particularly if the parameter was required)

After this change, in such a case, the generated code ONLY fills in the parameter. If the field is required (ie not an Option type) that will make the --json-body parameter mandatory as it would be the only way to supply that required field. This is similarly the case if a required body field is not a scalar and therefore cannot be expressed as a simple parameter on the command line.

Copy link

@rcgoodfellow rcgoodfellow left a comment

Choose a reason for hiding this comment

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

Thanks for the clarification. Changes LGTM!

@ahl ahl merged commit 4c6375f into main Oct 9, 2024
6 checks passed
@ahl ahl deleted the cli-dup-params branch October 9, 2024 05:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants