Skip to content

Fix/strip path fields from component schemas#235

Open
paultyng wants to merge 2 commits intosudorandom:mainfrom
paultyng:fix/strip-path-fields-from-component-schemas
Open

Fix/strip path fields from component schemas#235
paultyng wants to merge 2 commits intosudorandom:mainfrom
paultyng:fix/strip-path-fields-from-component-schemas

Conversation

@paultyng
Copy link
Copy Markdown
Contributor

@paultyng paultyng commented Mar 6, 2026

When using google.api.http with path parameters, path-bound fields are correctly excluded from inline request bodies (fixed in #234), but they still appear in the corresponding components/schemas entries. This adds an opt-in strip-path-params-from-schemas option to remove them there as well.
Related: #27

Example

Given this proto:

message GetThingRequest {
  string path = 1 [(google.api.field_behavior) = REQUIRED];
}
service ThingService {
  rpc GetThing(GetThingRequest) returns (Thing) {
    option (google.api.http) = {
      get: "/v1/{path=things/*}"
    };
  }
}

Beforepath appears as both a URL parameter and in the component schema:

paths:
  /v1/things/{thing}:
    get:
      parameters:
        - name: thing
          in: path
          required: true
components:
  schemas:
    GetThingRequest:
      type: object
      properties:
        path:          # redundant — already a path param
          type: string
      required:
        - path

After (with strip-path-params-from-schemas):

components:
  schemas:
    GetThingRequest:
      type: object

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?

paultyng added 2 commits March 6, 2026 10:30
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
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.

1 participant