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

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

Open thoroughsoft opened this issue 1 year ago • 1 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?
  • [x] [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

thoroughsoft avatar May 02 '24 16:05 thoroughsoft

Same issue reported here https://github.com/OAI/OpenAPI-Specification/issues/892#issuecomment-281681728

stefan521 avatar May 10 '24 20:05 stefan521