openapi-generator icon indicating copy to clipboard operation
openapi-generator copied to clipboard

[BUG] [Java][RestTemplate][WebClient] Fix incorrect generation query parameter with deepObject, pipeDelimited and spaceDelimited

Open jorgerod opened this issue 2 years ago • 3 comments

Bug Report Checklist

  • [x] Have you provided a full/minimal spec to reproduce the issue?
  • [x] Have you validated the input using an OpenAPI validator (example)?
  • [x] Have you tested with the latest master to confirm the issue still exists?
  • [x] Have you searched for related issues/PRs?
  • [x] What's the actual output vs expected output?
  • [ ] [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

Java RestTemplate and Java Webclient generator don't support deepObject, spaceDelimited or pipeDelimited in query and the generated requests do not take into account the explode field.

Following the documentation, the generated urls are not correct.

style explode URI template Array id = [3, 4, 5] Object id = {"role": "admin", "firstName": "Alex"}
spaceDelimited true /users{?id*} /users?id=3&id=4&id=5 n/a
spaceDelimited false n/a /users?id=3%204%205 n/a
pipeDelimited true /users{?id*} /users?id=3&id=4&id=5 n/a
pipeDelimited false n/a /users?id=3|4|5 n/a
deepObject true n/a n/a /users?id[role]=admin&id[firstName]=Alex
openapi-generator version

5.4.0 and 6.4.0

OpenAPI declaration file content or url
openapi: 3.0.0
info:
  description: >-
    This spec is mainly for testing Petstore server and contains fake endpoints,
    models. Please do not use this for any other purpose. Special characters: "
    \
  version: 1.0.0
  title: OpenAPI Petstore
  license:
    name: Apache-2.0
    url: 'https://www.apache.org/licenses/LICENSE-2.0.html'
tags:
  - name: pet
    description: Everything about your Pets
paths:
  '/pet6/other':
    get:
      tags:
        - pet
      summary: Find pet by ID
      description: Returns a single pet, Test array as parameter spaceDelimited, explode
      operationId: getPet6
      parameters:
        - name: status
          in: query
          required: true
          style: spaceDelimited
          explode: true
          schema:
            type: array
            items:
              type: string
              enum:
                - available
                - pending
                - sold
              default: available
      responses:
        '200':
          description: successful operation
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Pet'
  '/pet7/other':
    get:
      tags:
        - pet
      summary: Find pet by ID
      description: Returns a single pet, Test array as parameter spaceDelimited, not explode
      operationId: getPet7
      parameters:
        - name: status
          in: query
          required: true
          style: spaceDelimited
          explode: false
          schema:
            type: array
            items:
              type: string
              enum:
                - available
                - pending
                - sold
              default: available
      responses:
        '200':
          description: successful operation
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Pet'
  '/pet8/other':
    get:
      tags:
        - pet
      summary: Find pet by ID
      description: Returns a single pet, Test array as parameter pipeDelimited, explode
      operationId: getPet8
      parameters:
        - name: status
          in: query
          required: true
          style: pipeDelimited
          explode: true
          schema:
            type: array
            items:
              type: string
              enum:
                - available
                - pending
                - sold
              default: available
      responses:
        '200':
          description: successful operation
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Pet'
  '/pet9/other':
    get:
      tags:
        - pet
      summary: Find pet by ID
      description: Returns a single pet, Test array as parameter pipeDelimited, not explode
      operationId: getPet9
      parameters:
        - name: status
          in: query
          required: true
          style: pipeDelimited
          explode: false
          schema:
            type: array
            items:
              type: string
              enum:
                - available
                - pending
                - sold
              default: available
      responses:
        '200':
          description: successful operation
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Pet'
  '/pet10/other':
    get:
      tags:
        - pet
      summary: Find pet by ID
      description: Returns a single pet, Test object as parameter deepObject, explode
      operationId: getPet10
      parameters:
        - name: category
          in: query
          required: true
          style: deepObject
          explode: true
          schema:
            $ref: '#/components/schemas/Category'
      responses:
        '200':
          description: successful operation
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Pet'
servers:
  - url: 'http://{server}.swagger.io:{port}/v2'
    description: petstore server
components:
  requestBodies:
    Pet:
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Pet'
      description: Pet object that needs to be added to the store
      required: true
  schemas:
    Pet:
      type: object
      required:
        - name
        - photoUrls
      properties:
        id:
          type: integer
          format: int64
        name:
          type: string
          example: doggie
        status:
          type: string
          description: pet status in the store
          enum:
            - available
            - pending
            - sold
    Category:
      type: object
      required:
        - name
      properties:
        id:
          type: integer
          format: int64
        name:
          type: string
          default: default-name

Generation Details

java -jar openapi-generator-cli.jar generate -g java -i openapi-rest.yml -o openapi --library resttemplate java -jar openapi-generator-cli.jar generate -g java -i openapi-rest.yml -o openapi --library webclient

Steps to reproduce
style explode expected url actual url Result
spaceDelimited true /projectkeyRestServiceOpenApi/pet6/other?status=pending&status=sold /projectkeyRestServiceOpenApi/pet6/other?status=available%20sold KO
spaceDelimited false /projectkeyRestServiceOpenApi/pet7/other?status=pending%20sold /projectkeyRestServiceOpenApi/pet7/other?status=available%20sold OK
pipeDelimited true /projectkeyRestServiceOpenApi/pet8/other?status=available&status=pending /projectkeyRestServiceOpenApi/pet8/other?status=available%7Csold KO
pipeDelimited false /projectkeyRestServiceOpenApi/pet9/other?status=available|sold /projectkeyRestServiceOpenApi/pet9/other?status=available%7Csold OK
deepObject true /projectkeyRestServiceOpenApi/pet10/other?category%5Bname%5D=default-name&category%5Bid%5D=6 /projectkeyRestServiceOpenApi/pet10/other?category=class%20CategoryDTO%20%7B%0A%20%20%20%20id:%202%0A%20%20%20%20name:%20catName%0A%7D KO
Related issues/PRs
  • https://github.com/OpenAPITools/openapi-generator/issues/14691
  • https://github.com/OpenAPITools/openapi-generator/issues/13658
  • https://github.com/OpenAPITools/openapi-generator/issues/11697
  • https://github.com/OpenAPITools/openapi-generator/issues/11707
  • https://github.com/OpenAPITools/openapi-generator/issues/11401

jorgerod avatar Feb 22 '23 08:02 jorgerod

@jorgerod can you try the native, apache-httpclient, which should have better support for query parameters?

wing328 avatar Feb 22 '23 17:02 wing328

Can this be escalated?

dscalzi avatar Aug 23 '23 18:08 dscalzi

Hi @wing328

Sorry for the confusion, in this other issue I answered you.

It also does not work in the cases you mentioned. I think this issue has been stopped for a long time and should be taken up again.

Thank you very much, best regards

jorgerod avatar Jun 03 '25 11:06 jorgerod