OpenAPITools / OpenAPITools/openapi-generator

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

Open
#14,790 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Bug Report Checklist
  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • 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

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

Reproduce the issue with the supplied OpenAPI declaration and the Java generator commands for the RestTemplate and WebClient libraries. Start by tracing how query parameters are generated for the five example operations, then compare the generated URLs with the expected URLs for each style and explode setting. Done means both libraries correctly handle deepObject, spaceDelimited, and pipeDelimited query parameters.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi
Domain
api, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.