OpenAPITools / OpenAPITools/openapi-generator

[BUG][JAVA][apache-httpclient] doesn't handle pipe (|) in parameter names

Open
#15,010 0 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

When using a specification that includes the | symbol in parameter names, the resultant code is confused (interprets it as a regexp) and ends up trying to use an invalid uri.

openapi-generator version

Encountered the issue with 6.4.0.

OpenAPI declaration file content or url
swagger: '2.0'
paths:
  /jobs/{jobname}/{jobgroupname|jobgroupID}:
    get:
      summary: View job by name
      description: Display the details and properties associated with a specific job. To retrieve jobs by name, you must specify a `jobGroupName` or `jobGroupId`
      operationId: getJob
      tags:
        - Jobs
      parameters:
      - name: jobname
        in: path
        required: true
        type: string
      - name: jobgroupname|jobgroupID
        in: path
        required: true
        type: string
      responses:
        200:
          description: Job response
          schema:
            $ref: '#/definitions/GetJob'
Generation Details

Using the gradle plugin as follows:

openApiGenerate {
    generatorName = "java"
    library = "apache-httpclient" 
    inputSpec = "$rootDir/src/main/openapi/managerOpenAPI.yaml"
    apiPackage = "test.api"
    invokerPackage = "test.client"
    modelPackage = "test.model" 
}
Steps to reproduce

Generate api client as above. Use generated code to call the given endpoint. Results in an invalid url being created, eg:

https://HOSTNAME/jobs/testJob/testJobGroup|testJobGroup

instead of the expected:

https://HOSTNAME/jobs/testJob/testJobGroup

Related issues/PRs
Suggest a fix

I believe the issue is caused by the use of 'replaceAll' here:

https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/resources/Java/libraries/apache-httpclient/api.mustache#L107

which is interpreting the first argument as a regular expression, not a string.

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

Inspect modules/openapi-generator/src/main/resources/Java/libraries/apache-httpclient/api.mustache at the linked replaceAll call. Generate the Java client with the provided OpenAPI declaration and apache-httpclient library, then call the endpoint containing the pipe in its parameter name. Done means the generated URI matches the expected path without the pipe being treated as a regular-expression pattern.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.