[BUG][KOTLIN] kotlin-server generator bug that skips imports for enum classes in Paths.kt file
Created by: svok
Bug Report Checklist
-
Have you provided a full/minimal spec to reproduce the issue? -
Have you validated the input using an OpenAPI validator (example)? -
What's the version of OpenAPI Generator used? -
Have you search for related issues/PRs? -
What's the actual output vs expected output? -
[Optional] Bounty to sponsor the fix (example)
Description
The full sample project is published in https://github.com/svok/openapi-test
The bug concerns kotlin-server (KTOR) generator.
The main bug consequence is a lucking import declaration for the enum class in the Paths.kt file that causes Unresolved reference: SomeStatus
error message.
openapi-generator version
4.2.3
OpenAPI declaration file content or url
Full declaration is over there: https://github.com/svok/openapi-test/blob/master/spec.yaml
The code causing error is following:
/pet/findByStatus:
get:
tags:
- pet
parameters:
- name: status
in: query
schema:
type: array
items:
$ref: '#/components/schemas/SomeStatus'
components:
schemas:
SomeStatus:
type: string
default: available
enum:
- available
- pending
- sold
Command line used for generation
The complete set of the parameters can be foun in the generateKotlinModels
task of the https://github.com/svok/openapi-test/blob/master/build.gradle.kts file.
Steps to reproduce
To reproduce the error you need to start:
./gradlew generateKotlinModels
After that you can find in Paths.kt
file:
@KtorExperimentalLocationsAPI
@Location("/pet/findByStatus") class findPetsByStatus(val status: kotlin.Array<SomeStatus>)
where SomeStatus
is undeclared
The extra lines to be included into the file:
import org.example.rest.models.SomeStatus
NOTE! The same declaration in kotlin/org/example/rest/models/Pet.kt
contains import for SomeStatus, but there it is not required.
Related issues/PRs
Not found
Suggest a fix
Right now I have no idea. The bug may relate to the following file: https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/resources/kotlin-server/libraries/ktor/Paths.kt.mustache