Skip to content

Commit 4f5d67c

Browse files
author
Dennis Ameling
committed
[typescript] make TypeScript version configurable
1 parent 7bce639 commit 4f5d67c

16 files changed

Lines changed: 24 additions & 14 deletions

File tree

docs/generators/typescript.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
4242
|sortModelPropertiesByRequiredFlag|Sort model properties to place required parameters before optional parameters.| |true|
4343
|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true|
4444
|supportsES6|Generate code that conforms to ES6.| |false|
45+
|typescriptMajorVersion|Specify the major version of TypeScript to use in the client code. Default is 5.| |5|
4546
|useInversify|Enable this to generate decorators and service identifiers for the InversifyJS inversion of control container. If you set 'deno' as 'platform', the generator will process this value as 'disable'.| |false|
4647
|useObjectParameters|Use aggregate parameter objects as function arguments for api operations instead of passing each parameter as a separate function argument.| |false|
4748
|useRxJS|Enable this to internally use rxjs observables. If disabled, a stub is used instead. This is required for the 'angular' framework.| |false|

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ public class TypeScriptClientCodegen extends AbstractTypeScriptClientCodegen imp
7676
private static final String USE_OBJECT_PARAMS_SWITCH = "useObjectParameters";
7777
private static final String USE_OBJECT_PARAMS_DESC = "Use aggregate parameter objects as function arguments for api operations instead of passing each parameter as a separate function argument.";
7878

79+
protected static final String TYPESCRIPT_MAJOR_VERSION_SWTICH = "typescriptMajorVersion";
80+
private static final String TYPESCRIPT_MAJOR_VERSION_DESC = "Specify the major version of TypeScript to use in the client code. Default is 5.";
81+
7982
private final Map<String, String> frameworkToHttpLibMap;
8083

8184
// NPM Options
@@ -87,6 +90,9 @@ public class TypeScriptClientCodegen extends AbstractTypeScriptClientCodegen imp
8790
protected String snapshot = null;
8891
protected ENUM_PROPERTY_NAMING_TYPE enumPropertyNaming = ENUM_PROPERTY_NAMING_TYPE.PascalCase;
8992

93+
@Getter @Setter
94+
protected String typescriptMajorVersion = "5";
95+
9096
private final DateTimeFormatter iso8601Date = DateTimeFormatter.ISO_DATE;
9197
private final DateTimeFormatter iso8601DateTime = DateTimeFormatter.ISO_DATE_TIME;
9298

@@ -119,6 +125,7 @@ public TypeScriptClientCodegen() {
119125
cliOptions.add(new CliOption(TypeScriptClientCodegen.USE_RXJS_SWITCH, TypeScriptClientCodegen.USE_RXJS_SWITCH_DESC).defaultValue("false"));
120126
cliOptions.add(new CliOption(TypeScriptClientCodegen.USE_OBJECT_PARAMS_SWITCH, TypeScriptClientCodegen.USE_OBJECT_PARAMS_DESC).defaultValue("false"));
121127
cliOptions.add(new CliOption(TypeScriptClientCodegen.USE_INVERSIFY_SWITCH, TypeScriptClientCodegen.USE_INVERSIFY_SWITCH_DESC).defaultValue("false"));
128+
cliOptions.add(new CliOption(TypeScriptClientCodegen.TYPESCRIPT_MAJOR_VERSION_SWTICH, TypeScriptClientCodegen.TYPESCRIPT_MAJOR_VERSION_DESC).defaultValue(this.getTypescriptMajorVersion()));
122129
cliOptions.add(new CliOption(TypeScriptClientCodegen.IMPORT_FILE_EXTENSION_SWITCH, TypeScriptClientCodegen.IMPORT_FILE_EXTENSION_SWITCH_DESC));
123130

124131
CliOption frameworkOption = new CliOption(TypeScriptClientCodegen.FRAMEWORK_SWITCH, TypeScriptClientCodegen.FRAMEWORK_SWITCH_DESC);
@@ -459,6 +466,8 @@ public void processOpts() {
459466
if (additionalProperties.containsKey(NPM_REPOSITORY)) {
460467
setNpmRepository(additionalProperties.get(NPM_REPOSITORY).toString());
461468
}
469+
470+
additionalProperties.put(TYPESCRIPT_MAJOR_VERSION_SWTICH, typescriptMajorVersion);
462471
}
463472

464473
private String getHttpLibForFramework(String object) {

modules/openapi-generator/src/main/resources/typescript/package.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
"url-parse": "^1.4.3"
7676
},
7777
"devDependencies": {
78-
"typescript": "^4.0",
78+
"typescript": "^{{typescriptMajorVersion}}.0",
7979
"@types/url-parse": "1.4.4"
8080
}{{#npmRepository}},{{/npmRepository}}
8181
{{#npmRepository}}

samples/client/others/typescript/builds/array-of-lists/package.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

samples/client/others/typescript/builds/enum-single-value/package.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

samples/client/others/typescript/builds/null-types-simple/package.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

samples/client/others/typescript/builds/with-unique-items/package.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

samples/client/others/typescript/encode-decode/build/package.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

samples/openapi3/client/petstore/typescript/builds/browser/package.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

samples/openapi3/client/petstore/typescript/builds/composed-schemas/package.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)