Skip to content

[BUG] [kotlin-spring] allOf with single $ref loses sibling example in fromProperty #23335

Description

@oszust002

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator?
  • 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

When a property uses allOf with a single $ref and has a sibling example, the generated code loses the example value. The @Schema annotation emits example = "null" (the literal string) instead of the actual example value from the spec.

This worked correctly in 6.x.

Actual output:

@Schema(example = "null", description = "Current status of the item.")
@get:JsonProperty("status") val status: StatusEnum? = null

The example becomes the literal string "null" instead of "ACTIVE".

Expected output:

@Schema(example = "ACTIVE", description = "Current status of the item.")
@get:JsonProperty("status") val status: StatusEnum? = null
openapi-generator version

Tested on 7.12.0 and 7.18.0. Worked correctly on 6.3.0.

OpenAPI declaration file content or url
openapi: 3.0.1
info:
  title: Test API
  version: 1.0.0
paths:
  /test:
    get:
      operationId: getTest
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TestDTO'
components:
  schemas:
    TestDTO:
      type: object
      properties:
        status:
          description: Current status of the item.
          allOf:
            - $ref: '#/components/schemas/StatusEnum'
          example: ACTIVE
    StatusEnum:
      type: string
      enum: [ACTIVE, INACTIVE, PENDING]
      description: Status type.
      example: ACTIVE
Generation Details
openapi-generator-cli generate -i spec.yaml -g kotlin-spring -o output

Using kotlin-spring generator with interfaceOnly: true, useSpringBoot3: true.

Steps to reproduce
  1. Generate code with the spec above using openapi-generator 7.12.0+
  2. Check the generated TestDTO.kt
Related issues/PRs
Suggest a fix

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      Sponsor
      SponsoredKunjungi sekarang
      Promo