From 354f195ec09293cfd731b72e67c3cc977b8c0894 Mon Sep 17 00:00:00 2001 From: Harald Fernengel Date: Tue, 28 Apr 2020 10:37:31 +0200 Subject: [PATCH] [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. --- .../languages/TypeScriptFetchClientCodegen.java | 14 ++++++++++++++ .../main/resources/typescript-fetch/apis.mustache | 5 +++++ 2 files changed, 19 insertions(+) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptFetchClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptFetchClientCodegen.java index 38b3f71ac6cc..85ac755a42c6 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptFetchClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptFetchClientCodegen.java @@ -236,9 +236,23 @@ public Map postProcessOperationsWithModels(Map o this.addOperationObjectResponseInformation(operations); this.addOperationPrefixParameterInterfacesInformation(operations); this.escapeOperationIds(operations); + this.addDeepObjectVendorExtension(operations); return operations; } + private void addDeepObjectVendorExtension(Map operations) { + Map _operations = (Map) operations.get("operations"); + List operationList = (List) _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 operations) { Map _operations = (Map) operations.get("operations"); List operationList = (List) _operations.get("operation"); diff --git a/modules/openapi-generator/src/main/resources/typescript-fetch/apis.mustache b/modules/openapi-generator/src/main/resources/typescript-fetch/apis.mustache index ace07d5b9626..39ed958da288 100644 --- a/modules/openapi-generator/src/main/resources/typescript-fetch/apis.mustache +++ b/modules/openapi-generator/src/main/resources/typescript-fetch/apis.mustache @@ -122,7 +122,12 @@ export class {{classname}} extends runtime.BaseAPI { queryParameters['{{baseName}}'] = (requestParameters.{{paramName}} as any).toISOString().substr(0,10); {{/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}}; + {{/vendorExtensions.x-codegen-isDeepObject}} {{/isDate}} {{/isDateTime}} }