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.97k stars 6.59k forks source link

[BUG][Java][restclient,resttemplate,webclient] `explode` not applied to array values inside a parameter object #20126

Open wacker opened 1 week ago

wacker commented 1 week ago

Bug Report Checklist

Description

explode: true does not cause array values to be exploded when given inside a parameter object, as it does using the native or apache-httpclient library.

Example: PagingParams = { sort: [ 'amount,desc', 'name,asc'] } -- a typical Pageable object in Spring Web

Generated query string using library restclient ,resttemplate or webclient: ❌ /api/search?sort=amount,desc,name,asc

Generated query string using library native or apache-httpclient: ✅ /api/search?sort=amount,desc&sort=name,asc

openapi-generator version

v7.9.0

OpenAPI declaration file content or url
openapi: 3.0.3
info: { title: API, version: 1.0.0 }
paths:
  /api/search:
    get:
      parameters:
        - in: query
          name: PagingParams
          schema: { $ref: '#/components/schemas/PagingParams' }
          style: form
          explode: true
      responses:
        200: { description: OK }
components:
  schemas:
    PagingParams:
      type: object
      properties:
        page: { type: integer, format: int32, minimum: 0 }
        size: { type: integer, format: int32, minimum: 1 }
        sort: { type: array, items: { type: string } }
Generation Details

✅ generated DefaultApi.java using library native or apache-httpclient:

localVarQueryParams.addAll(ApiClient.parameterToPairs("multi", "sort", pagingParams.getSort()));

❌ generated DefaultApi.java using library restclient or webclient

queryParams.putAll(apiClient.parameterToMultiValueMap(null, "sort", pagingParams.getSort()));

❌ generated DefaultApi.java using using library resttemplate

localVarQueryParams.putAll(apiClient.parameterToMultiValueMap(null, "sort", pagingParams.getSort()));
Steps to reproduce
openapi-generator-cli generate -g java -i api-spec.yaml -o out-native --library native