-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- Have you tested with the latest master to confirm the issue still exists? (used with maven not CLI)
- 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 OpenApi specification contains 'allOf' combined with multiple '$ref' generation is broken. Please see example bellow:
openapi-generator version
7.2.0
OpenAPI declaration file content or url
openapi: 3.0.1
info:
title: aaa
version: 1.0.0
contact:
name: "aaa"
url: "https://aaa.com"
email: "aaaa@gmail.com"
description: "aaa"
servers:
- url: http://localhost:8080/
description: Local development
tags:
- name: my_tag
paths:
/some/get:
get:
tags:
- my_tag
summary: aa
description: aa
operationId: aa
responses:
'200':
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/MyResponse'
security:
- default: []
components:
schemas:
MyResponse:
type: object
allOf:
- $ref: '#/components/schemas/MyResponseBase'
- type: object
properties:
code:
type: string
status:
allOf:
- $ref: '#/components/schemas/StatusEnum'
anotherParam:
allOf:
- $ref: '#/components/schemas/AnotherParam'
MyResponseBase:
type: object
properties:
whatever:
type: string
AnotherParam:
type: object
properties:
whatever:
type: string
StatusEnum:
type: string
enum:
- A
- B
- C
securitySchemes:
default:
type: http
scheme: basicGeneration Details
Sorry maven for me, not a cli :(
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>7.2.0<version>
<executions>
<execution>
<id>generate-client</id>
<goals><goal>generate</goal></goals>
<phase>process-resources</phase>
<configuration>
<inputSpec>${specs.dir}${spec.yaml.file}</inputSpec>
<generatorName>kotlin</generatorName>
<configOptions>
<library>jvm-spring-webclient</library>
<dateLibrary>java8</dateLibrary>
<modelMutable>false</modelMutable>
<serializableModel>false</serializableModel>
<serializationLibrary>jackson</serializationLibrary>
<enumPropertyNaming>original</enumPropertyNaming>
<useSpringBoot3>false</useSpringBoot3>
</configOptions>
<generateApis>true</generateApis>
<generateApiDocumentation>false</generateApiDocumentation>
<generateApiTests>false</generateApiTests>
<generateSupportingFiles>true</generateSupportingFiles>
<generateModelTests>false</generateModelTests>
<generateModelDocumentation>false</generateModelDocumentation>
</configuration>
</execution>
</executions>
</plugin>Steps to reproduce
Use mvn plugin as above
It generated following classes:

MyResponse.kt
data class MyResponse (
@field:JsonProperty("whatever")
val whatever: kotlin.String? = null,
@field:JsonProperty("code")
val code: kotlin.String? = null,
@field:JsonProperty("status")
val status: MyResponseAllOfStatus? = null,
@field:JsonProperty("anotherParam")
val anotherParam: MyResponseAllOfAnotherParam? = null
)It is using some <class-name>AllOf<parameterName> parameters instead of actual parameters/classes, I hope it is not intentional as they are generated again for every class, which would cause so much mapping from one to another in code.
MyResponseAllOfStatus.kt
data class MyResponseAllOfStatus (
)
It is generating empty data class instead of enum for AllOf enum reference. (code can't even compile thanks to this).
MyResponseAllOfAnotherParam.kt is the same as AnotherParam.kt (only difference is name)
MyResponseBase.kt was generated correctly
Related issues/PRs
I think at least those issues are related:
#17534
#17551
#17542
Suggest a fix
As I went through release notes, I suggest this PR is responsible: #17141