Skip to content

[BUG][Kotlin] Data class is not generated anymore #19993

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

Open
5 of 6 tasks
joellportier opened this issue Oct 29, 2024 · 4 comments
Open
5 of 6 tasks

[BUG][Kotlin] Data class is not generated anymore #19993

joellportier opened this issue Oct 29, 2024 · 4 comments

Comments

@joellportier
Copy link

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

Our spec used to generated data classes, but now it generates classes without the data keyword. This happens when I have a component that has a allOf with a $ref to a supertype and no extra properties. When I have a component that has a allOf with a $ref to a supertype and an extra property it does generate a data class.

openapi-generator version

Broken in 7.9.0, it did work in 7.8.0

OpenAPI declaration file content or url
components:
  schemas:
    AssetType:
      type: string
      enum:
        - ASSET_A
        - ASSET_B
    BaseAsset:
      type: object
      required:
        - assetId
        - assetType
      properties:
        assetId:
          type: string
          format: uuid
        assetType:
          $ref: '#/components/schemas/AssetType'
      discriminator:
        propertyName: assetType
        mapping:
          ASSET_A: '#/components/schemas/AssetWithoutDataClass'
          ASSET_B: '#/components/schemas/AssetWithDataClass'
    AssetWithoutDataClass:
      allOf:
        - $ref: '#/components/schemas/BaseAsset'
        - type: object          
    AssetWithDataClass:
      allOf:
        - $ref: '#/components/schemas/BaseAsset'
        - type: object
          required:
            - number
          properties:
            number:
              type: string
              example: 'CK1924'

AssetWithDataClass now generates a data class. AssetWithoutDataClass does not generate a data class anymore, but it did in 7.8.0.

Generation Details
Steps to reproduce
Related issues/PRs
Suggest a fix
@Daredevil9999
Copy link

This seems to be originating from #19526 . The variable hasVars is true only when the generated class has properties and does not consider the base class properties.

@wing328
Copy link
Member

wing328 commented Nov 10, 2024

@jaqxues can you please have a look at this issue when you've time?

@renatosilvarosa
Copy link

I have the same issue when updating to 7.9.0. Before, the generator created data classes implementing an interface, but now it outputs simple classes. This causes problems, e.g. in tests, that were using the default field-based equals method to compare instances, which are now compared by identity and make the assertions fail.

@jaqxues
Copy link
Contributor

jaqxues commented Dec 2, 2024

I am not that deep into the OpenAPI spec and the generator. I can look at it again, but for now I think replacing the hasVars variable from #19526 with a check if the allVars is empty would solve the issue. I do not have enough experience with both to come up with edge cases for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants