swagger-api / swagger-api/swagger-codegen
[Kotlin] Bug generating model import with --import-mappings
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
Kotlin generator generates faulty imports for models imported with --import-mappings. When I specify fully qualified class name to import via --import-mappings config, the generator prepends package from --model-package property. For the cmd below it generates this model:
package io.swagger.petstore.model
import io.swagger.petstore.model.Tag
import io.swagger.petstore.model.org.example.model.Category
/**
*
* @param id
* @param category
* @param name
* @param photoUrls
* @param tags
* @param status pet status in the store
*/
data class Pet (
val name: kotlin.String,
val photoUrls: kotlin.Array,
val id: kotlin.Long? = null,
val category: org.example.model.Category? = null,
val tags: kotlin.Array? = null,
/* pet status in the store */
val status: Pet.Status? = null
)
//..rest of the file
Swagger-codegen version
swagger-codegen-cli-2.4.12
Swagger declaration file content or url
http://petstore.swagger.io/v2/swagger.json
Command line used for generation
java -jar swagger-codegen-cli.jar generate -Dmodels \
-i http://petstore.swagger.io/v2/swagger.json \
-l kotlin-server \
-o generated \
--model-package io.swagger.petstore.model \
--import-mappings Category=org.example.model.Category
Suggest a fix/enhancement
I believe we shouldn't add imports for classes specified in --import-mappings config, so the possible workaround would be adding && !importMapping.values().contains(type) to AbstractKotlinCodegen.java#L538
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 AbstractKotlinCodegen.java around line 538 and reproduce the issue using the provided swagger-codegen-cli command with --import-mappings Category=org.example.model.Category. Check how the Kotlin generator builds imports for mapped models. Done means the generated model does not prepend --model-package to the fully qualified mapped class name.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, kotlin
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100