Hacktoberfest 2026 : les issues que les mainteneurs ont marquées pour octobre, ouvertes et accessibles aux débutants. Parcourir les issues Hacktoberfest

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

Ouverte
#2,525 1 commentaire 0 réactions 0 personnes assignées Voir sur GitHub

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
Type d'issue
Bug
Clarté
Clairement spécifiée
Activité
Calme
Stack technique
go
Domaine
api, backend

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 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.
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

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de oapi-codegen/oapi-codegen

Toutes les issues de oapi-codegen/oapi-codegen

Issues similaires

Plus d'issues Go

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.