strict-server: any-typed response bodies generate a method on an interface type, which does not compile
Les mainteneurs répondent en général sous 1 jour
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 3/5
- Temps estimé
- 1-2 jours
- Accessibilité débutants
- 55/100
Piste de recherche
The issue is in the strict-server code generation when a response schema lowers to any. Look at the generator code for strict-server responses, likely in pkg/codegen/templates.go or similar. The fix involves modifying the template to wrap interface/pointer underlying types in a struct (e.g., type GetThing200JSONResponse struct { Body any }) instead of generating a method directly on the any type. Test with the provided YAML spec and config to ensure the output compiles.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
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:
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:
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 marshalingresponse.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-typeto a concrete type), but generating something that works seems strictly better.
- Langage dominant
- Go
- Étoiles
- 8.6k
- Forks
- 1.1k
- Merge moyen
- 14 h 45 min
- PR mergées (30 j)
- 29
Préparer son environnement
- Aucun Dockerfile ni fichier Docker Compose
- Aucun modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de oapi-codegen/oapi-codegen
-
v2.8.0: identical schemas with the same x-go-type-name now fail with "duplicate typename"Peut-être pris @eyoshioka l’a pris il y a 3 jours. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 84/100
oapi-codegen/oapi-codegen#2599 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
Render `x-stability-level` in GodocPeut-être pris @Anandb71 l’a pris il y a 5 jours. Ouverteclient
Difficulté 2/5 1-3 heures Accessibilité débutants 70/100
oapi-codegen/oapi-codegen#2483 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 65/100
oapi-codegen/oapi-codegen#2408 ·
Les mainteneurs répondent en général sous 1 jour
-
Use constants from net/http for the status codesPeut-être pris @mromaszewicz l’a pris il y a 127 jours. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 70/100
oapi-codegen/oapi-codegen#2397 · 3 commentaires ·
Les mainteneurs répondent en général sous 1 jour
-
documentation
Difficulté 2/5 1-3 heures Accessibilité débutants 65/100
oapi-codegen/oapi-codegen#2168 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
Toutes les issues de oapi-codegen/oapi-codegen
Issues similaires
-
bug frontend good first issue
Difficulté 2/5 1-3 heures Accessibilité débutants 86/100
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 1/5 Moins d'une heure Accessibilité débutants 82/100
oalders/clodhopper#133 ·
-
Difficulté 2/5 1-3 heures Accessibilité débutants 62/100
peasant-labs/peasant#596 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
hatchet-dev/hatchet#5179 ·
Les mainteneurs répondent en général sous 1 jour
-
bug triage
Difficulté 2/5 1-3 heures Accessibilité débutants 62/100
FairwindsOps/nova#484 ·