ogen icon indicating copy to clipboard operation
ogen copied to clipboard

Feature Request: Wrap Types with the same name

Open Daniel-Vetter-Coverwhale opened this issue 1 year ago • 0 comments

Description

Automatically wrap anonymous types with the same name.

In a schema that I'm consuming, the vendor has specified OrderId (and several other things) in all of the responses, schema, and parameters subsections of the components section of the schema. This causes ogen to error out with the following

generate:
    main.run
        /Users/daniel.vetter/src/github/ogen/cmd/ogen/main.go:304
  - build IR:
    main.generate
        /Users/daniel.vetter/src/github/ogen/cmd/ogen/main.go:64
  - make ir:
    github.com/ogen-go/ogen/gen.NewGenerator
        /Users/daniel.vetter/src/github/ogen/gen/generator.go:112
  - operations:
    github.com/ogen-go/ogen/gen.(*Generator).makeIR
        /Users/daniel.vetter/src/github/ogen/gen/generator.go:130
  - anonymous type name conflict: "OrderId":
    github.com/ogen-go/ogen/gen.(*tstorage).merge
        /Users/daniel.vetter/src/github/ogen/gen/tstorage.go:144

I tried to play around with checking a few things, but ultimately I couldn't figure out what the right changes to make were or where to make them. I think it is allowed by the OpenAPI spec to have objects in different components sections with the same name, so it would be awesome if ogen could carry some information through and perhaps provide a wrapper name for the struct based on where it came from, i.e. OrderIdResponse, OrderId, OrderIdParam or something to that effect. Where the error is being thrown though is in the types merge check, and I couldn't figure out how to determine what section the type came from in there.

For now, I've used x-ogen-name to specify the schema pieces with different names so it's not a blocker, but it does mean I'll have to go back in and manually add annotations whenever the vendor updates their OAS.

References

https://dev-devportal.sambasafety.io/references/apis/