OpenAPITools / OpenAPITools/openapi-generator

[BUG] kotlin-spring does not play well with Any type

Open
#14,137 2 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
Description

A structure accepting any valid JSON described at https://swagger.io/docs/specification/data-models/data-types/#any generates unusable Model code.

Example:

components:
  schemas:
    AnyValue:
      description: Accepts any valid JSON value
      anyOf:
        - type: string
        - type: number
        - type: integer
        - type: boolean
        - type: array
          items:
            $ref: "#/components/schemas/AnyValue"
        - type: object
          additionalProperties: true

gets translated to

/**
 * Accepts any valid JSON value
*/
@javax.annotation.Generated
class AnyValueDto(

) {

}
openapi-generator version

6.2.2

OpenAPI declaration file content or url
components:
  schemas:
    AnyValue:
      description: Accepts any valid JSON value
      anyOf:
        - type: string
        - type: number
        - type: integer
        - type: boolean
        - type: array
          items:
            $ref: "#/components/schemas/AnyValue"
        - type: object
          additionalProperties: true
Generation Details
Steps to reproduce

Generate code using the described schema.

Related issues/PRs
Suggest a fix

A complex combination anyOf should be translated to Any (Java Object) and should not try to generate custom empty Model class.

It should generate the same code as

components:
  schemas:
    AnyValue: { }

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 with the kotlin-spring generator and reproduce the issue using the AnyValue schema from the report. Trace how its complex anyOf schema is mapped during model generation; done means the generated Kotlin code represents arbitrary JSON as Any or Java Object rather than an empty AnyValueDto model.

Written by the indexing model from the issue text.

Assessment

Tech stack
kotlin, spring
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.