OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.23k stars 6.43k forks source link

[REQ][Kotlin] Support deepObject for jvm-retrofit2 #8572

Open kronstein opened 3 years ago

kronstein commented 3 years ago

Is your feature request related to a problem? Please describe.

Kotlin openapi-generator ignores style: deepObject explode: true query param options.

Spec (click to view)

``` openapi: 3.0.0 ... paths: /tags/: get: summary: Get all tags parameters: - $ref: '#/components/parameters/TagsFilter' responses: "200": description: Array of tags content: application/json: schema: type: object properties: meta: $ref: '#/components/schemas/ListMetaInfo' data: type: array items: $ref: '#/components/schemas/TagModel' "400": $ref: '#/components/responses/BadRequest' default: $ref: '#/components/responses/ServerError' ... parameters: TagsFilter: name: filter description: | Tag filter. Should be serialized as: filter[filter1name]=filter1val&filter[filter2name]=filter2val. in: query required: false schema: type: object properties: important: type: boolean description: | Important tags only. example: true style: deepObject explode: true ... ```

The output produced:

data class Filter (
    @Json(name = "important")
    val important: kotlin.Boolean? = null
)

@GET("tags/")
suspend fun tagsGet(@Query("filter") filter: Filter? = null): Response<InlineResponse2001>

Actual: https://host/tags/?filter=Filter%28important%3Dtrue%29 Expected: https://host/tags/?filter[important]=true

Describe the solution you'd like

Unfortunately, retrofit2 doesn't have advanced custom parameter type handling yet. See https://github.com/square/retrofit/issues/626 for details.

Suggested workaround:

suspend fun tagsGet(filter: Filter? = null) = tagsGet(filter?.important)

@GET("tags/")
suspend fun tagsGet(@Query("filter[important]") filterImportant: Boolean? = null): Response<InlineResponse2001>
auto-labeler[bot] commented 3 years ago

👍 Thanks for opening this issue! 🏷 I have applied any labels matching special text in your issue.

The team will review the labels and make any necessary changes.