Skip to content

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

Merged
ahl merged 2 commits into
mainfrom
cli-dup-params
Oct 9, 2024
Merged

Improve handling of name collisions between parameters and top-level body fields#941
ahl merged 2 commits into
mainfrom
cli-dup-params

Conversation

@ahl

@ahl ahl commented Oct 7, 2024

Copy link
Copy Markdown
Collaborator

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
Copy Markdown

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

ahl commented Oct 8, 2024

Copy link
Copy Markdown
Collaborator Author

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.

@rcgoodfellow rcgoodfellow left a comment

Copy link
Copy Markdown

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
@ahl ahl deleted the cli-dup-params branch October 9, 2024 05:20
abus-sh pushed a commit to abus-sh/progenitor that referenced this pull request Dec 5, 2025
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