Skip to content

fix(openapi): operation-level parameters override path-level ones (same name+in) - #974

Open
Larslllllll wants to merge 1 commit into
profullstack:masterfrom
Larslllllll:fix/openapi-param-override
Open

fix(openapi): operation-level parameters override path-level ones (same name+in)#974
Larslllllll wants to merge 1 commit into
profullstack:masterfrom
Larslllllll:fix/openapi-param-override

Conversation

@Larslllllll

Copy link
Copy Markdown
Contributor

Problem

normalize() concatenated path-level and operation-level parameters arrays. Per the OpenAPI spec, an operation-level parameter with the same name + in replaces the path-level one (it exists precisely to override description, schema, required, … per operation).

Because both copies were kept, every consumer saw duplicated parameters:

  • openapi docs renders duplicate rows in the parameters table
  • openapi mcp silently overwrites one entry in the input schema
  • openapi sdk emits invalid TypeScript — duplicate function arguments:
// generated from a spec where the op re-declares petId with a stricter schema
async getPet(petId: string, petId: string, opts: { ... } = {}): Promise<unknown>

Repro

Spec: /pets/{petId} declares petId at path level; the get operation re-declares it with minLength: 1. sh1pt openapi sdk on this spec produces the broken client above.

Fix

  • Resolve $refs in both positions first, then drop any path-level parameter for which the operation declares its own same name + in parameter.
  • Non-overridden path-level parameters are still inherited, as before.

Tests

  • operation-level override replaces the path-level param and keeps unrelated inherited params (verbose)
  • override detection works when either side is a $\ref to #/components/parameters/…

All 10 openapi tests pass; typecheck clean.

…me name+in)

Per the OpenAPI spec, an operation parameter with the same name and
location as a path-level parameter replaces it. normalize() concatenated
both, so every downstream consumer saw duplicated parameters:

- generated docs showed duplicate parameter table rows
- MCP input schemas silently overwrote one entry
- the TS SDK emitted invalid code: `async getPet(petId: string,
  petId: string, ...)` — duplicate function arguments do not compile

Operation-level params now replace same name+in path params ($refs in
both positions are resolved before comparing). Path-level params not
overridden are still inherited. Verified against a Petstore-style spec:
before, getPet generated two petId arguments; after, one.
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