OpenAPITools / OpenAPITools/openapi-generator

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

Open
#19,993 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by generating Kotlin models from the YAML specification with OpenAPI Generator 7.8.0 and 7.9.0, focusing on AssetWithoutDataClass and AssetWithDataClass. Trace the Kotlin model-generation entry point to identify the regression for an allOf reference with no extra properties. Done means the no-property subtype again generates a data class while the provided reproduction remains covered by a regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
kotlin
Domain
api, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.