Skip to content

Commit 118ac7b

Browse files
sandwoodKJacobOJ
authored andcommitted
Fix nim code generation (#20752)
Same variable name declared multiple times in the same scope. => nim generated code does not compile.
1 parent 218602d commit 118ac7b

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

modules/openapi-generator/src/main/resources/nim-client/api.mustache

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,19 @@ proc {{{operationId}}}*(httpClient: HttpClient{{#allParams}}, {{{paramName}}}: {
3737
httpClient.headers["Content-Type"] = "application/x-www-form-urlencoded"{{/isMultipart}}{{#isMultipart}}
3838
httpClient.headers["Content-Type"] = "multipart/form-data"{{/isMultipart}}{{/hasFormParams}}{{#hasHeaderParams}}{{#headerParams}}
3939
httpClient.headers["{{{baseName}}}"] = {{{paramName}}}{{#isArray}}.join(","){{/isArray}}{{/headerParams}}{{#description}} ## {{{.}}}{{/description}}{{/hasHeaderParams}}{{#hasQueryParams}}
40-
let query_for_api_call = encodeQuery([{{#queryParams}}
40+
let url_encoded_query_params = encodeQuery([{{#queryParams}}
4141
("{{{baseName}}}", ${{{paramName}}}{{#isArray}}.join(","){{/isArray}}), # {{{description}}}{{/queryParams}}
4242
]){{/hasQueryParams}}{{#hasFormParams}}{{^isMultipart}}
43-
let query_for_api_call = encodeQuery([{{#formParams}}
43+
let form_data = encodeQuery([{{#formParams}}
4444
("{{{baseName}}}", ${{{paramName}}}{{#isArray}}.join(","){{/isArray}}), # {{{description}}}{{/formParams}}
4545
]){{/isMultipart}}{{#isMultipart}}
46-
let query_for_api_call = newMultipartData({
46+
let multipart_data = newMultipartData({
4747
{{#formParams}} "{{{baseName}}}": ${{{paramName}}}{{#isArray}}.join(","){{/isArray}}, # {{{description}}}
4848
{{/formParams}}
4949
}){{/isMultipart}}{{/hasFormParams}}{{#returnType}}
5050

51-
let response = httpClient.{{{httpMethod}}}(basepath & {{^pathParams}}"{{{path}}}"{{/pathParams}}{{#hasPathParams}}fmt"{{{path}}}"{{/hasPathParams}}{{#hasQueryParams}} & "?" & query_for_api_call{{/hasQueryParams}}{{#hasBodyParam}}{{#bodyParams}}, $(%{{{paramName}}}){{/bodyParams}}{{/hasBodyParam}}{{#hasFormParams}}, {{^isMultipart}}$query_for_api_call{{/isMultipart}}{{#isMultipart}}multipart=query_for_api_call{{/isMultipart}}{{/hasFormParams}})
51+
let response = httpClient.{{{httpMethod}}}(basepath & {{^pathParams}}"{{{path}}}"{{/pathParams}}{{#hasPathParams}}fmt"{{{path}}}"{{/hasPathParams}}{{#hasQueryParams}} & "?" & url_encoded_query_params{{/hasQueryParams}}{{#hasBodyParam}}{{#bodyParams}}, $(%{{{paramName}}}){{/bodyParams}}{{/hasBodyParam}}{{#hasFormParams}}, {{^isMultipart}}$form_data{{/isMultipart}}{{#isMultipart}}multipart=multipart_data{{/isMultipart}}{{/hasFormParams}})
5252
constructResult[{{{returnType}}}](response){{/returnType}}{{^returnType}}
53-
httpClient.{{{httpMethod}}}(basepath & {{^pathParams}}"{{{path}}}"{{/pathParams}}{{#hasPathParams}}fmt"{{{path}}}"{{/hasPathParams}}{{#hasQueryParams}} & "?" & query_for_api_call{{/hasQueryParams}}{{#hasBodyParam}}{{#bodyParams}}, $(%{{{paramName}}}){{/bodyParams}}{{/hasBodyParam}}{{#hasFormParams}}, {{^isMultipart}}$query_for_api_call{{/isMultipart}}{{#isMultipart}}multipart=query_for_api_call{{/isMultipart}}{{/hasFormParams}}){{/returnType}}
53+
httpClient.{{{httpMethod}}}(basepath & {{^pathParams}}"{{{path}}}"{{/pathParams}}{{#hasPathParams}}fmt"{{{path}}}"{{/hasPathParams}}{{#hasQueryParams}} & "?" & url_encoded_query_params{{/hasQueryParams}}{{#hasBodyParam}}{{#bodyParams}}, $(%{{{paramName}}}){{/bodyParams}}{{/hasBodyParam}}{{#hasFormParams}}, {{^isMultipart}}$form_data{{/isMultipart}}{{#isMultipart}}multipart=multipart_data{{/isMultipart}}{{/hasFormParams}}){{/returnType}}
5454

5555
{{/operation}}{{/operations}}

samples/client/petstore/nim/petstore/apis/api_pet.nim

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,21 +55,21 @@ proc deletePet*(httpClient: HttpClient, petId: int64, apiKey: string): Response
5555

5656
proc findPetsByStatus*(httpClient: HttpClient, status: seq[Status]): (Option[seq[Pet]], Response) =
5757
## Finds Pets by status
58-
let query_for_api_call = encodeQuery([
58+
let url_encoded_query_params = encodeQuery([
5959
("status", $status.join(",")), # Status values that need to be considered for filter
6060
])
6161

62-
let response = httpClient.get(basepath & "/pet/findByStatus" & "?" & query_for_api_call)
62+
let response = httpClient.get(basepath & "/pet/findByStatus" & "?" & url_encoded_query_params)
6363
constructResult[seq[Pet]](response)
6464

6565

6666
proc findPetsByTags*(httpClient: HttpClient, tags: seq[string]): (Option[seq[Pet]], Response) {.deprecated.} =
6767
## Finds Pets by tags
68-
let query_for_api_call = encodeQuery([
68+
let url_encoded_query_params = encodeQuery([
6969
("tags", $tags.join(",")), # Tags to filter by
7070
])
7171

72-
let response = httpClient.get(basepath & "/pet/findByTags" & "?" & query_for_api_call)
72+
let response = httpClient.get(basepath & "/pet/findByTags" & "?" & url_encoded_query_params)
7373
constructResult[seq[Pet]](response)
7474

7575

@@ -91,21 +91,21 @@ proc updatePet*(httpClient: HttpClient, pet: Pet): (Option[Pet], Response) =
9191
proc updatePetWithForm*(httpClient: HttpClient, petId: int64, name: string, status: string): Response =
9292
## Updates a pet in the store with form data
9393
httpClient.headers["Content-Type"] = "application/x-www-form-urlencoded"
94-
let query_for_api_call = encodeQuery([
94+
let form_data = encodeQuery([
9595
("name", $name), # Updated name of the pet
9696
("status", $status), # Updated status of the pet
9797
])
98-
httpClient.post(basepath & fmt"/pet/{petId}", $query_for_api_call)
98+
httpClient.post(basepath & fmt"/pet/{petId}", $form_data)
9999

100100

101101
proc uploadFile*(httpClient: HttpClient, petId: int64, additionalMetadata: string, file: string): (Option[ApiResponse], Response) =
102102
## uploads an image
103103
httpClient.headers["Content-Type"] = "multipart/form-data"
104-
let query_for_api_call = newMultipartData({
104+
let multipart_data = newMultipartData({
105105
"additionalMetadata": $additionalMetadata, # Additional data to pass to server
106106
"file": $file, # file to upload
107107
})
108108

109-
let response = httpClient.post(basepath & fmt"/pet/{petId}/uploadImage", multipart=query_for_api_call)
109+
let response = httpClient.post(basepath & fmt"/pet/{petId}/uploadImage", multipart=multipart_data)
110110
constructResult[ApiResponse](response)
111111

samples/client/petstore/nim/petstore/apis/api_user.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,12 @@ proc getUserByName*(httpClient: HttpClient, username: string): (Option[User], Re
7070
7171
proc loginUser*(httpClient: HttpClient, username: string, password: string): (Option[string], Response) =
7272
## Logs user into the system
73-
let query_for_api_call = encodeQuery([
73+
let url_encoded_query_params = encodeQuery([
7474
("username", $username), # The user name for login
7575
("password", $password), # The password for login in clear text
7676
])
7777

78-
let response = httpClient.get(basepath & "/user/login" & "?" & query_for_api_call)
78+
let response = httpClient.get(basepath & "/user/login" & "?" & url_encoded_query_params)
7979
constructResult[string](response)
8080

8181

0 commit comments

Comments
 (0)