diff --git a/modules/openapi-generator/src/main/resources/nim-client/api.mustache b/modules/openapi-generator/src/main/resources/nim-client/api.mustache index d80ec8281bc..77d403284dc 100644 --- a/modules/openapi-generator/src/main/resources/nim-client/api.mustache +++ b/modules/openapi-generator/src/main/resources/nim-client/api.mustache @@ -37,19 +37,19 @@ proc {{{operationId}}}*(httpClient: HttpClient{{#allParams}}, {{{paramName}}}: { httpClient.headers["Content-Type"] = "application/x-www-form-urlencoded"{{/isMultipart}}{{#isMultipart}} httpClient.headers["Content-Type"] = "multipart/form-data"{{/isMultipart}}{{/hasFormParams}}{{#hasHeaderParams}}{{#headerParams}} httpClient.headers["{{{baseName}}}"] = {{{paramName}}}{{#isArray}}.join(","){{/isArray}}{{/headerParams}}{{#description}} ## {{{.}}}{{/description}}{{/hasHeaderParams}}{{#hasQueryParams}} - let query_for_api_call = encodeQuery([{{#queryParams}} + let url_encoded_query_params = encodeQuery([{{#queryParams}} ("{{{baseName}}}", ${{{paramName}}}{{#isArray}}.join(","){{/isArray}}), # {{{description}}}{{/queryParams}} ]){{/hasQueryParams}}{{#hasFormParams}}{{^isMultipart}} - let query_for_api_call = encodeQuery([{{#formParams}} + let form_data = encodeQuery([{{#formParams}} ("{{{baseName}}}", ${{{paramName}}}{{#isArray}}.join(","){{/isArray}}), # {{{description}}}{{/formParams}} ]){{/isMultipart}}{{#isMultipart}} - let query_for_api_call = newMultipartData({ + let multipart_data = newMultipartData({ {{#formParams}} "{{{baseName}}}": ${{{paramName}}}{{#isArray}}.join(","){{/isArray}}, # {{{description}}} {{/formParams}} }){{/isMultipart}}{{/hasFormParams}}{{#returnType}} - 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}}) + 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}}) constructResult[{{{returnType}}}](response){{/returnType}}{{^returnType}} - 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}} + 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}} {{/operation}}{{/operations}} \ No newline at end of file diff --git a/samples/client/petstore/nim/petstore/apis/api_pet.nim b/samples/client/petstore/nim/petstore/apis/api_pet.nim index b2f77c2bdbb..8d53b553a3d 100644 --- a/samples/client/petstore/nim/petstore/apis/api_pet.nim +++ b/samples/client/petstore/nim/petstore/apis/api_pet.nim @@ -55,21 +55,21 @@ proc deletePet*(httpClient: HttpClient, petId: int64, apiKey: string): Response proc findPetsByStatus*(httpClient: HttpClient, status: seq[Status]): (Option[seq[Pet]], Response) = ## Finds Pets by status - let query_for_api_call = encodeQuery([ + let url_encoded_query_params = encodeQuery([ ("status", $status.join(",")), # Status values that need to be considered for filter ]) - let response = httpClient.get(basepath & "/pet/findByStatus" & "?" & query_for_api_call) + let response = httpClient.get(basepath & "/pet/findByStatus" & "?" & url_encoded_query_params) constructResult[seq[Pet]](response) proc findPetsByTags*(httpClient: HttpClient, tags: seq[string]): (Option[seq[Pet]], Response) {.deprecated.} = ## Finds Pets by tags - let query_for_api_call = encodeQuery([ + let url_encoded_query_params = encodeQuery([ ("tags", $tags.join(",")), # Tags to filter by ]) - let response = httpClient.get(basepath & "/pet/findByTags" & "?" & query_for_api_call) + let response = httpClient.get(basepath & "/pet/findByTags" & "?" & url_encoded_query_params) constructResult[seq[Pet]](response) @@ -91,21 +91,21 @@ proc updatePet*(httpClient: HttpClient, pet: Pet): (Option[Pet], Response) = proc updatePetWithForm*(httpClient: HttpClient, petId: int64, name: string, status: string): Response = ## Updates a pet in the store with form data httpClient.headers["Content-Type"] = "application/x-www-form-urlencoded" - let query_for_api_call = encodeQuery([ + let form_data = encodeQuery([ ("name", $name), # Updated name of the pet ("status", $status), # Updated status of the pet ]) - httpClient.post(basepath & fmt"/pet/{petId}", $query_for_api_call) + httpClient.post(basepath & fmt"/pet/{petId}", $form_data) proc uploadFile*(httpClient: HttpClient, petId: int64, additionalMetadata: string, file: string): (Option[ApiResponse], Response) = ## uploads an image httpClient.headers["Content-Type"] = "multipart/form-data" - let query_for_api_call = newMultipartData({ + let multipart_data = newMultipartData({ "additionalMetadata": $additionalMetadata, # Additional data to pass to server "file": $file, # file to upload }) - let response = httpClient.post(basepath & fmt"/pet/{petId}/uploadImage", multipart=query_for_api_call) + let response = httpClient.post(basepath & fmt"/pet/{petId}/uploadImage", multipart=multipart_data) constructResult[ApiResponse](response) diff --git a/samples/client/petstore/nim/petstore/apis/api_user.nim b/samples/client/petstore/nim/petstore/apis/api_user.nim index 618477db595..dbc56457d94 100644 --- a/samples/client/petstore/nim/petstore/apis/api_user.nim +++ b/samples/client/petstore/nim/petstore/apis/api_user.nim @@ -70,12 +70,12 @@ proc getUserByName*(httpClient: HttpClient, username: string): (Option[User], Re proc loginUser*(httpClient: HttpClient, username: string, password: string): (Option[string], Response) = ## Logs user into the system - let query_for_api_call = encodeQuery([ + let url_encoded_query_params = encodeQuery([ ("username", $username), # The user name for login ("password", $password), # The password for login in clear text ]) - let response = httpClient.get(basepath & "/user/login" & "?" & query_for_api_call) + let response = httpClient.get(basepath & "/user/login" & "?" & url_encoded_query_params) constructResult[string](response)