oapi-codegen icon indicating copy to clipboard operation
oapi-codegen copied to clipboard

Generated path responses can conflict with schema definitions

Open joshprzybyszewski-wf opened this issue 5 months ago • 0 comments

Example: https://github.com/oapi-codegen/oapi-codegen/pull/2096

I noticed when using this generator that when attempting to use the "client with response", the returned type is busted. In particular, it's because there are two types with the same name: one seems to be defined in the schemas and one seems to be generated from the paths definition.

Image

Example OAS

https://github.com/joshprzybyszewski-wf/oapi-codegen/blob/jp/reproStatusConflict/examples/conflicting-fields/api.yaml#L6-L26

https://github.com/joshprzybyszewski-wf/oapi-codegen/blob/jp/reproStatusConflict/examples/conflicting-fields/api.yaml#L27-L35

How the problem appears

The presenting problem was that resp.Status gave me an IDE warning: invalid operation: cannot indirect resp.Status (value of type func() string). In reality, there are two types in the generated file with the same name:

https://github.com/joshprzybyszewski-wf/oapi-codegen/blob/jp/reproStatusConflict/examples/conflicting-fields/conflicting_fields.gen.go#L23-L27

https://github.com/joshprzybyszewski-wf/oapi-codegen/blob/jp/reproStatusConflict/examples/conflicting-fields/conflicting_fields.gen.go#L195-L207

joshprzybyszewski-wf avatar Sep 24 '25 16:09 joshprzybyszewski-wf