OpenAPITools / OpenAPITools/openapi-generator
[BUG][Kotlin] When using additional properties as an array it doesn't specify List's type correctly
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
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?
- 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 trying to specify additional properties to handle dynamic keys which will always be an array of a certain type, the generator doesn't specify the List's type correctly.
For the declaration below it generates model as following:
data class Item(val id: String, val type: String)
class Responses (
) : kotlin.collections.HashMap<String, kotlin.collections.List>()
Which is incorrect as the expected one would be something like this:
data class Item(val id: String, val type: String)
class Responses (
) : kotlin.collections.HashMap<String, kotlin.collections.List<Item>()
openapi-generator version
Gradle plugin 5.4.0
OpenAPI declaration file content or url
Responses:
type: object
additionalProperties:
type: array
items:
$ref: '#/components/schemas/Item'
Item:
type: object
properties:
id:
type: string
type:
type: string
Generation Details
Gradle generator task config
group = "dependencies"
generatorName = "kotlin"
generateAliasAsModel = false
configOptions = [
dateLibrary : "java8",
library : "multiplatform",
sourceFolder : "source/kotlin",
sortModelPropertiesByRequiredFlag: "false",
sortParamsByRequiredFlag : "false",
enumPropertyNaming : "UPPERCASE",
serializationLibrary : "jackson",
interfaceOnly : "true",
modelMutable : "false"
]
Steps to reproduce
Generate the models using the above described spec
Related issues/PRs
NA
Suggest a fix
NA
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 by reproducing the Kotlin generation with the provided OpenAPI YAML and Gradle generator configuration, then inspect the generated Responses model and the Kotlin generator entry points that handle additionalProperties. Done means the generated declaration uses kotlin.collections.List rather than a raw kotlin.collections.List, with generation still succeeding for the example.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- kotlin, openapi
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100