OpenAPITools / OpenAPITools/openapi-generator
[BUG] [Kotlin-Spring] Generate interface extension for Kotlin-Spring, but it still generates fields in the sub-interface that already exist in the base interface.
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Description
The language I'm using is Kotlin. I've defined two template YMLs for two interfaces, where one interface extends the other. When OpenAPI Generator processes these, it defaults to generating fields in the sub-interface that already exist in the base interface, and it does so without the 'override' keyword.
However, in Kotlin, if an interface extends a base interface, the fields from the base interface cannot be defined again in the sub-interface. Therefore, I believe OpenAPI Generator should not generate these redundant fields for my sub-interface.
openapi-generator version
7.9.0
OpenAPI declaration file content or url
As the YMLs in the following, the interface CommonSearchRequest extends BaseCommonSearchRequest by using
discriminator, allOf and ref.
- base-common-search-request.yml:
type: object
discriminator:
propertyName: requestType
required:
- requestType
- pagination
properties:
requestType:
type: string
pagination:
$ref: './request/providers/pagination.yml'
- common-search-request.yml
type: object
discriminator:
propertyName: requestType
required:
- checkInDate
- checkOutDate
allOf:
- $ref: 'base-common-search-request.yml'
- type: object
properties:
checkInDate:
type: string
format: date
example: 2024-10-19
checkOutDate:
type: string
format: date
example: 2024-10-20
- pagination.yml
type: object
required:
- offset
properties:
offset:
type: integer
minimum: 0
example: 0
limit:
type: integer
minimum: 1
example: 30
Generation Details
I used general commands for OpenAPI Generator and here are two Kotlin interfaces generated.
- BaseCommonSearchRequest:
interface BaseCommonSearchRequest {
val requestType: kotlin.String
val pagination: Pagination
}
- CommonSearchRequest:
interface CommonSearchRequest: BaseCommonSearchRequest {
val checkInDate: java.time.LocalDate
val checkOutDate: java.time.LocalDate
val requestType: kotlin.String
val pagination: Pagination
}
Expectation
For my Kotlin example, I expect CommonSearchRequest to only declare property checkInDate and checkOutDate, given that the fields requestType and pagination are inherited from the base interface and therefore should not be redefined in the sub-interface.
Due to this behavior, the compiler will show errors, and require you to manually add an override to these two properties.
Related issues/PRs
N/A
Suggest a fix
N/A
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
Reproduce the Kotlin-Spring generation with the supplied base-common-search-request.yml, common-search-request.yml, and pagination.yml files, then trace how allOf and discriminator properties are collected. Add a regression test for the generated interfaces; done means inherited requestType and pagination are not redeclared in CommonSearchRequest and the generated Kotlin compiles.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- kotlin, spring
- Domain
- backend-api-design, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100