You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
strict-server: any-typed response bodies generate a method on an interface type, which does not compile #2525
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:
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.
Cross-linking: this is the same bug as #1328, and #2514 is an open fix for it. It wraps receiver-incompatible JSON response bodies in a struct with a Body field, the shape suggested here, across all the strict templates.
I tested that branch merged onto current main. The merge is clean, make generate produces no drift, and the full suite passes. Every shape from this issue generates the wrapper and compiles: schema: {}, type: "null", a 3.1 multi-type union, and a $ref to a named union component (it resolves the ref and classifies by the underlying schema). Its test specs are all 3.0, so the 3.1 cases aren't pinned by fixtures, but the classification handles them.
Given that, I'll hold off on a separate PR for this.
This is fixed on main by #2514 and will ship in the next release.
When a strict-server JSON response body's schema resolves to any, the response is now wrapped in a struct instead of being declared as a type over an interface:
typeGetThing200JSONResponsestruct {
Bodyany
}
The visitor encodes response.Body. This is the shape suggested in the issue.
I re-checked both cases from the report, schema: {} and type: "null", with models, std-http-server and strict-server enabled. Both generate the wrapped form, and the output compiles and passes go vet.
Activity
bendrucker commentedon Aug 19, 2026
Cross-linking: this is the same bug as #1328, and #2514 is an open fix for it. It wraps receiver-incompatible JSON response bodies in a struct with a
Bodyfield, the shape suggested here, across all the strict templates.I tested that branch merged onto current main. The merge is clean,
make generateproduces no drift, and the full suite passes. Every shape from this issue generates the wrapper and compiles:schema: {},type: "null", a 3.1 multi-type union, and a$refto a named union component (it resolves the ref and classifies by the underlying schema). Its test specs are all 3.0, so the 3.1 cases aren't pinned by fixtures, but the classification handles them.Given that, I'll hold off on a separate PR for this.
test: describe what the response_cast fixture now covers
fix: handle untyped strict response bodies (#2514)
mromaszewicz commentedon Nov 7, 2026
This is fixed on
mainby #2514 and will ship in the next release.When a strict-server JSON response body's schema resolves to
any, the response is now wrapped in a struct instead of being declared as a type over an interface:The visitor encodes
response.Body. This is the shape suggested in the issue.I re-checked both cases from the report,
schema: {}andtype: "null", withmodels,std-http-serverandstrict-serverenabled. Both generate the wrapped form, and the output compiles and passesgo vet.Closing as fixed.
This message was drafted with the help of Claude.