OpenAPITools / OpenAPITools/openapi-generator

[BUG][JAVA] {path} is URL Encoded

Open
#18,556 1 comment 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 declaring /api/1.0/projects/{projectKey}/repos/{repositorySlug}/raw/{path},
{path} is URL encoded.
Generated code is

    String localVarPath = "/rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/raw/{path}"
        .replace("{projectKey}", ApiClient.urlEncode(projectKey.toString()))
        .replace("{repositorySlug}", ApiClient.urlEncode(repositorySlug.toString()))
        .replace("{path}", ApiClient.urlEncode(path.toString()));

This mean that if I pass in
nifty_module/src/main/java/NiftyClass.java
as value for path, the final URL will be
/rest/api/1.0/projects/nifty_project/repos/nifty_repo/raw/nifty_module%2Fsrc%2Fmain%2Fjava%2FNiftyClass.java
instead of
/rest/api/1.0/projects/nifty_project/repos/nifty_repo/raw/nifty_module/src/main/java/NiftyClass.java
and in the end a 404.

Now I am the first to admit that I am not a super, duper swagger coder so maybe there is some setting or parameter that I can set to get me out of the problem. I have however not found any such information so for now I consider it a problem in the generated code.

openapi-generator version

7.3.0 and 7.5.0

OpenAPI declaration file content or url
  "/api/1.0/projects/{projectKey}/repos/{repositorySlug}/raw/{path}":
    parameters:
      - description: the parent project key
        in: path
        name: projectKey
        required: true
        type: string
      - description: the repository slug
        in: path
        name: repositorySlug
        required: true
        type: string
      - description: the file path to retrieve content from
        in: path
        name: path
        required: true
        type: string
    get:
      operationId: retrieveRawContent
      description: |-
        Retrieve the raw content for a file path at a specified revision.
         <p>
         The authenticated user must have <strong>REPO_READ</strong> permission for the specified repository to call this
         resource.
      parameters:
        - description: the commit ID or ref to retrieve the content for.
          in: query
          name: at
          required: false
          type: string
        - description: |-
            if present or <code>"true"</code>, triggers the raw content to be markup-rendered and returned
                               as HTML; otherwise, if not specified, or any value other than <code>"true"</code>, the content
                               is streamed without markup
          in: query
          name: markup
          required: false
          type: string
        - description: |-
            (Optional) Whether the markup implementation should convert newlines to breaks.
                               If not specified, {@link MarkupService} will use the value of the
                               <code>markup.render.hardwrap</code> property, which is <code>true</code> by default
          in: query
          name: hardwrap
          required: false
          type: boolean
        - description: |-
            (Optional) true if HTML should be escaped in the input markup, false otherwise.
                               If not specified, {@link MarkupService} will use the value of the
                               <code>markup.render.html.escape</code> property, which is <code>true</code> by default
          in: query
          name: htmlEscape
          required: false
          type: boolean
      responses:
        "200":
          description: Successful Response
Generation Details

The example is an extract of the REST API for BitBucket, version 1.0
Full files can be found at
https://github.com/TwoStone/bitbucket-server-api/blob/master/bitbucket-server-api.yaml
and
https://github.com/gfleury/go-bitbucket-v1/blob/master/docs/bitbucketV1-rest-swagger.yaml

Note that one file is swagger 2.0 and one is openapi 3.0; both result in the same generation.

Steps to reproduce

Run the example files using the standard maven plugin and inspect the generated code.
Just look for any operation with {path} as the a parameter.

Related issues/PRs
Suggest a fix

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

Start with the generated Java client output from the Bitbucket OpenAPI or Swagger 2.0 declarations and inspect how the Maven plugin builds localVarPath for the {path} parameter. Reproduce the issue with an operation containing a slash-separated path value, then verify that the generated request preserves the intended path segments without causing a 404.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.