OpenAPITools / OpenAPITools/openapi-generator

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

Open
#8,572 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Client: Retrofit 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.

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>

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 at the jvm-retrofit2 generator entry point and compare the shown generated @Query method with the expected deepObject query. Review Retrofit issue 626 for the stated custom-parameter limitation; done means generated Kotlin serializes filter[important]=true instead of Filter(important)=true.

Written by the indexing model from the issue text.

Assessment

Tech stack
kotlin, openapi
Domain
api
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.