OpenAPITools / OpenAPITools/openapi-generator
[REQ] [Kotlin] Consistent API methods return types
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Greets!
Is your feature request related to a problem? Please describe.
In our services, we have some endpoints that are returning an optional class, and some that are not.
Currently, the default behaviour of the generator is to map all endpoint methods to non-nullable classes. This is problematic because it might potentially cause an NPE on the caller's side.
We found an option called nullableReturnType (that was implemented in #4422) but that makes all API method responses nullable. This makes it a bit inconvenient from the caller's point of view because they have to always check if the returned object is null, even if the original method cannot return null by definition.
Describe the solution you'd like
Can we have another option in the config file? When set, the generated client's return types will be consistent with the actual return types:
- if the service returns a non-nullable object from a method
foo, the generated client will return a non-nullable object for the generatedfoo - if the service returns a nullable object from a method
bar, the generated client will return a nullable object for the generatedbar
cc @dacloutier
Thank you!
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 tracing the existing nullableReturnType configuration and the implementation referenced in #4422. Compare how generated Kotlin client methods represent nullable and non-nullable service responses, then define configuration behavior that preserves each endpoint's actual return type without making every response nullable.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- kotlin, openapi
- Domain
- api, tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100