From bf18a0779257427d38a01ecd0119f66242c07f86 Mon Sep 17 00:00:00 2001 From: Dennis Ameling Date: Fri, 8 Nov 2024 14:20:25 +0100 Subject: [PATCH] [typescript] make TypeScript version configurable --- docs/generators/typescript.md | 1 + .../codegen/languages/TypeScriptClientCodegen.java | 9 +++++++++ .../src/main/resources/typescript/package.mustache | 2 +- samples/client/echo_api/typescript/build/package.json | 2 +- .../others/typescript/builds/array-of-lists/package.json | 2 +- .../typescript/builds/enum-single-value/package.json | 2 +- .../typescript/builds/null-types-simple/package.json | 2 +- .../typescript/builds/with-unique-items/package.json | 2 +- .../others/typescript/encode-decode/build/package.json | 2 +- .../petstore/typescript/builds/browser/package.json | 2 +- .../typescript/builds/composed-schemas/package.json | 2 +- .../petstore/typescript/builds/default/package.json | 2 +- .../typescript/builds/explode-query/package.json | 2 +- .../petstore/typescript/builds/inversify/package.json | 2 +- .../petstore/typescript/builds/jquery/package.json | 2 +- .../typescript/builds/nullable-enum/package.json | 2 +- .../typescript/builds/object_params/package.json | 2 +- 17 files changed, 25 insertions(+), 15 deletions(-) diff --git a/docs/generators/typescript.md b/docs/generators/typescript.md index 5634f424a966..8616f926108d 100644 --- a/docs/generators/typescript.md +++ b/docs/generators/typescript.md @@ -42,6 +42,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl |sortModelPropertiesByRequiredFlag|Sort model properties to place required parameters before optional parameters.| |true| |sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true| |supportsES6|Generate code that conforms to ES6.| |false| +|typescriptMajorVersion|Specify the major version of TypeScript to use in the client code. Default is 5.| |5| |useErasableSyntax|Use erasable syntax for the generated code. This is a temporary feature and will be removed in the future.| |false| |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| |useObjectParameters|Use aggregate parameter objects as function arguments for api operations instead of passing each parameter as a separate function argument.| |false| diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptClientCodegen.java index 3ab788ef8b14..085461f446ea 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptClientCodegen.java @@ -78,6 +78,9 @@ public class TypeScriptClientCodegen extends AbstractTypeScriptClientCodegen imp private static final String USE_OBJECT_PARAMS_SWITCH = "useObjectParameters"; 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."; + protected static final String TYPESCRIPT_MAJOR_VERSION_SWTICH = "typescriptMajorVersion"; + private static final String TYPESCRIPT_MAJOR_VERSION_DESC = "Specify the major version of TypeScript to use in the client code. Default is 5."; + public static final String USE_ERASABLE_SYNTAX = "useErasableSyntax"; 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."; @@ -97,6 +100,9 @@ public class TypeScriptClientCodegen extends AbstractTypeScriptClientCodegen imp protected String snapshot = null; protected ENUM_PROPERTY_NAMING_TYPE enumPropertyNaming = ENUM_PROPERTY_NAMING_TYPE.PascalCase; + @Getter @Setter + protected String typescriptMajorVersion = "5"; + private final DateTimeFormatter iso8601Date = DateTimeFormatter.ISO_DATE; private final DateTimeFormatter iso8601DateTime = DateTimeFormatter.ISO_DATE_TIME; @@ -131,6 +137,7 @@ public TypeScriptClientCodegen() { cliOptions.add(new CliOption(TypeScriptClientCodegen.USE_RXJS_SWITCH, TypeScriptClientCodegen.USE_RXJS_SWITCH_DESC).defaultValue("false")); cliOptions.add(new CliOption(TypeScriptClientCodegen.USE_OBJECT_PARAMS_SWITCH, TypeScriptClientCodegen.USE_OBJECT_PARAMS_DESC).defaultValue("false")); cliOptions.add(new CliOption(TypeScriptClientCodegen.USE_INVERSIFY_SWITCH, TypeScriptClientCodegen.USE_INVERSIFY_SWITCH_DESC).defaultValue("false")); + cliOptions.add(new CliOption(TypeScriptClientCodegen.TYPESCRIPT_MAJOR_VERSION_SWTICH, TypeScriptClientCodegen.TYPESCRIPT_MAJOR_VERSION_DESC).defaultValue(this.getTypescriptMajorVersion())); cliOptions.add(new CliOption(TypeScriptClientCodegen.IMPORT_FILE_EXTENSION_SWITCH, TypeScriptClientCodegen.IMPORT_FILE_EXTENSION_SWITCH_DESC)); cliOptions.add(new CliOption(TypeScriptClientCodegen.USE_ERASABLE_SYNTAX, TypeScriptClientCodegen.USE_ERASABLE_SYNTAX_DESC).defaultValue("false")); @@ -495,6 +502,8 @@ public void processOpts() { if (additionalProperties.containsKey(NPM_REPOSITORY)) { setNpmRepository(additionalProperties.get(NPM_REPOSITORY).toString()); } + + additionalProperties.put(TYPESCRIPT_MAJOR_VERSION_SWTICH, typescriptMajorVersion); } private String getHttpLibForFramework(String object) { diff --git a/modules/openapi-generator/src/main/resources/typescript/package.mustache b/modules/openapi-generator/src/main/resources/typescript/package.mustache index e508e8787e09..e5da801fc289 100644 --- a/modules/openapi-generator/src/main/resources/typescript/package.mustache +++ b/modules/openapi-generator/src/main/resources/typescript/package.mustache @@ -71,7 +71,7 @@ "es6-promise": "^4.2.4" }, "devDependencies": { - "typescript": "^4.0" + "typescript": "^{{typescriptMajorVersion}}.0" }{{#npmRepository}},{{/npmRepository}} {{#npmRepository}} "publishConfig":{ diff --git a/samples/client/echo_api/typescript/build/package.json b/samples/client/echo_api/typescript/build/package.json index c658f9c1879a..f0abe77d2774 100644 --- a/samples/client/echo_api/typescript/build/package.json +++ b/samples/client/echo_api/typescript/build/package.json @@ -38,6 +38,6 @@ "es6-promise": "^4.2.4" }, "devDependencies": { - "typescript": "^4.0" + "typescript": "^5.0" } } diff --git a/samples/client/others/typescript/builds/array-of-lists/package.json b/samples/client/others/typescript/builds/array-of-lists/package.json index c8f6a2b429cd..5dbf979d205d 100644 --- a/samples/client/others/typescript/builds/array-of-lists/package.json +++ b/samples/client/others/typescript/builds/array-of-lists/package.json @@ -36,6 +36,6 @@ "es6-promise": "^4.2.4" }, "devDependencies": { - "typescript": "^4.0" + "typescript": "^5.0" } } diff --git a/samples/client/others/typescript/builds/enum-single-value/package.json b/samples/client/others/typescript/builds/enum-single-value/package.json index c8f6a2b429cd..5dbf979d205d 100644 --- a/samples/client/others/typescript/builds/enum-single-value/package.json +++ b/samples/client/others/typescript/builds/enum-single-value/package.json @@ -36,6 +36,6 @@ "es6-promise": "^4.2.4" }, "devDependencies": { - "typescript": "^4.0" + "typescript": "^5.0" } } diff --git a/samples/client/others/typescript/builds/null-types-simple/package.json b/samples/client/others/typescript/builds/null-types-simple/package.json index c8f6a2b429cd..5dbf979d205d 100644 --- a/samples/client/others/typescript/builds/null-types-simple/package.json +++ b/samples/client/others/typescript/builds/null-types-simple/package.json @@ -36,6 +36,6 @@ "es6-promise": "^4.2.4" }, "devDependencies": { - "typescript": "^4.0" + "typescript": "^5.0" } } diff --git a/samples/client/others/typescript/builds/with-unique-items/package.json b/samples/client/others/typescript/builds/with-unique-items/package.json index c8f6a2b429cd..5dbf979d205d 100644 --- a/samples/client/others/typescript/builds/with-unique-items/package.json +++ b/samples/client/others/typescript/builds/with-unique-items/package.json @@ -36,6 +36,6 @@ "es6-promise": "^4.2.4" }, "devDependencies": { - "typescript": "^4.0" + "typescript": "^5.0" } } diff --git a/samples/client/others/typescript/encode-decode/build/package.json b/samples/client/others/typescript/encode-decode/build/package.json index 0354df36287e..a64a41bcc37c 100644 --- a/samples/client/others/typescript/encode-decode/build/package.json +++ b/samples/client/others/typescript/encode-decode/build/package.json @@ -38,6 +38,6 @@ "es6-promise": "^4.2.4" }, "devDependencies": { - "typescript": "^4.0" + "typescript": "^5.0" } } diff --git a/samples/openapi3/client/petstore/typescript/builds/browser/package.json b/samples/openapi3/client/petstore/typescript/builds/browser/package.json index 0133eb86c1b7..81bc96b3dca4 100644 --- a/samples/openapi3/client/petstore/typescript/builds/browser/package.json +++ b/samples/openapi3/client/petstore/typescript/builds/browser/package.json @@ -36,6 +36,6 @@ "es6-promise": "^4.2.4" }, "devDependencies": { - "typescript": "^4.0" + "typescript": "^5.0" } } diff --git a/samples/openapi3/client/petstore/typescript/builds/composed-schemas/package.json b/samples/openapi3/client/petstore/typescript/builds/composed-schemas/package.json index 6df8f66dc984..32405dfeaaef 100644 --- a/samples/openapi3/client/petstore/typescript/builds/composed-schemas/package.json +++ b/samples/openapi3/client/petstore/typescript/builds/composed-schemas/package.json @@ -36,6 +36,6 @@ "es6-promise": "^4.2.4" }, "devDependencies": { - "typescript": "^4.0" + "typescript": "^5.0" } } diff --git a/samples/openapi3/client/petstore/typescript/builds/default/package.json b/samples/openapi3/client/petstore/typescript/builds/default/package.json index 6a9259aee78b..39793a26c109 100644 --- a/samples/openapi3/client/petstore/typescript/builds/default/package.json +++ b/samples/openapi3/client/petstore/typescript/builds/default/package.json @@ -38,6 +38,6 @@ "es6-promise": "^4.2.4" }, "devDependencies": { - "typescript": "^4.0" + "typescript": "^5.0" } } diff --git a/samples/openapi3/client/petstore/typescript/builds/explode-query/package.json b/samples/openapi3/client/petstore/typescript/builds/explode-query/package.json index 6a9259aee78b..39793a26c109 100644 --- a/samples/openapi3/client/petstore/typescript/builds/explode-query/package.json +++ b/samples/openapi3/client/petstore/typescript/builds/explode-query/package.json @@ -38,6 +38,6 @@ "es6-promise": "^4.2.4" }, "devDependencies": { - "typescript": "^4.0" + "typescript": "^5.0" } } diff --git a/samples/openapi3/client/petstore/typescript/builds/inversify/package.json b/samples/openapi3/client/petstore/typescript/builds/inversify/package.json index b4151dbcae86..774eaa4d7ca0 100644 --- a/samples/openapi3/client/petstore/typescript/builds/inversify/package.json +++ b/samples/openapi3/client/petstore/typescript/builds/inversify/package.json @@ -39,6 +39,6 @@ "es6-promise": "^4.2.4" }, "devDependencies": { - "typescript": "^4.0" + "typescript": "^5.0" } } diff --git a/samples/openapi3/client/petstore/typescript/builds/jquery/package.json b/samples/openapi3/client/petstore/typescript/builds/jquery/package.json index 01432e3bf7d6..f5a71db4be87 100644 --- a/samples/openapi3/client/petstore/typescript/builds/jquery/package.json +++ b/samples/openapi3/client/petstore/typescript/builds/jquery/package.json @@ -37,6 +37,6 @@ "es6-promise": "^4.2.4" }, "devDependencies": { - "typescript": "^4.0" + "typescript": "^5.0" } } diff --git a/samples/openapi3/client/petstore/typescript/builds/nullable-enum/package.json b/samples/openapi3/client/petstore/typescript/builds/nullable-enum/package.json index c8f6a2b429cd..5dbf979d205d 100644 --- a/samples/openapi3/client/petstore/typescript/builds/nullable-enum/package.json +++ b/samples/openapi3/client/petstore/typescript/builds/nullable-enum/package.json @@ -36,6 +36,6 @@ "es6-promise": "^4.2.4" }, "devDependencies": { - "typescript": "^4.0" + "typescript": "^5.0" } } diff --git a/samples/openapi3/client/petstore/typescript/builds/object_params/package.json b/samples/openapi3/client/petstore/typescript/builds/object_params/package.json index 6a9259aee78b..39793a26c109 100644 --- a/samples/openapi3/client/petstore/typescript/builds/object_params/package.json +++ b/samples/openapi3/client/petstore/typescript/builds/object_params/package.json @@ -38,6 +38,6 @@ "es6-promise": "^4.2.4" }, "devDependencies": { - "typescript": "^4.0" + "typescript": "^5.0" } }