Skip to content

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

@jamietanna

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions