Skip to content

docs(client): how to handle duplicate names in generated types #1965

Closed

Description

@jamietanna

For posterity, this still can occur when using the Client generation, i.e.:

internal/endoflifedate/client/client.gen.go:976:6: ProductResponse redeclared in this block
        internal/endoflifedate/client/client.gen.go:187:6: other declaration of ProductResponse
internal/endoflifedate/client/client.gen.go:984:7: r.HTTPResponse undefined (type ProductResponse has no field or method HTTPResponse)

From code:

// ProductReleaseResponse A response containing a release cycle.
type ProductReleaseResponse struct {
	// Result Full information about a product release cycle.
	Result ProductRelease `json:"result"`

	// SchemaVersion Version of this schema.
	SchemaVersion string `json:"schema_version"`
}

// ClientWithResponsesInterface is the interface specification for the client with responses above.
type ClientWithResponsesInterface interface {

	// ProductReleaseWithResponse request
	ProductReleaseWithResponse(ctx context.Context, product string, release string, reqEditors ...RequestEditorFn) (*ProductReleaseResponse, error)
}

type ProductReleaseResponse struct {
	Body         []byte
	HTTPResponse *http.Response
	JSON200      *ProductReleaseResponse
}

// Status returns HTTPResponse.Status
func (r ProductReleaseResponse) Status() string {
	if r.HTTPResponse != nil {
		return r.HTTPResponse.Status
	}
	return http.StatusText(0)
}

This can be overridden when using output-options.response-type-suffix:

# yaml-language-server: $schema=https://raw.githubusercontent.com/oapi-codegen/oapi-codegen/v2.4.1/configuration-schema.json
# ...
output-options:
  response-type-suffix: Resp

I'll look at getting this more prominently documented.

Originally posted by @jamietanna in #386

Activity

  1. added this to the v2.5.0 milestone on May 4, 2025
  2. self-assigned this
    on May 4, 2025
  3. added a commit that references this issue on Jul 15, 2025
    6840334
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions