OpenAPITools / OpenAPITools/openapi-generator

[REQ] Kotlin: Support array responses

Open
#2,986 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Enhancement: Feature
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.