Skip to content

fix(openapi): let WithParameter reach the document - #69

Merged
juicycleff merged 1 commit into
mainfrom
fix/openapi-with-parameter
Aug 25, 2026
Merged

fix(openapi): let WithParameter reach the document#69
juicycleff merged 1 commit into
mainfrom
fix/openapi-with-parameter

Conversation

@juicycleff

Copy link
Copy Markdown
Contributor

The option appended a ParameterDef to route metadata under "parameters", and the only two references to that key in the whole repository were the two lines doing the appending. The generator builds an operation's parameters from the path template, the query schema and the header schema, so a declaration made this way went into a map and stopped. It compiled, it ran, it returned no error, and the parameter reached no document and no generated client.

That is a bad way for an option to fail. A route declaring a parameter the server honours would ship an OpenAPI document that never mentioned it, and the only way to find out was to read the generated spec and notice an absence.

ParameterDef has a name, a location, a description, a required flag and an example, and the example is the only one of those that says anything about what the value holds. So that is what the schema is typed from. An int example gives an integer, a []string example gives an array of string, which is how you declare a repeatable parameter. With no example the parameter falls back to string, because a parameter with no schema is one no client can type at all. The typing runs through a throwaway schema generator with no component registry, so describing a parameter cannot register a component or leave a $ref pointing into one.

Both branches of the operation builder converge before this runs, so a declaration behaves the same whether or not the handler takes a request struct. The already-collected parameters merge first, which means a name described by both a Go type and a declaration keeps the type-derived version. That is the precedence the three existing sources already use among themselves, and it is the right way round: the type knows the real shape, a declaration only knows what somebody typed into the call.

A path parameter comes out required whatever the declaration says, since OpenAPI does not accept one that claims otherwise.

The option appended a ParameterDef to route metadata under "parameters", and
the only two references to that key in the whole repository were the two lines
doing the appending. The generator builds an operation's parameters from the
path template, the query schema and the header schema, so a declaration made
this way went into a map and stopped. It compiled, it ran, it returned no
error, and the parameter reached no document and no generated client.

That is a bad way for an option to fail. A route declaring a parameter the
server honours would ship an OpenAPI document that never mentioned it, and the
only way to find out was to read the generated spec and notice an absence.

ParameterDef has a name, a location, a description, a required flag and an
example, and the example is the only one of those that says anything about what
the value holds. So that is what the schema is typed from. An int example gives
an integer, a []string example gives an array of string, which is how you
declare a repeatable parameter. With no example the parameter falls back to
string, because a parameter with no schema is one no client can type at all.
The typing runs through a throwaway schema generator with no component
registry, so describing a parameter cannot register a component or leave a $ref
pointing into one.

Both branches of the operation builder converge before this runs, so a
declaration behaves the same whether or not the handler takes a request struct.
The already-collected parameters merge first, which means a name described by
both a Go type and a declaration keeps the type-derived version. That is the
precedence the three existing sources already use among themselves, and it is
the right way round: the type knows the real shape, a declaration only knows
what somebody typed into the call.

A path parameter comes out required whatever the declaration says, since
OpenAPI does not accept one that claims otherwise.
@vercel

vercel Bot commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
forge Ready Ready Preview Aug 25, 2026 2:27pm

Request Review

@github-actions

Copy link
Copy Markdown
Contributor

Conventional Commits Validation

PR Title: valid
Commits: all 1 follow conventional format

@github-actions github-actions Bot added the fix label Aug 25, 2026
@juicycleff
juicycleff merged commit 072e37a into main Aug 25, 2026
27 checks passed
@juicycleff
juicycleff deleted the fix/openapi-with-parameter branch August 25, 2026 21:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant