OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.86k stars 6.59k forks source link

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

Open joellportier opened 2 weeks ago

joellportier commented 2 weeks ago

Bug Report Checklist

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 commented 5 days ago

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 commented 5 days ago

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