OpenAPITools / OpenAPITools/openapi-generator

[BUG][Kotlin] openapi 3.0.3 allOf + description + nullable = intermediate class created

Open
#18,399 0 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

7.0 had many improvements to avoid intermediate classes. However, there is a case where no intermediate class was created in 6.4.x but is in 7.4.0

openapi-generator version

openapi-generator-maven-plugin 7.2.0
generatorName: kotlin-spring
useSpringBoot3: true

OpenAPI declaration file content or url
openapi: 3.0.3
info:
  title: Swagger Petstore - OpenAPI 3.0
  version: 1.0.11
servers:
  - url: "/api"
paths:
  /user/logout:
    get:
      summary: Logs out current logged in user session
      description: ''
      operationId: logoutUser
      parameters: []
      responses:
        default:
          description: successful operation
      security:
        - api_key: []
components:
  schemas:
    A:
      type: object
      allOf:
        - $ref: '#/components/schemas/B'
        - type: object
          properties:
            propWithMissingDescription:
              allOf:
                - $ref: '#/components/schemas/SomeRef'
              description: "this comment doesn't show up on the prop (but on the intermediate class)"
              nullable: true # <-- makes that an intermediate class is created
            workaround:
              allOf:
                - type: object
                  allOf:
                    - $ref: '#/components/schemas/SomeRef'
                  description: "this comment shows up"
              nullable: true # <-- works 
    B:
      type: object
      allOf:
        - type: object
          properties:
            name:
              type: string
    SomeRef:
      type: object
      properties:
        a:
          type: string
        b:
          type: string
  securitySchemes:
    api_key:
      type: apiKey
      name: api_key
      in: header       
Generation Details
Steps to reproduce
Related issues/PRs

similar to https://github.com/OpenAPITools/openapi-generator/issues/17726

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 with the kotlin-spring generator and the supplied OpenAPI 3.0.3 declaration, reproducing the generated models for the propWithMissingDescription and workaround schemas. Compare the output to confirm whether nullable creates an intermediate class and whether the property description is retained; done means the problematic property no longer produces the unintended intermediate class while preserving its description.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.