Skip to content

Commit 17a08d2

Browse files
fixes OpenAPITools#18489: provide support of array attributes in multipart/form-data request for angular typescript client (OpenAPITools#18490)
1 parent 86f23e1 commit 17a08d2

4 files changed

Lines changed: 7 additions & 3 deletions

File tree

docs/generators/typescript-angular.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
5050
|supportsES6|Generate code that conforms to ES6.| |false|
5151
|taggedUnions|Use discriminators to create tagged unions instead of extending interfaces.| |false|
5252
|useSingleRequestParameter|Setting this property to true will generate functions with a single argument containing all API endpoint parameters instead of one argument per parameter.| |false|
53+
|useSquareBracketsInArrayNames|Setting this property to true will add brackets to array attribute names, e.g. my_values[].| |false|
5354
|withInterfaces|Setting this property to true will generate interfaces next to the default class implementations.| |false|
5455

5556
## IMPORT MAPPING

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptAngularClientCodegen.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ public static enum PROVIDED_IN_LEVEL {none, root, any, platform}
7575
public static final String STRING_ENUMS = "stringEnums";
7676
public static final String STRING_ENUMS_DESC = "Generate string enums instead of objects for enum values.";
7777
public static final String QUERY_PARAM_OBJECT_FORMAT = "queryParamObjectFormat";
78+
public static final String USE_SQUARE_BRACKETS_IN_ARRAY_NAMES = "useSquareBracketsInArrayNames";
7879

7980
protected String ngVersion = "17.0.0";
8081
@Getter @Setter
@@ -142,6 +143,7 @@ public TypeScriptAngularClientCodegen() {
142143
this.cliOptions.add(new CliOption(FILE_NAMING, "Naming convention for the output files: 'camelCase', 'kebab-case'.").defaultValue(this.fileNaming));
143144
this.cliOptions.add(new CliOption(STRING_ENUMS, STRING_ENUMS_DESC).defaultValue(String.valueOf(this.stringEnums)));
144145
this.cliOptions.add(new CliOption(QUERY_PARAM_OBJECT_FORMAT, "The format for query param objects: 'dot', 'json', 'key'.").defaultValue(this.queryParamObjectFormat.name()));
146+
this.cliOptions.add(CliOption.newBoolean(USE_SQUARE_BRACKETS_IN_ARRAY_NAMES, "Setting this property to true will add brackets to array attribute names, e.g. my_values[].", false));
145147
}
146148

147149
@Override

modules/openapi-generator/src/main/resources/typescript-angular/api.service.mustache

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -342,16 +342,16 @@ export class {{classname}} {
342342
if ({{paramName}}) {
343343
{{#isCollectionFormatMulti}}
344344
{{paramName}}.forEach((element) => {
345-
localVarFormParams = localVarFormParams.append('{{baseName}}', <any>element) as any || localVarFormParams;
345+
localVarFormParams = localVarFormParams.append('{{baseName}}{{#useSquareBracketsInArrayNames}}[]{{/useSquareBracketsInArrayNames}}', <any>element) as any || localVarFormParams;
346346
})
347347
{{/isCollectionFormatMulti}}
348348
{{^isCollectionFormatMulti}}
349349
if (localVarUseForm) {
350350
{{paramName}}.forEach((element) => {
351-
localVarFormParams = localVarFormParams.append('{{baseName}}', <any>element) as any || localVarFormParams;
351+
localVarFormParams = localVarFormParams.append('{{baseName}}{{#useSquareBracketsInArrayNames}}[]{{/useSquareBracketsInArrayNames}}', <any>element) as any || localVarFormParams;
352352
})
353353
} else {
354-
localVarFormParams = localVarFormParams.append('{{baseName}}', [...{{paramName}}].join(COLLECTION_FORMATS['{{collectionFormat}}'])) as any || localVarFormParams;
354+
localVarFormParams = localVarFormParams.append('{{baseName}}{{#useSquareBracketsInArrayNames}}[]{{/useSquareBracketsInArrayNames}}', [...{{paramName}}].join(COLLECTION_FORMATS['{{collectionFormat}}'])) as any || localVarFormParams;
355355
}
356356
{{/isCollectionFormatMulti}}
357357
}

modules/openapi-generator/src/test/java/org/openapitools/codegen/options/TypeScriptAngularClientOptionsProvider.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ public Map<String, String> createOptions() {
9494
.put(CodegenConstants.DISALLOW_ADDITIONAL_PROPERTIES_IF_NOT_PRESENT, "true")
9595
.put(TypeScriptAngularClientCodegen.QUERY_PARAM_OBJECT_FORMAT, QUERY_PARAM_OBJECT_FORMAT_VALUE)
9696
.put(CodegenConstants.ENUM_UNKNOWN_DEFAULT_CASE, ENUM_UNKNOWN_DEFAULT_CASE_VALUE)
97+
.put(TypeScriptAngularClientCodegen.USE_SQUARE_BRACKETS_IN_ARRAY_NAMES, Boolean.FALSE.toString())
9798
.build();
9899
}
99100

0 commit comments

Comments
 (0)