Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #11242
Closed
Open
Issue created Jan 06, 2022 by Administrator@rootContributor5 of 6 checklist items completed5/6 checklist items

[BUG][JAVA] Path parameter encoding is using + instead of %20 for white spaces

Created by: sorin-florea

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

Path parameter encoding is using + instead of %20 for white spaces when using native library for java. The generated code is using ApiClient.urlEncode(param.toString()) which in turn uses URLEncoder.encode(s, UTF_8).

openapi-generator version

5.3.0 and master

OpenAPI declaration file content or url
openapi: 3.0.3
info:
  title: Bug reproducer
  description: API for param encoding
  version: "1.0.0"
servers:
  - url: localhost:8080
paths:
  /api/{someParam}:
    parameters:
      - in: path
        name: someParam
        schema:
          type: string
        required: true
        description: Some parameter.
    get:
      operationId: GetSomeParam
      summary: View some param
      responses:
        '200':
          description: Some return value
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SomeReturnValue'
              example:
                someParam: someValue
components:
  schemas:
    SomeReturnValue:
      type: object
      required:
        - someParam
      properties:
        someParam:
          type: string

{
  "library": "native",
  "dateLibrary": "java8",
  "modelPackage": "com.api.model",
  "apiPackage": "com.api",
  "invokerPackage": "com.api.client",
  "hideGenerationTimestamp": true,
  "openApiNullable": false,
  "useBeanValidation": false,
  "additionalModelTypeAnnotations": "@com.fasterxml.jackson.annotation.JsonInclude(com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL)"
}
Generation Details

java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -g java --library native -i openapi.yaml -o client-test

Steps to reproduce
  • generate client and call api.getSomeParam("some parameter");
  • observe that the path is http://localhost:8080/api/some+parameter
Related issues/PRs
Suggest a fix

Change encoding of path params when using the native library for java similar to okhttp implementation URLEncoder.encode(str, "utf8").replaceAll("\\+", "%20");

Assignee
Assign to
Time tracking