OpenAPITools / OpenAPITools/openapi-generator
[BUG] [kotlin-server] Does not create type mapping for oneOf (jaxrs-spec)
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
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
https://github.com/OpenAPITools/openapi-generator/pull/22610
(I was under the impression, that this should actually work in 7.24.0)?
Thank you :)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the kotlin-server generator using the jaxrs-spec library and Jackson, reproducing the supplied OpenAPI 3.1 oneOf/discriminator specification on version 7.24.0. Compare the generated ClassA, ClassB, and ServiceTOAllOfServiceDetails output with the expected @JsonTypeInfo and @JsonSubTypes annotations; done means serviceDetails JSON parses correctly. Check related pull request 22610 before starting.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- kotlin, openapi
- Domain
- api, backend, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100