Skip to content

Commit 9547ebd

Browse files
author
Dennis Ameling
authored
[typescript] make TypeScript version configurable (#20064)
1 parent 48b7c85 commit 9547ebd

File tree

17 files changed

+25
-15
lines changed

17 files changed

+25
-15
lines changed

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
|useErasableSyntax|Use erasable syntax for the generated code. This is a temporary feature and will be removed in the future.| |false|
4647
|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|
4748
|useObjectParameters|Use aggregate parameter objects as function arguments for api operations instead of passing each parameter as a separate function argument.| |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
@@ -78,6 +78,9 @@ public class TypeScriptClientCodegen extends AbstractTypeScriptClientCodegen imp
7878
private static final String USE_OBJECT_PARAMS_SWITCH = "useObjectParameters";
7979
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.";
8080

81+
protected static final String TYPESCRIPT_MAJOR_VERSION_SWTICH = "typescriptMajorVersion";
82+
private static final String TYPESCRIPT_MAJOR_VERSION_DESC = "Specify the major version of TypeScript to use in the client code. Default is 5.";
83+
8184
public static final String USE_ERASABLE_SYNTAX = "useErasableSyntax";
8285
public static final String USE_ERASABLE_SYNTAX_DESC = "Use erasable syntax for the generated code. This is a temporary feature and will be removed in the future.";
8386

@@ -97,6 +100,9 @@ public class TypeScriptClientCodegen extends AbstractTypeScriptClientCodegen imp
97100
protected String snapshot = null;
98101
protected ENUM_PROPERTY_NAMING_TYPE enumPropertyNaming = ENUM_PROPERTY_NAMING_TYPE.PascalCase;
99102

103+
@Getter @Setter
104+
protected String typescriptMajorVersion = "5";
105+
100106
private final DateTimeFormatter iso8601Date = DateTimeFormatter.ISO_DATE;
101107
private final DateTimeFormatter iso8601DateTime = DateTimeFormatter.ISO_DATE_TIME;
102108

@@ -131,6 +137,7 @@ public TypeScriptClientCodegen() {
131137
cliOptions.add(new CliOption(TypeScriptClientCodegen.USE_RXJS_SWITCH, TypeScriptClientCodegen.USE_RXJS_SWITCH_DESC).defaultValue("false"));
132138
cliOptions.add(new CliOption(TypeScriptClientCodegen.USE_OBJECT_PARAMS_SWITCH, TypeScriptClientCodegen.USE_OBJECT_PARAMS_DESC).defaultValue("false"));
133139
cliOptions.add(new CliOption(TypeScriptClientCodegen.USE_INVERSIFY_SWITCH, TypeScriptClientCodegen.USE_INVERSIFY_SWITCH_DESC).defaultValue("false"));
140+
cliOptions.add(new CliOption(TypeScriptClientCodegen.TYPESCRIPT_MAJOR_VERSION_SWTICH, TypeScriptClientCodegen.TYPESCRIPT_MAJOR_VERSION_DESC).defaultValue(this.getTypescriptMajorVersion()));
134141
cliOptions.add(new CliOption(TypeScriptClientCodegen.IMPORT_FILE_EXTENSION_SWITCH, TypeScriptClientCodegen.IMPORT_FILE_EXTENSION_SWITCH_DESC));
135142
cliOptions.add(new CliOption(TypeScriptClientCodegen.USE_ERASABLE_SYNTAX, TypeScriptClientCodegen.USE_ERASABLE_SYNTAX_DESC).defaultValue("false"));
136143

@@ -495,6 +502,8 @@ public void processOpts() {
495502
if (additionalProperties.containsKey(NPM_REPOSITORY)) {
496503
setNpmRepository(additionalProperties.get(NPM_REPOSITORY).toString());
497504
}
505+
506+
additionalProperties.put(TYPESCRIPT_MAJOR_VERSION_SWTICH, typescriptMajorVersion);
498507
}
499508

500509
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
@@ -71,7 +71,7 @@
7171
"es6-promise": "^4.2.4"
7272
},
7373
"devDependencies": {
74-
"typescript": "^4.0"
74+
"typescript": "^{{typescriptMajorVersion}}.0"
7575
}{{#npmRepository}},{{/npmRepository}}
7676
{{#npmRepository}}
7777
"publishConfig":{

samples/client/echo_api/typescript/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/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.

0 commit comments

Comments
 (0)