Skip to content

Commit 8a07557

Browse files
thibaudsowaThibaud SOWA
andauthored
fix(typescript-angular): fix new angular dependency cli option usage (#20247)
Co-authored-by: Thibaud SOWA <[email protected]>
1 parent 71ccc88 commit 8a07557

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+2911
-27
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
generatorName: typescript-angular
2+
outputDir: samples/client/petstore/typescript-angular-v19-with-angular-dependency-params/builds/default
3+
inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore.yaml
4+
templateDir: modules/openapi-generator/src/main/resources/typescript-angular
5+
additionalProperties:
6+
ngVersion: 19.0.1
7+
npmName: sample-angular-19-0-0-with-angular-dependency-params
8+
supportsES6: true
9+
tsVersion: 5.6.3
10+
zonejsVersion: 0.15.0
11+
ngPackagrVersion: 19.0.1
12+
rxjsVersion: 6.5.3
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
generatorName: typescript-angular
2-
outputDir: samples/client/petstore/typescript-angular-v19-provided-in-root/builds/default
2+
outputDir: samples/client/petstore/typescript-angular-v19/builds/default
33
inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore.yaml
44
templateDir: modules/openapi-generator/src/main/resources/typescript-angular
55
additionalProperties:
66
ngVersion: 19.0.0
7+
npmName: sample-angular-19-0-0
78
supportsES6: true

docs/generators/typescript-angular.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
5656
|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|
5757
|useSquareBracketsInArrayNames|Setting this property to true will add brackets to array attribute names, e.g. my_values[].| |false|
5858
|withInterfaces|Setting this property to true will generate interfaces next to the default class implementations.| |false|
59-
|zoneJsVersion|The version of zone.js compatible with Angular (see ngVersion option).| |null|
59+
|zonejsVersion|The version of zone.js compatible with Angular (see ngVersion option).| |null|
6060

6161
## IMPORT MAPPING
6262

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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public static enum PROVIDED_IN_LEVEL {none, root, any, platform}
8181
public static final String TS_VERSION = "tsVersion";
8282
public static final String RXJS_VERSION = "rxjsVersion";
8383
public static final String NGPACKAGR_VERSION = "ngPackagrVersion";
84-
public static final String ZONEJS_VERSION = "zoneJsVersion";
84+
public static final String ZONEJS_VERSION = "zonejsVersion";
8585

8686
protected String ngVersion = "19.0.0";
8787
@Getter @Setter
@@ -321,21 +321,21 @@ private void addNpmPackageGeneration(SemVer ngVersion) {
321321
.map(Map.Entry::getValue)
322322
.orElseThrow(() -> new IllegalArgumentException("Invalid ngVersion. Only Angular v9+ is supported."));
323323

324-
additionalProperties.put(TS_VERSION, additionalProperties.containsKey(TS_VERSION)
325-
? additionalProperties.containsKey(TS_VERSION)
326-
: angularDependencies.getTsVersion());
324+
if (!additionalProperties.containsKey(TS_VERSION)) {
325+
additionalProperties.put(TS_VERSION, angularDependencies.getTsVersion());
326+
}
327327

328-
additionalProperties.put(RXJS_VERSION, additionalProperties.containsKey(RXJS_VERSION)
329-
? additionalProperties.containsKey(RXJS_VERSION)
330-
: angularDependencies.getRxjsVersion());
328+
if (!additionalProperties.containsKey(RXJS_VERSION)) {
329+
additionalProperties.put(RXJS_VERSION, angularDependencies.getRxjsVersion());
330+
}
331331

332-
additionalProperties.put(NGPACKAGR_VERSION, additionalProperties.containsKey(NGPACKAGR_VERSION)
333-
? additionalProperties.containsKey(NGPACKAGR_VERSION)
334-
: angularDependencies.getNgPackagrVersion());
332+
if (!additionalProperties.containsKey(NGPACKAGR_VERSION)) {
333+
additionalProperties.put(NGPACKAGR_VERSION, angularDependencies.getNgPackagrVersion());
334+
}
335335

336-
additionalProperties.put("zonejsVersion", additionalProperties.containsKey(ZONEJS_VERSION)
337-
? additionalProperties.containsKey(ZONEJS_VERSION)
338-
: angularDependencies.getZonejsVersion());
336+
if (!additionalProperties.containsKey(ZONEJS_VERSION)) {
337+
additionalProperties.put(ZONEJS_VERSION, angularDependencies.getZonejsVersion());
338+
}
339339

340340
if (angularDependencies.getTsickleVersion() != null) {
341341
additionalProperties.put("tsickleVersion", angularDependencies.getTsickleVersion());

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
public class TypeScriptAngularClientOptionsProvider implements TypeScriptSharedClientOptionsProvider {
2626
public static final String STRING_ENUMS_VALUE = "false";
2727
private static final String NPM_REPOSITORY = "https://registry.npmjs.org";
28-
public static final String NG_VERSION = "12";
28+
public static final String NG_VERSION = "19";
2929
public static final String FILE_NAMING_VALUE = "camelCase";
3030
public static final String API_MODULE_PREFIX = "";
3131
public static final String CONFIGURATION_PREFIX = "";
@@ -37,7 +37,7 @@ public class TypeScriptAngularClientOptionsProvider implements TypeScriptSharedC
3737
public static final String MODEL_FILE_SUFFIX = "";
3838
public static final String TS_VERSION = "";
3939
public static final String RXJS_VERSION = "";
40-
public static final String NGPACKAGR_VERSION = " ";
40+
public static final String NGPACKAGR_VERSION = "";
4141
public static final String ZONEJS_VERSION = "";
4242

4343
@Override

modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/typescriptangular/TypeScriptAngularClientCodegenTest.java

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
import java.util.HashMap;
2222
import java.util.Map;
2323

24+
import static org.assertj.core.api.Assertions.assertThat;
25+
2426

2527
@Test(groups = {TypeScriptGroups.TYPESCRIPT, TypeScriptGroups.TYPESCRIPT_ANGULAR})
2628
public class TypeScriptAngularClientCodegenTest {
@@ -344,4 +346,48 @@ public void testModelNameMappings() throws Exception {
344346
"files?: Array<SystemFile>;" // ensure it's an array of SystemFile (not Any)
345347
);
346348
}
349+
350+
@Test
351+
public void testAngularDependenciesFromCliOptions() {
352+
// GIVEN
353+
OpenAPI openAPI = TestUtils.createOpenAPI();
354+
355+
TypeScriptAngularClientCodegen codegen = new TypeScriptAngularClientCodegen();
356+
codegen.additionalProperties().put("npmName", "@openapi/typescript-angular-petstore");
357+
codegen.additionalProperties().put("tsVersion", "12");
358+
codegen.additionalProperties().put("rxjsVersion", "23");
359+
codegen.additionalProperties().put("ngPackagrVersion", "34");
360+
codegen.additionalProperties().put("zonejsVersion", "45");
361+
362+
// WHEN
363+
codegen.processOpts();
364+
codegen.preprocessOpenAPI(openAPI);
365+
366+
// THEN
367+
assertThat(codegen.additionalProperties()).containsEntry("tsVersion", "12");
368+
assertThat(codegen.additionalProperties()).containsEntry("rxjsVersion", "23");
369+
assertThat(codegen.additionalProperties()).containsEntry("ngPackagrVersion", "34");
370+
assertThat(codegen.additionalProperties()).containsEntry("zonejsVersion", "45");
371+
}
372+
373+
@Test
374+
public void testAngularDependenciesFromConfigFile() {
375+
// GIVEN
376+
OpenAPI openAPI = TestUtils.createOpenAPI();
377+
378+
TypeScriptAngularClientCodegen codegen = new TypeScriptAngularClientCodegen();
379+
codegen.additionalProperties().put("npmName", "@openapi/typescript-angular-petstore");
380+
// We fix ngVersion to do not update this test on every new angular release.
381+
codegen.additionalProperties().put("ngVersion", "19.0.0");
382+
383+
// WHEN
384+
codegen.processOpts();
385+
codegen.preprocessOpenAPI(openAPI);
386+
387+
// THEN
388+
assertThat(codegen.additionalProperties()).containsEntry("tsVersion", ">=5.5.0 <5.7.0");
389+
assertThat(codegen.additionalProperties()).containsEntry("rxjsVersion", "7.4.0");
390+
assertThat(codegen.additionalProperties()).containsEntry("ngPackagrVersion", "19.0.0");
391+
assertThat(codegen.additionalProperties()).containsEntry("zonejsVersion", "0.15.0");
392+
}
347393
}

samples/client/petstore/typescript-angular-v19-provided-in-root/builds/default/.gitignore renamed to samples/client/petstore/typescript-angular-v19-with-angular-dependency-params/builds/default/.gitignore

File renamed without changes.

samples/client/petstore/typescript-angular-v19-provided-in-root/builds/default/.openapi-generator-ignore renamed to samples/client/petstore/typescript-angular-v19-with-angular-dependency-params/builds/default/.openapi-generator-ignore

File renamed without changes.

samples/client/petstore/typescript-angular-v19-provided-in-root/builds/default/.openapi-generator/FILES renamed to samples/client/petstore/typescript-angular-v19-with-angular-dependency-params/builds/default/.openapi-generator/FILES

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,8 @@ model/order.ts
1616
model/pet.ts
1717
model/tag.ts
1818
model/user.ts
19+
ng-package.json
20+
package.json
1921
param.ts
22+
tsconfig.json
2023
variables.ts

samples/client/petstore/typescript-angular-v19-provided-in-root/builds/default/.openapi-generator/VERSION renamed to samples/client/petstore/typescript-angular-v19-with-angular-dependency-params/builds/default/.openapi-generator/VERSION

File renamed without changes.

0 commit comments

Comments
 (0)