Skip to content

[BUG] [kotlin-server] Does not create type mapping for oneOf (jaxrs-spec) #24606

Description

@rupert-jung-mw
Description

It seems like the kotlin-server generator is not creating any type mappings as JSON annotations for Jackson when using oneOf + discriminator.

OpenAPI 3.1 (snippet)

# (within Model MyService)
      properties:
        serviceDetails:
          description: "Service specific details. Identified by the serviceType discriminator."
          oneOf:
            - $ref: '#/components/schemas/ServiceA'
            - $ref: '#/components/schemas/ServiceB'
          discriminator:
            propertyName: serviceType
            mapping:
              A: '#/components/schemas/ServiceA'
              B: '#/components/schemas/ServiceB'

Configuration (Maven) looks like this:

<configuration>
    <inputSpec>myfile.openapi.yaml</inputSpec>
    <generatorName>kotlin-server</generatorName>
    <skipValidateSpec>true</skipValidateSpec>
    <output>${project.build.directory}/generated-sources</output>
    <packageName>com.testing</packageName>
    <modelPackage>com.testing.myapi.dto</modelPackage>
    <apiPackage>com.testing.myapi.api</apiPackage>
    <generateApis>true</generateApis>
    <generateApiTests>false</generateApiTests>
    <generateModelTests>false</generateModelTests>
    <generateModelDocumentation>false</generateModelDocumentation>
    <generateSupportingFiles>false</generateSupportingFiles>
    <configOptions>
        <library>jaxrs-spec</library>
        <useJakartaEe>true</useJakartaEe>
        <useSwaggerAnnotations>false</useSwaggerAnnotations>
        <sourceFolder>src/main/java</sourceFolder>
        <dateLibrary>java8</dateLibrary>
        <serializationLibrary>jackson</serializationLibrary>
        <useBeanValidation>true</useBeanValidation>
        <openApiNullable>false</openApiNullable>
        <sortModelPropertiesByRequiredFlag>true</sortModelPropertiesByRequiredFlag>
        <sortParamsByRequiredFlag>true</sortParamsByRequiredFlag>
        <interfaceOnly>true</interfaceOnly>
    </configOptions>
</configuration>

Generated classes look like this:

data class ClassA(...): ServiceTOAllOfServiceDetails
data class ClassB(...): ServiceTOAllOfServiceDetails
interface MyClassAllOfServiceDetails

But there is no JSON type info generated.
I would expect something like

@JsonTypeInfo(use = NAME, include = PROPERTY, property = "serviceType")
@JsonSubTypes(
	JsonSubTypes.Type(value = ServiceA::class, name = "A"),
	JsonSubTypes.Type(value = ServiceB::class, name = "B"),
	
)
interface ServiceDetails 

So JSON in this form cannot be parsed:

{
    // ...
    "serviceDetails": {
        "serviceType": "A",
        // ...
    }
}

Error: Cannot construct instance of ServiceTOAllOfServiceDetails ... no Creators

openapi-generator version

7.24.0

OpenAPI declaration file content or url

(See above)

Generation Details
  • Using kotlin-server generator with library `jax
Steps to reproduce

See above

Related merge requests

#22610

(I was under the impression, that this should actually work in 7.24.0)?

Thank you :)

No activity

Activity on this issue will appear here.

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