Skip to content

Bug: path parameter should be encoded #131

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Thiry1 opened this issue Mar 1, 2024 · 2 comments · Fixed by #132
Closed

Bug: path parameter should be encoded #131

Thiry1 opened this issue Mar 1, 2024 · 2 comments · Fixed by #132
Labels
Type: Bug Something isn't working

Comments

@Thiry1
Copy link
Contributor

Thiry1 commented Mar 1, 2024

Because the path parameters are not encoded, passing values containing '/' or '?' will result in the destination path becoming unintended. I guess we shoulld encode the path parameters using encodeURIComponent.

Steps To Reproduce

// generated code
export const createClient = <RequestOption>(apiClient: ApiClient<RequestOption>, baseUrl: string) => {
    const _baseUrl = baseUrl.replace(/\/$/, "");
    return {
        getBook: (params: Params$getBook, option?: RequestOption): Promise<Response$getBook$Status$200["application/json"]> => {
            const url = _baseUrl + `/get/book/${params.parameter.id}`;
            const headers = {
                Accept: "application/json"
            };
            return apiClient.request({
                httpMethod: "GET",
                url,
                headers
            }, option);
        },
    }
}
const client = createClient(something);
client.getBook({
  params: {
    parameter: {
      id: "foo/bar" // params contains `/`
    },
  }
})

The current behavior

request to /get/book/foo/bar

The expected behavior

request to /get/book/foo%2Fbar

@Thiry1 Thiry1 added the Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug label Mar 1, 2024
@Himenon Himenon added Type: Bug Something isn't working and removed Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug labels Mar 1, 2024
@Himenon
Copy link
Owner

Himenon commented Mar 1, 2024

@Thiry1

Thanks for the bug report! I checked the Document and found that this is a responsibility that should be held on the generated code side.

https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#path-templating

@Thiry1
Copy link
Contributor Author

Thiry1 commented Mar 1, 2024

Thank you for the quick fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Something isn't working
Projects
None yet
2 participants