Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
fiendish opened this issue Oct 31, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@fiendish
Copy link

fiendish commented Oct 31, 2024

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.


Workaround?

If properties are defined as (openapi 3.1 style equivalent)

  properties:
    charges:
      $ref: '#/components/schemas/Charges'
    listCharges:
      $ref: '#/components/schemas/Charges'
    retailCharges:
      $ref: '#/components/schemas/Charges'

Then this doesn't happen and things look as expected.

@fiendish fiendish added the bug Something isn't working label Oct 31, 2024
@fiendish fiendish changed the title code generation: Reused struct gets generated multiple times with different names when not appropriate code generation: Reused schema gets generated to struct multiple times with different names when not appropriate Oct 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant