[typescript-fetch] Support deepObject query params (#6075)

deepObject query parameters need to be specially marshalled.
Unfortunately, they're quite tricky to distinguish in mustache because
there's no boolean property for deepObject, so add a vendorExtension
property to ease the mustache template.
This commit is contained in:
Harald Fernengel 2020-04-28 10:37:31 +02:00 committed by GitHub
parent 3d5b140c3d
commit 354f195ec0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 0 deletions

View File

@ -236,9 +236,23 @@ public class TypeScriptFetchClientCodegen extends AbstractTypeScriptClientCodege
this.addOperationObjectResponseInformation(operations); this.addOperationObjectResponseInformation(operations);
this.addOperationPrefixParameterInterfacesInformation(operations); this.addOperationPrefixParameterInterfacesInformation(operations);
this.escapeOperationIds(operations); this.escapeOperationIds(operations);
this.addDeepObjectVendorExtension(operations);
return operations; return operations;
} }
private void addDeepObjectVendorExtension(Map<String, Object> operations) {
Map<String, Object> _operations = (Map<String, Object>) operations.get("operations");
List<CodegenOperation> operationList = (List<CodegenOperation>) _operations.get("operation");
for (CodegenOperation op : operationList) {
for (CodegenParameter param : op.queryParams) {
if (param.style != null && param.style.equals("deepObject")) {
param.vendorExtensions.put("x-codegen-isDeepObject", true);
}
}
}
}
private void escapeOperationIds(Map<String, Object> operations) { private void escapeOperationIds(Map<String, Object> operations) {
Map<String, Object> _operations = (Map<String, Object>) operations.get("operations"); Map<String, Object> _operations = (Map<String, Object>) operations.get("operations");
List<CodegenOperation> operationList = (List<CodegenOperation>) _operations.get("operation"); List<CodegenOperation> operationList = (List<CodegenOperation>) _operations.get("operation");

View File

@ -122,7 +122,12 @@ export class {{classname}} extends runtime.BaseAPI {
queryParameters['{{baseName}}'] = (requestParameters.{{paramName}} as any).toISOString().substr(0,10); queryParameters['{{baseName}}'] = (requestParameters.{{paramName}} as any).toISOString().substr(0,10);
{{/isDate}} {{/isDate}}
{{^isDate}} {{^isDate}}
{{#vendorExtensions.x-codegen-isDeepObject}}
queryParameters['{{baseName}}'] = runtime.querystring(requestParameters.{{paramName}} as unknown as runtime.HTTPQuery, '{{baseName}}');
{{/vendorExtensions.x-codegen-isDeepObject}}
{{^vendorExtensions.x-codegen-isDeepObject}}
queryParameters['{{baseName}}'] = requestParameters.{{paramName}}; queryParameters['{{baseName}}'] = requestParameters.{{paramName}};
{{/vendorExtensions.x-codegen-isDeepObject}}
{{/isDate}} {{/isDate}}
{{/isDateTime}} {{/isDateTime}}
} }