Skip to content

[BUG] [kotlin-client][kotlin-spring] Discriminator is serialized twice when defined as property #21733

@dgenchev-uniper

Description

@dgenchev-uniper

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 the property used as discriminator is specified as a property within the model definitions and jackson is used as serialization library, the discriminator is serialized twice.

openapi-generator version

7.14.0

OpenAPI declaration file content or url
components:
  schemas:
    ShapeType:
      type: string
      enum:
        - TRIANGLE
        - SQUARE
    Shape:
      type: object
      required:
        - type
      properties:
        type:
          $ref: "#/components/schemas/ShapeType"
      discriminator:
        propertyName: type
        mapping:
          TRIANGLE: '#/components/schemas/Triangle'
          SQUARE: '#/components/schemas/Square'
    Triangle:
      allOf:
        - $ref: '#/components/schemas/Shape'
        - type: object
          required:
            - base
            - height
          properties:
            base:
              type: number
            height:
              type: number
    Square:
      allOf:
        - $ref: '#/components/schemas/Shape'
        - type: object
          required:
            - side
          properties:
            side:
              type: number

produces

[
    {
        "type": "TRIANGLE",
        "base": 1,
        "height": 1,
        "type": "TRIANGLE"
    },
    {
        "type": "SQUARE",
        "side": 1,
        "type": "SQUARE"
    }
]
Generation Details

Using gradle plugin

configOptions.set(
    mapOf(
        "dateLibrary" to "java8",
        "disallowAdditionalPropertiesIfNotPresent" to "false",
        "documentationProvider" to "none",
        "enumPropertyNaming" to "original",
        "exceptionHandler" to "false",
        "hideGenerationTimestamp" to "true",
        "interfaceOnly" to "true",
        "modelMutable" to "true",
        "serializationLibrary" to "jackson",
        "useSpringBoot3" to "true",
        "useTags" to "true",
    )
)
Steps to reproduce
  1. Generate using jackson as serialization library
  2. Check the JSON payload.
Related issues/PRs

Issue #9441 / PR #11691

Issue #3796

Suggest a fix

Adopt existing solution from Java / JavaSpring

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