ogen-go / ogen

OpenAPI v3 code generator for go
https://ogen.dev
Apache License 2.0
1.45k stars 86 forks source link

code generation: Reused schema gets generated to struct multiple times with different names when not appropriate #1338

Open fiendish opened 3 weeks ago

fiendish commented 3 weeks ago

What version of ogen are you using?

v1.6.0

Can this issue be reproduced with the latest version?

Yes

What did you do?

With an OpenAPI spec schema that looks like (trimmed down for clarity):

Result:
  type: object
  required:
    - charges
  properties:
    charges:
      allOf:
        - $ref: '#/components/schemas/Charges'
    listCharges:
      allOf:
        - $ref: '#/components/schemas/Charges'
    retailCharges:
      allOf:
        - $ref: '#/components/schemas/Charges'

What did you expect to see?

Since charges, listCharges, and retailCharges are all defined as using the same Charges schema, I expect to see only a single struct generated for the Charges schema with a single batch of set/get/etc accessors and an OptCharges wrapper for optionality

What did you see instead?

I see a bunch of unnecessarily-repeated identical structs and accessors for ResultCharges, ResultListCharges, ResultRetailCharges, and all their nested elements, and all their nested accessor methods, that all implement the same schemas but which are named after the attribute name.