Skip to content

Commit

Permalink
typescript-angular: support angular 9 (OpenAPITools#5370)
Browse files Browse the repository at this point in the history
* fix code to support ng9
also render in tempate module with providers

* execute script .\bin\windows\typescript-angular-petstore-all.bat
and commit result

* re-generate samples

* remove whitespace, re-generate samples

* re-generate samples

* code cleanup

Co-authored-by: Esteban Gehring <[email protected]>
  • Loading branch information
2 people authored and MikailBag committed Mar 23, 2020
1 parent 9c1b16b commit 3dbae0d
Show file tree
Hide file tree
Showing 17 changed files with 32 additions and 1,895 deletions.
2 changes: 1 addition & 1 deletion docs/generators/typescript-angular.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ sidebar_label: typescript-angular
|modelFileSuffix|The suffix of the file of the generated model (model&lt;suffix&gt;.ts).| |null|
|modelPropertyNaming|Naming convention for the property: 'camelCase', 'PascalCase', 'snake_case' and 'original', which keeps the original name| |camelCase|
|modelSuffix|The suffix of the generated model.| |null|
|ngVersion|The version of Angular.| |8.0.0|
|ngVersion|The version of Angular.| |9.0.0|
|npmName|The name under which you want to publish generated npm package. Required to generate a full package| |null|
|npmRepository|Use this property to set an url your private npmRepo in the package.json| |null|
|npmVersion|The version of your npm package. If not provided, using the version from the OpenAPI specification file.| |1.0.0|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public class TypeScriptAngularClientCodegen extends AbstractTypeScriptClientCode
public static final String TAGGED_UNIONS = "taggedUnions";
public static final String NG_VERSION = "ngVersion";
public static final String PROVIDED_IN_ROOT = "providedInRoot";
public static final String ENFORCE_GENERIC_MODULE_WITH_PROVIDERS = "enforceGenericModuleWithProviders";
public static final String API_MODULE_PREFIX = "apiModulePrefix";
public static final String SERVICE_SUFFIX = "serviceSuffix";
public static final String SERVICE_FILE_SUFFIX = "serviceFileSuffix";
Expand All @@ -55,7 +56,7 @@ public class TypeScriptAngularClientCodegen extends AbstractTypeScriptClientCode
public static final String STRING_ENUMS = "stringEnums";
public static final String STRING_ENUMS_DESC = "Generate string enums instead of objects for enum values.";

protected String ngVersion = "8.0.0";
protected String ngVersion = "9.0.0";
protected String npmRepository = null;
private boolean useSingleRequestParameter = false;
protected String serviceSuffix = "Service";
Expand Down Expand Up @@ -123,7 +124,7 @@ public String getName() {

@Override
public String getHelp() {
return "Generates a TypeScript Angular (2.x - 7.x) client library.";
return "Generates a TypeScript Angular (2.x - 9.x) client library.";
}

@Override
Expand Down Expand Up @@ -192,6 +193,12 @@ public void processOpts() {
additionalProperties.put(PROVIDED_IN_ROOT, false);
}

if (ngVersion.atLeast("9.0.0")) {
additionalProperties.put(ENFORCE_GENERIC_MODULE_WITH_PROVIDERS, true);
} else {
additionalProperties.put(ENFORCE_GENERIC_MODULE_WITH_PROVIDERS, false);
}

additionalProperties.put(NG_VERSION, ngVersion);
additionalProperties.put("injectionToken", ngVersion.atLeast("4.0.0") ? "InjectionToken" : "OpaqueToken");
additionalProperties.put("injectionTokenTyped", ngVersion.atLeast("4.0.0"));
Expand Down Expand Up @@ -253,7 +260,9 @@ private void addNpmPackageGeneration(SemVer ngVersion) {
}

// Set the typescript version compatible to the Angular version
if (ngVersion.atLeast("8.0.0")) {
if (ngVersion.atLeast("9.0.0")) {
additionalProperties.put("tsVersion", ">=3.6.0 <3.8.0");
} else if (ngVersion.atLeast("8.0.0")) {
additionalProperties.put("tsVersion", ">=3.4.0 <3.6.0");
} else if (ngVersion.atLeast("7.0.0")) {
additionalProperties.put("tsVersion", ">=3.1.1 <3.2.0");
Expand All @@ -267,7 +276,9 @@ private void addNpmPackageGeneration(SemVer ngVersion) {
}

// Set the rxJS version compatible to the Angular version
if (ngVersion.atLeast("8.0.0")) {
if (ngVersion.atLeast("9.0.0")) {
additionalProperties.put("rxjsVersion", "6.5.3");
} else if (ngVersion.atLeast("8.0.0")) {
additionalProperties.put("rxjsVersion", "6.5.0");
} else if (ngVersion.atLeast("7.0.0")) {
additionalProperties.put("rxjsVersion", "6.3.0");
Expand Down Expand Up @@ -297,7 +308,10 @@ private void addNpmPackageGeneration(SemVer ngVersion) {
additionalProperties.put("useOldNgPackagr", !ngVersion.atLeast("5.0.0"));

// Specific ng-packagr configuration
if (ngVersion.atLeast("8.0.0")) {
if (ngVersion.atLeast("9.0.0")) {
additionalProperties.put("ngPackagrVersion", "9.0.1");
additionalProperties.put("tsickleVersion", "0.38.0");
} else if (ngVersion.atLeast("8.0.0")) {
additionalProperties.put("ngPackagrVersion", "5.4.0");
additionalProperties.put("tsickleVersion", "0.35.0");
} else if (ngVersion.atLeast("7.0.0")) {
Expand All @@ -319,6 +333,8 @@ private void addNpmPackageGeneration(SemVer ngVersion) {

// set zone.js version
if (ngVersion.atLeast("8.0.0")) {
additionalProperties.put("zonejsVersion", "0.10.2");
} else if (ngVersion.atLeast("8.0.0")) {
additionalProperties.put("zonejsVersion", "0.9.1");
} else if (ngVersion.atLeast("5.0.0")) {
// compatible versions to Angular 5+
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { {{classname}} } from './{{importPath}}';
{{/hasMore}}{{/apis}}{{/apiInfo}} {{/providedInRoot}}]
})
export class {{apiModuleClassName}} {
public static forRoot(configurationFactory: () => Configuration): ModuleWithProviders {
public static forRoot(configurationFactory: () => Configuration): ModuleWithProviders{{#enforceGenericModuleWithProviders}}<{{apiModuleClassName}}>{{/enforceGenericModuleWithProviders}} {
return {
ngModule: {{apiModuleClassName}},
providers: [ { provide: Configuration, useFactory: configurationFactory } ]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Swagger Codegen Ignore
# Generated by swagger-codegen https://github.com/swagger-api/swagger-codegen
# OpenAPI Generator Ignore
# Generated by openapi-generator https://github.com/openapitools/openapi-generator

# Use this file to prevent files from being overwritten by the generator.
# The patterns follow closely to .gitignore or .dockerignore.

# As an example, the C# client generator defines ApiClient.cs.
# You can make changes and tell Swagger Codgen to ignore just this file by uncommenting the following line:
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
#ApiClient.cs

# You can match any string of characters against a directory, file or extension with a single asterisk (*):
Expand Down
201 changes: 0 additions & 201 deletions samples/client/petstore/typescript-angular-v2/default/LICENSE

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Swagger Codegen Ignore
# Generated by swagger-codegen https://github.com/swagger-api/swagger-codegen
# OpenAPI Generator Ignore
# Generated by openapi-generator https://github.com/openapitools/openapi-generator

# Use this file to prevent files from being overwritten by the generator.
# The patterns follow closely to .gitignore or .dockerignore.

# As an example, the C# client generator defines ApiClient.cs.
# You can make changes and tell Swagger Codgen to ignore just this file by uncommenting the following line:
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
#ApiClient.cs

# You can match any string of characters against a directory, file or extension with a single asterisk (*):
Expand Down
Loading

0 comments on commit 3dbae0d

Please sign in to comment.