Skip to content

Non-Existent Types Referenced by Response Schema #636

Closed as not planned
Closed as not planned

Description

@linden

I'm not sure why but sometimes generated type GetExampleResponse struct {}s reference non-existent types whose names start with a status code (illegal to have a type start with a digit so this refuses to format). This is only happening when the Schema type lacks a Title, so I'm guessing it's something to do with the substitution.

type GetExampleResponse struct {
	Body         []byte
	HTTPResponse *http.Response
	JSON200      *struct {
		Limit   int                 `json:"limit"`
		Offset  int                 `json:"offset"`
		Results []200_Results_Item `json:"results"`
		Total   int                 `json:"total"`
	}
}

Here's a simplified example of what it looks like, notice the Results field references a (non-existent) type named 200_Results_Item.
I'm trying to generate a wrapper around this spec, let me know if you need more information.

Activity

  1. jamietanna commented on Jun 28, 2022

    @jamietanna
    Member

    I think this is the same as I saw in #626, which appears to mirror your issue

  2. alexpyc commented on Mar 11, 2024

    @alexpyc

    Not sure if my issue is related to this one: #1496

  3. added this to the v2.6.0 milestone on Nov 28, 2024
  4. mromaszewicz commented on Apr 21, 2026

    @mromaszewicz
    Member

    Closing as stale — this appears to have been resolved by subsequent work.

    Reproduction attempt (2026-04): A minimal spec mirroring the report (inline response object, nested results array of inline objects, no Title on any schema) now generates a valid anonymous struct:

    type GetExampleResponse struct {
        Body         []byte
        HTTPResponse *http.Response
        JSON200      *struct {
            Limit   int `json:"limit"`
            Offset  int `json:"offset"`
            Results []struct {
                Name  string `json:"name"`
                Value int    `json:"value"`
            } `json:"results"`
            Total   int `json:"total"`
        }
    }

    Compiles and passes gofmt — no 200_Results_Item-style reference.

    Why it no longer reproduces: Two independent guards now prevent the broken output:

    1. Inline nested schemas in response bodies are emitted as anonymous struct{} literals, so no generated name is needed.
    2. If a name were synthesized from a status code, typeNamePrefix in pkg/codegen/utils.go prepends N whenever the first character is a digit (added in Fix/handle initial digit of operation #735, four months after this was filed).

    If anyone still sees this on a current version, please open a new issue with a minimal spec that reproduces it.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions