Skip to content

Redeclared Types when model name matches client endpoint id response name #1474

Closed

Description

@hackerrdave

When generating types,client for the openai openapi spec, I see many errors similar to this example:

Duplicate types

// CreateChatCompletionResponse Represents a chat completion response returned by model, based on the provided input.
type CreateChatCompletionResponse struct {
	// Choices A list of chat completion choices. Can be more than one if `n` is greater than 1.
	Choices []struct {
		// FinishReason The reason the model stopped generating tokens. This will be `stop` if the model hit a natural stop point or a provided stop sequence,
		// `length` if the maximum number of tokens specified in the request was reached,
		// `content_filter` if content was omitted due to a flag from our content filters,
		// `tool_calls` if the model called a tool, or `function_call` (deprecated) if the model called a function.
		FinishReason CreateChatCompletionResponseChoicesFinishReason `json:"finish_reason"`

		// Index The index of the choice in the list of choices.
		Index int `json:"index"`

                //etc...
}

//...

type CreateChatCompletionResponse struct {
	Body         []byte
	HTTPResponse *http.Response
	JSON200      *CreateChatCompletionResponse // name here matches both types
}

Error:

CreateChatCompletionResponse redeclared in this block 

I believe this occurs when the schema for an operation's response has the same name as the generated name for <OperationId>Response, this is the yaml in question:

/chat/completions:
    post:
      operationId: createChatCompletion
      tags:
        - Chat
      summary: Creates a model response for the given chat conversation.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/CreateChatCompletionRequest"
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/CreateChatCompletionResponse"

Is there an expected flag to use to workaround this? Or is this a bug?

Activity

  1. pvanbuijtene commented on Feb 26, 2024

    @pvanbuijtene

    I had the same and would see this as a bug, end-users should not have to worry about this.
    You can work around it by setting a response type suffix in you config, like this:

    output-options:
      response-type-suffix: Resp
    
  2. jamietanna commented on Mar 25, 2024

    @jamietanna
    Member

    Interesting! Yeah this looks like a bug. Glad there's a workaround in the meantime - I'll get it officially documented in #1254 - but an ideal solution would be to detect when there may be a clash, and rename the generated response type

  3. added
    bug
    on Mar 25, 2024
  4. rostislaved commented on Sep 24, 2025

    @rostislaved

    Hi @jamietanna,

    Any update on this?

    Response was the most obvious template for naming these models. So I was surprised when I faced this issue

  5. mromaszewicz commented on Mar 2, 2026

    @mromaszewicz
    Member

    This was addressed in #2213, please enable name conflict resolution via the output options and file a new issue if it doesn't work for you

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

    bughas-workaround

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions