OpenAPITools / OpenAPITools/openapi-generator
[REQ][Kotlin] JsonNullable Support for 'spring-kotlin'
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Is your feature request related to a problem? Please describe.
When generating an API using OpenAPI spec 3.1.0 the spring generator with Java the JsonNullable types are properly generated for properties that have either type: [string, 'null'] or anyOf - type: 'null' - ref: 'some-ref'
When changing the generation to use spring-kotlin the JsonNullable types are not generated correctly. They are generated with nullable types such as String? = null and not JsonNullable = JsonNullable.undefined()
Describe the solution you'd like
When using spring-kotlin to generate the schema with the API and using JsonNullable the proper types should be used. I would also like JsonNullable to be compatible with Jackson 3 though I realize that is another project. Currently JsonNullable is compatible with Jackson 2 and there is a workaround with Spring Boot 4.
Describe alternatives you've considered
I have implemented my own Patch class in Kotlin that handles the merge/patch logic and generate the OpenAPI spec from code. Doing this introduces undesired schemas into the spec such as Set and Ignore. Clients shouldn't have to worry about these schemas
Additional context
I've included a sample project that exhibits this behavior. If you change the generator to Spring it will generate the java classes with JsonNullable. I tried to import these classes and it causes errors when trying to use them with Kotlin. I have not found a solution there yet.
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 the attached kotlin-open-api-generator.zip and compare the classes generated by the spring and spring-kotlin generators for the nullable string and anyOf-null cases. Trace the spring-kotlin generation path and its JsonNullable handling; done means nullable properties use JsonNullable with undefined defaults and the generated Kotlin output works for the sample.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- kotlin, openapi, spring
- Domain
- api, backend, tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100