strict-server: any-typed response bodies generate a method on an interface type, which does not compile

Author: mromaszewiczCreated Aug 16, 2026Updated Aug 19, 2026

Found during the review of #2522; pre-existing on main and independent of that PR.

Problem

Under strict-server, a JSON response body whose schema lowers to any generates a defined type with an interface underlying type, plus a value-receiver method on it:

go
type GetThing200JSONResponse any

func (response GetThing200JSONResponse) VisitGetThingResponse(w http.ResponseWriter) error {

Go forbids methods on types whose underlying type is a pointer or interface, so the output does not compile:

invalid receiver type GetThing200JSONResponse (pointer or interface type)

Reproduction

Verified on main with:

yaml
paths:
  /things:
    get:
      operationId: getThing
      responses:
        "200":
          description: ok
          content:
            application/json:
              schema: {}

and config generate: { models: true, std-http-server: true, strict-server: true }. The same happens for type: "null" (#2430) and, once #2522 lands, for multi-type unions (type: [string, number]) — every schema shape that lowers to any.

Notes

  • Non-strict servers are unaffected; only the strict envelope needs a method on the response type.
  • Since this output has never compiled, there are no existing users of the current shape — the fix is free to choose the right one. The obvious candidate is wrapping the body in a struct for interface-underlying response types (e.g. type GetThing200JSONResponse struct { Body any }, with the visitor marshaling response.Body), mirroring how strict response envelopes with headers already wrap. Alternatively the generator could error on this combination with a pointer at the workaround (x-go-type to a concrete type), but generating something that works seems strictly better.

Source: oapi-codegen/oapi-codegen