Bug Report Checklist
Description
If I specify a field, that is "oneOf" two types, a new type is generated, which contains a superset of all fields in those two types
(or perhaps more than two) - so far correct.
However if those two types contain required fields, the generated superset type also contains required fields, probably for any field, that is required in any of oneOf types, not only for intersection (see example)
openapi-generator version
7.10
OpenAPI declaration file content or url
IrrelevantWrapperType:
type: object
required:
- oneOfField
properties:
oneOfField:
$ref: '#/components/schemas/SupersetOneOfType'
SupersetOneOfType:
type: object
oneOf:
- $ref: '#/components/schemas/TypeA'
- $ref: '#/components/schemas/TypeB'
TypeA:
type: object
required:
- fieldA
- commonField
properties:
fieldA:
type: integer
commonField:
type: integer
TypeB:
type: object
required:
- fieldB
- commonField
properties:
fieldB:
type: integer
commonField:
type: integer
Generation Details
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>${openapi-generator-maven-plugin.version}</version>
<executions>
<execution>
<id>generate-betslip-schema</id>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpecRootDirectory>${project.build.directory}/classes/oas/foo</inputSpecRootDirectory>
<generatorName>kotlin</generatorName>
<configOptions>
<library>jvm-ktor</library>
<serializationLibrary>jackson</serializationLibrary>
<modelMutable>true</modelMutable> <!-- true or false, makes no difference in this -->
<enumPropertyNaming>UPPERCASE</enumPropertyNaming>
<sourceFolder>src/main/kotlin</sourceFolder>
<additionalModelTypeAnnotations>@com.fasterxml.jackson.annotation.JsonInclude(com.fasterxml.jackson.annotation.JsonInclude.Include.NON_EMPTY)</additionalModelTypeAnnotations>
</configOptions>
<openapiNormalizer>REF_AS_PARENT_IN_ALLOF=true</openapiNormalizer>
<generateApis>false</generateApis>
<generateModelTests>false</generateModelTests>
<generateApiTests>false</generateApiTests>
<generateSupportingFiles>false</generateSupportingFiles>
<modelPackage>foo.model</modelPackage>
<packageName>foo</packageName>
<additionalProperties>removeEnumValuePrefix=false</additionalProperties>
</configuration>
</execution>
</executions>
</plugin>
Expected vs actual
Generated code:
data class SupersetOneOfType (
@field:JsonProperty("fieldA")
val fieldA: kotlin.Int, //this should be Int?
@field:JsonProperty("commonField")
val commonField: kotlin.Int, //OK to be Int!!
@field:JsonProperty("fieldB")
val fieldB: kotlin.Int //this should be Int?
)
Bug Report Checklist
Description
If I specify a field, that is "oneOf" two types, a new type is generated, which contains a superset of all fields in those two types
(or perhaps more than two) - so far correct.
However if those two types contain required fields, the generated superset type also contains required fields, probably for any field, that is required in any of oneOf types, not only for intersection (see example)
openapi-generator version
7.10
OpenAPI declaration file content or url
Generation Details
Expected vs actual
Generated code: