OpenAPITools / OpenAPITools/openapi-generator
[BUG][KOTLIN] object type should not generate property of type "Any"
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 using a property of type "object" the generated code uses Kotlin type "Any" which is incorrect. This is because this would allow setting the property to any value on Kotlin side - for example a string. Setting the value to a string is though not in bounds of the given type in the spec, as an "object" should always be a list of properties and their values.
I would expect that using a type "object" generates a Map<String, Any?> as type in Kotlin instead.
openapi-generator version
7.7.0
OpenAPI declaration file content or url
openapi: 3.1.0
info:
title: ""
version: 1.0.0
paths: {}
components:
schemas:
SomeNiceClass:
type: object
properties:
someValue:
type: object
Generation Details
Language: Kotlin
Steps to reproduce
No special steps needed, just generate the model for the spec above.
Related issues/PRs
None - or at least I couldn't find one.
Suggest a fix
I can only tell that the generator for Go does this correctly and generates a map[string]interface{} for type "object".
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 generating the Kotlin model from the issue's minimal OpenAPI 3.1 declaration and inspect the generated type for SomeNiceClass.someValue. Compare the result with the requested Map<String, Any?> representation and add or update the relevant Kotlin generator coverage if the project has it. Done means an object property no longer generates as Kotlin Any while the reproduction remains valid.
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
- 42/100