Skip to content

Generate anonymous objects when generate: models #1512

Closed

Description

@jamietanna
openapi: "3.0.0"
info:
  version: 1.0.0
  title: Generate models
paths:
  /client:
    get:
      operationId: getClient
      responses:
        200:
          content:
            application/json:
              schema:
                # NOTE that Client is generated here, because it's within #/components/schemas
                $ref: "#/components/schemas/Client"
    put:
      operationId: updateClient
      responses:
        400:
          content:
            application/json:
              # NOTE that this anonymous object is /not/ generated because it's an anonymous 
              schema:
                type: object
                properties:
                  code:
                    type: string
                required:
                - code
components:
  schemas:
    Client:
      type: object
      required:
        - name
      properties:
        name:
          type: string

Should this result in the anonymous type being generated?

Activity

  1. jamietanna commented on Mar 25, 2024

    @jamietanna
    MemberAuthor

    (May be a duplicate)

  2. added
    enhancement
    on Mar 25, 2024
  3. magnusp commented on Nov 21, 2024

    @magnusp

    I've seen codegens utilize the schema title attribute to name the model

  4. magicmark commented on Jan 14, 2025

    @magicmark

    Would very much appreciate this, yes!

  5. pezzer55 commented on Feb 27, 2025

    @pezzer55

    I just came across this from the docs trying to figure out how to name anonymous types. It would seem to already be handled using x-go-type-name. E.g. the following will generate a type 'UpdateResponse'

        put:
          operationId: updateClient
          responses:
            400:
              content:
                application/json:
                  schema:
                    type: object
                    x-go-type-name: UpdateResponse
                    properties:
                      code:
                        type: string
                    required:
                    - code
  6. mromaszewicz commented on Feb 7, 2026

    @mromaszewicz
    Member

    Anonymous inline schemas can be given named types using the x-go-type-name extension. This is by design — schemas under components/schemas get named types, inline schemas are anonymous unless annotated.

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

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions