Skip to content
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

fix(spec): fix wrong query parameters #330

Merged
merged 5 commits into from
Apr 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

import org.openapitools.codegen.CodegenOperation;
import org.openapitools.codegen.languages.TypeScriptNodeClientCodegen;

import io.swagger.v3.oas.models.media.Schema;
import io.swagger.v3.oas.models.parameters.Parameter;
import io.swagger.v3.oas.models.Operation;
import io.swagger.v3.oas.models.servers.Server;

Expand All @@ -18,4 +19,12 @@ public String getName() {
public CodegenOperation fromOperation(String path, String httpMethod, Operation operation, List<Server> servers) {
return Utils.specifyCustomRequest(super.fromOperation(path, httpMethod, operation, servers));
}

@Override
protected String getParameterDataType(Parameter parameter, Schema p) {
String type = super.getParameterDataType(parameter, p);
// openapi generator is wrong, 'object' is not a fit all object, we need 'any'
// we use replace because there might be more to this type, like '| undefined'
return type.replace("{ [key: string]: object; }", "Record<string, any>");
}
}
6 changes: 3 additions & 3 deletions specs/common/schemas/CustomRequest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ PathInPath:
Parameters:
name: parameters
in: query
description: URL-encoded query string. Force some query parameters to be applied for each query made with this API key.
description: Query parameters to be applied to the current query.
schema:
type: string
example: '?query=mySearchQuery&hitsPerPage=10'
type: object
additionalProperties: true
13 changes: 10 additions & 3 deletions templates/java/libraries/okhttp-gson/api.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -119,18 +119,25 @@ public class {{classname}} extends ApiClient {
{{javaUtilPrefix}}List<Pair> queryParams = new {{javaUtilPrefix}}ArrayList<Pair>();
{{javaUtilPrefix}}Map<String, String> headers = new {{javaUtilPrefix}}HashMap<String, String>();

{{#queryParams}}
{{#vendorExtensions}}{{#queryParams}}
if ({{paramName}} != null) {
{{^x-is-custom-request}}
queryParams.addAll(this.parameterToPair("{{baseName}}", {{paramName}}));
{{/x-is-custom-request}}
{{#x-is-custom-request}}
for (Map.Entry<String, Object> parameter : parameters.entrySet()) {
queryParams.addAll(this.parameterToPair(parameter.getKey(), parameter.getValue().toString()));
}
{{/x-is-custom-request}}
}

{{/queryParams}}
{{/queryParams}}{{/vendorExtensions}}
{{#headerParams}}
if ({{paramName}} != null) {
headers.put("{{baseName}}", this.parameterToString({{paramName}}));
}

{{/headerParams}}
{{/headerParams}}
headers.put("Accept", "application/json");
headers.put("Content-Type", "application/json");

Expand Down
18 changes: 10 additions & 8 deletions templates/javascript/api-single.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,6 @@ export function create{{capitalizedApiName}}Api(options: CreateClientOptions{{#h
{{/allParams.0}}
requestOptions?: RequestOptions
) : Promise<{{{returnType}}}> {
const requestPath = '{{{path}}}'{{#vendorExtensions}}{{#pathParams}}.replace(
{{=<% %>=}}'{<%baseName%>}'<%={{ }}=%>,{{#x-is-custom-request}}String({{paramName}}){{/x-is-custom-request}}{{^x-is-custom-request}}encodeURIComponent(String({{paramName}})){{/x-is-custom-request}}
){{/pathParams}}{{/vendorExtensions}};
const headers: Headers = {};
const queryParameters: QueryParameters = {};

{{#allParams}}
{{#required}}
if ({{#isBoolean}}{{paramName}} === null || {{paramName}} === undefined{{/isBoolean}}{{^isBoolean}}!{{paramName}}{{/isBoolean}}) {
Expand All @@ -224,12 +218,20 @@ export function create{{capitalizedApiName}}Api(options: CreateClientOptions{{#h

{{/required}}
{{/allParams}}
{{#queryParams}}

const requestPath = '{{{path}}}'{{#vendorExtensions}}{{#pathParams}}.replace(
{{=<% %>=}}'{<%baseName%>}'<%={{ }}=%>,{{#x-is-custom-request}}{{paramName}}{{/x-is-custom-request}}{{^x-is-custom-request}}encodeURIComponent({{paramName}}){{/x-is-custom-request}}
){{/pathParams}}{{/vendorExtensions}};
const headers: Headers = {};
const queryParameters: QueryParameters = {{#vendorExtensions.x-is-custom-request}}parameters || {{/vendorExtensions.x-is-custom-request}}{};

{{^vendorExtensions.x-is-custom-request}}{{#queryParams}}
if ({{paramName}} !== undefined) {
queryParameters['{{baseName}}'] = {{paramName}}.toString();
}

{{/queryParams}}
{{/queryParams}}{{/vendorExtensions.x-is-custom-request}}

{{#headerParams}}
headers['{{baseName}}'] = {{paramName}};
{{/headerParams}}
Expand Down
6 changes: 3 additions & 3 deletions templates/php/api.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ use {{invokerPackage}}\RetryStrategy\ClusterHosts;
$resourcePath = '{{{path}}}';
$queryParams = [];
$httpBody = [];
{{#queryParams}}
{{#vendorExtensions}}{{#queryParams}}

{{#isExplode}}
if (${{paramName}} !== null) {
Expand All @@ -214,7 +214,7 @@ use {{invokerPackage}}\RetryStrategy\ClusterHosts;
}
}
else {
$queryParams['{{baseName}}'] = ${{paramName}};
$queryParams{{^x-is-custom-request}}['{{baseName}}']{{/x-is-custom-request}} = ${{paramName}};
}
{{/style}}
{{^style}}
Expand All @@ -230,7 +230,7 @@ use {{invokerPackage}}\RetryStrategy\ClusterHosts;
$queryParams['{{baseName}}'] = ${{paramName}};
}
{{/isExplode}}
{{/queryParams}}
{{/queryParams}}{{/vendorExtensions}}
{{#vendorExtensions}}{{#pathParams}}
// path params
{{#collectionFormat}}
Expand Down