OpenAPITools / OpenAPITools/openapi-generator
[REQ] Kotlin: Support array responses
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.
The actual implementation with moshi dont support array responses
[
{"text": "hello"},
{"text": "hello"}
]
Describe the solution you'd like
To parse a JSON array to a list, moshi recommand this approach in order get a List
val listType = Types.newParameterizedType(List::class.java, Person::class.java)
val adapter: JsonAdapter<List<Person>> = moshi.adapter(listType)
val result = adapter.fromJson(reader)
I think modifing the ApiClient.mustache and the method responseBody would be necesarry
Describe alternatives you've considered
Another fix that i have in my mind would be to create a wrapper for the array response, and create this wrapper inside Kotlin client.
something like this:
{"response": [
{"text": "hello"},
{"text": "hello"}
]}
And then return the response as a result of the responseBody inside ApiClient.mustache
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 Kotlin ApiClient.mustache template and its responseBody method. Trace how an array response is converted into a Moshi adapter, then verify that a generated Kotlin client can deserialize the example JSON array into a List; done means array responses work without requiring a wrapper object.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- kotlin
- Domain
- api, tooling
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100