Skip to content

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

@kronstein

Description

@kronstein

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 square/retrofit#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>

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions