Skip to content

fix: marshal a reusable form response's envelope, not its wrapper - #2587

Merged
mromaszewicz merged 1 commit into
oapi-codegen:mainfrom
mromaszewicz:fix/strict-form-ref-envelope
Sep 27, 2026
Merged

mromaszewicz merged 1 commit into
oapi-codegen:mainfrom
mromaszewicz:fix/strict-form-ref-envelope

Conversation

@mromaszewicz

Copy link
Copy Markdown
Member

What was wrong. A strict-server operation that reaches a components/responses entry through $ref, with a fixed status code and no headers, embeds the reusable envelope in its response struct (type Op200FormdataResponse struct{ ThingFormdataResponse }). The JSON visitor encodes the embedded envelope, but the form visitor passed the wrapper to runtime.MarshalForm. The embedded field has no tag, so its fields went on the wire under an empty name: %5Bvalue%5D=x instead of value=x. This happened in every strict flavor, and for cross-package $refs as well.

What changed. The form branch in strict-interface.tmpl, strict-fiber-interface.tmpl and strict-iris-interface.tmpl marshals response.<Envelope> for a $ref response, exactly as the JSON branch encodes it. The external case uses the envelope's unqualified name, which is the embedded field's name. Only the body of a form $ref visitor changes, and that output has never produced a correct body.

How it's tested.

  • The shared strict fixture (internal/test/servers/strict) gains a ReusableURLEncodedResponse operation that answers with a reusable form response. A wire test asserts the body is value=zxcv for chi, echo, echo5, gin, iris, fiber-v3 (strict_test.go), fiber and std-http. On main every one of them sends %5Bvalue%5D=zxcv.
  • TestStrictReusableFormResponseMarshalsEnvelope pins the visitor for local and cross-package $refs, with an inline control, across the standard, Fiber and Iris templates. It fails on main.
  • A scratch cross-package build (a base package plus an import-mapped consumer) sends value=x on this branch and the empty-name body on main.
  • Compared generated output from main and this branch across 71 specs × 15 configs (every strict flavor plus nullable-type, old-aliasing, old-allof-sibling-merging, schema-merging v1/v3, custom content-type tags). Of 1065 outputs, the only differences are the MarshalForm line of form $ref visitors, and no output's compile status changes.
  • make generate changes no other committed file. make test and make lint pass, and the strict fixtures pass under Go 1.25.

Fixes #2586

🤖 Generated with Claude Code

An operation that reaches a components/responses entry through $ref,
with a fixed status code and no headers, embeds the reusable envelope
in its own response struct. For JSON the visitor encodes the embedded
envelope, but for application/x-www-form-urlencoded it passed the
wrapper to runtime.MarshalForm. The embedded field has no tag, so its
fields went on the wire under an empty name: "%5Bvalue%5D=x" instead of
"value=x". Cross-package $refs had the same problem.

Marshal the embedded envelope, as the JSON path does, in the standard,
Fiber and Iris strict templates.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@mromaszewicz mromaszewicz added the bug Something isn't working label Sep 27, 2026
@mromaszewicz
mromaszewicz requested a review from a team as a code owner September 27, 2026 22:40
@greptile-apps

greptile-apps Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 4/5

[Medium risk] Adds a new API endpoint for form-encoded responses.

The PR appears safe to merge; the remaining feedback is a non-blocking fixture-documentation improvement.

Summary

The PR corrects strict-server serialization of reusable URL-encoded responses by marshaling their embedded response envelope rather than the operation wrapper.

  • Updates the standard, Fiber, and Iris strict templates.
  • Adds a shared response fixture, generated outputs, and wire and generator regression tests.

Reviews (1) · Last reviewed commit: "fix: marshal a reusable form response's ..."

@mromaszewicz
mromaszewicz merged commit 4ac6e94 into oapi-codegen:main Sep 27, 2026
16 checks passed
@mromaszewicz
mromaszewicz deleted the fix/strict-form-ref-envelope branch September 27, 2026 23:14
mromaszewicz added a commit to mromaszewicz/oapi-codegen that referenced this pull request Sep 27, 2026
Brings in oapi-codegen#2587 (a reusable form response's envelope is marshalled, not
its wrapper) and oapi-codegen#2589 (types from an imported document qualify only
their model names).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

strict-server: a form response reached through $ref is encoded under an empty field name

1 participant