Fix/strip path fields from component schemas#235
Open
paultyng wants to merge 2 commits intosudorandom:mainfrom
Open
Fix/strip path fields from component schemas#235paultyng wants to merge 2 commits intosudorandom:mainfrom
paultyng wants to merge 2 commits intosudorandom:mainfrom
Conversation
Demonstrates that path-bound fields (e.g. `path`, `parent`) remain in component schemas even though they are already mapped to URL path parameters. The expected golden files show the correct behavior with those fields stripped. This test is expected to fail until the fix is applied. Related: sudorandom#27 Made-with: Cursor
When using google.api.http annotations with path parameters, fields bound to URL path segments (e.g. `path`, `parent`) were correctly excluded from inline request bodies but still appeared in the corresponding component schemas under `components/schemas`. This adds a new `strip-path-params-from-schemas` option that removes these path-bound fields from component schemas. The option is opt-in for backward compatibility. Aligns with how Google Cloud APIs document their schemas in Discovery Documents and follows gRPC transcoding conventions (AIP-127/AEP-127). Related: sudorandom#27 Made-with: Cursor
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.
When using
google.api.httpwith path parameters, path-bound fields are correctly excluded from inline request bodies (fixed in #234), but they still appear in the correspondingcomponents/schemasentries. This adds an opt-instrip-path-params-from-schemasoption to remove them there as well.Related: #27
Example
Given this proto:
Before —
pathappears as both a URL parameter and in the component schema:After (with
strip-path-params-from-schemas):This matches how Google Cloud APIs handle the same situation in their Discovery Documents — path-bound fields are not repeated in request schemas.
I made this opt-in so as not to impact existing generation expectations, but I think it is perhaps a bug, unsure?