fix(analyzer): a parameter serialized with content went out style-encoded - #82
Merged
Conversation
giraffesyo
force-pushed
the
content-params
branch
from
August 20, 2026 20:22
0415bc9 to
748c961
Compare
…oded A parameter that names a media type instead of a style carries a document, and the media type says how to serialize it. convertParam read only param.Schema, so the value lost its type and was then encoded with the form style, which is not what the server parses. The media type's schema now types the parameter, and a JSON one is written as the document it declares before being percent-encoded into the query, set as a header value, or written into a cookie. Anything the generator cannot write, XML among others, warns and keeps today's encoding rather than sending JSON where the server expects something else. The name hint stays off the schema branch on purpose: a style-encoded parameter is written into the URL by the query encoder, and a synthesized union or struct there would go out as its Go shape rather than as the value the server parses.
giraffesyo
force-pushed
the
content-params
branch
from
August 20, 2026 20:59
748c961 to
6cb5ed2
Compare
This was referenced Aug 20, 2026
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.
Closes #77.
convertParamread onlyparam.Schemaand never looked atparam.Content, so the parameter lost its type and was encoded with theformstyle:Not merely awkward: a struct handed to the style encoder does not come out as the JSON document the server is parsing, so the request was wrong on the wire.
Now
The value is serialized as the media type it declares, then percent-encoded into the query. Header and cookie parameters get the same treatment through
setContentHeaderandaddContentCookieHeader.With #80 merged, the schema behind a content parameter is typed even when written inline, so
content: {application/json: {schema: {type: object, ...}}}yields a real struct rather thanany. There is a test for that composition.Decisions
Only media types the generator can write are serialized. An
application/xmlcontent parameter keeps today's style encoding and warns, rather than sending JSON where the server expects something else:The warning rides the
pkg.Warningschannel from fix(analyzer): a security scheme the generator cannot use costs the whole client #64, now also fed from an analyzer-level buffer.No name hint on the schema branch. Passing one there types inline unions and objects in style-encoded parameters, which sounds like an improvement and is not: the query encoder writes a synthesized union out as its Go shape (
value=...) rather than as the value the server parses.TestNullableUnion_QueryParamsResolveToTheVariantTypecaught it. Typed union parameters need the encoder to understand them first, which is separate work.Tests
internal/analyzer/operations_test.go: the media type and its schema reach the IR, a style parameter carries no content type, and an unserializable media type produces exactly one warning naming the parameter.internal/generator/e2e_content_param_test.go: compiles and runs againsthttptest, decoding the query parameter and the header back into the declared type, checking an inline schema is typed and serialized, that a style parameter beside it still goes out unquoted, and that an omitted optional parameter sends nothing rather thannull.gofmt,go vet ./..., andgo test ./...pass.