Skip to content

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

Closed

Description

@mromaszewicz

Problem

Under strict-server, an operation that reaches a components/responses entry through $ref (fixed status code, no headers) embeds the reusable envelope in its own response type:

type GetThing200FormdataResponse struct{ ThingFormdataResponse }

For application/x-www-form-urlencoded, the visitor passes that wrapper to runtime.MarshalForm:

form, err := runtime.MarshalForm(response, nil)

The embedded field has no form or json tag, so MarshalForm writes its fields under an empty name. A body of {value: "x"} goes on the wire as %5Bvalue%5D=x ([value]=x) instead of value=x. The JSON path already handles this case by encoding the embedded envelope (response.ThingJSONResponse); the form path does not.

Found while reviewing #2514. It reproduces on main, in every strict flavor (std-http, chi, gorilla, echo, echo5, gin, fiber, fiber-v3, iris), and for cross-package $refs through import-mapping too.

Reproduction

openapi: "3.0.3"
info: {title: t, version: "1"}
paths:
  /thing:
    get:
      operationId: getThing
      responses:
        "200":
          $ref: "#/components/responses/Thing"
components:
  schemas:
    Example:
      type: object
      properties:
        value: {type: string}
  responses:
    Thing:
      description: ok
      content:
        application/x-www-form-urlencoded:
          schema:
            $ref: "#/components/schemas/Example"

Config: generate: { models: true, std-http-server: true, strict-server: true }.

Return GetThing200FormdataResponse{ThingFormdataResponse: ThingFormdataResponse(Example{Value: &v})} with v := "x":

  • Observed body: %5Bvalue%5D=x
  • Expected body: value=x, which is what the same response declared inline produces.

Notes

  • Only form responses are affected. Text and multipart $ref responses are redeclared as the operation's type rather than embedded, and header-bearing or non-fixed-status responses already marshal response.Body.
  • The generated output has never produced a correct body, so fixing it doesn't change any output that works today.

Activity

  1. added
    bug
    on Sep 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugserver:strict

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions