From 4f5d67c8b4b36f5ee4ba2520ee2e771e14522013 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 +- .../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 +- 16 files changed, 24 insertions(+), 14 deletions(-) diff --git a/docs/generators/typescript.md b/docs/generators/typescript.md index d53ba13a6b81..8e458c8aeb6b 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| |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| |useRxJS|Enable this to internally use rxjs observables. If disabled, a stub is used instead. This is required for the 'angular' framework.| |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 f35c40b7677e..b00ae96a6a96 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 @@ -76,6 +76,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."; + private final Map frameworkToHttpLibMap; // NPM Options @@ -87,6 +90,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; @@ -119,6 +125,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)); CliOption frameworkOption = new CliOption(TypeScriptClientCodegen.FRAMEWORK_SWITCH, TypeScriptClientCodegen.FRAMEWORK_SWITCH_DESC); @@ -459,6 +466,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 34c324c08453..855c9d3d9a42 100644 --- a/modules/openapi-generator/src/main/resources/typescript/package.mustache +++ b/modules/openapi-generator/src/main/resources/typescript/package.mustache @@ -75,7 +75,7 @@ "url-parse": "^1.4.3" }, "devDependencies": { - "typescript": "^4.0", + "typescript": "^{{typescriptMajorVersion}}.0", "@types/url-parse": "1.4.4" }{{#npmRepository}},{{/npmRepository}} {{#npmRepository}} 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 ea853317fbd4..dbf0a316160e 100644 --- a/samples/client/others/typescript/builds/array-of-lists/package.json +++ b/samples/client/others/typescript/builds/array-of-lists/package.json @@ -36,7 +36,7 @@ "url-parse": "^1.4.3" }, "devDependencies": { - "typescript": "^4.0", + "typescript": "^5.0", "@types/url-parse": "1.4.4" } } 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 ea853317fbd4..dbf0a316160e 100644 --- a/samples/client/others/typescript/builds/enum-single-value/package.json +++ b/samples/client/others/typescript/builds/enum-single-value/package.json @@ -36,7 +36,7 @@ "url-parse": "^1.4.3" }, "devDependencies": { - "typescript": "^4.0", + "typescript": "^5.0", "@types/url-parse": "1.4.4" } } 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 ea853317fbd4..dbf0a316160e 100644 --- a/samples/client/others/typescript/builds/null-types-simple/package.json +++ b/samples/client/others/typescript/builds/null-types-simple/package.json @@ -36,7 +36,7 @@ "url-parse": "^1.4.3" }, "devDependencies": { - "typescript": "^4.0", + "typescript": "^5.0", "@types/url-parse": "1.4.4" } } 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 ea853317fbd4..dbf0a316160e 100644 --- a/samples/client/others/typescript/builds/with-unique-items/package.json +++ b/samples/client/others/typescript/builds/with-unique-items/package.json @@ -36,7 +36,7 @@ "url-parse": "^1.4.3" }, "devDependencies": { - "typescript": "^4.0", + "typescript": "^5.0", "@types/url-parse": "1.4.4" } } diff --git a/samples/client/others/typescript/encode-decode/build/package.json b/samples/client/others/typescript/encode-decode/build/package.json index 98e27af43f34..a8e3b0d9cd45 100644 --- a/samples/client/others/typescript/encode-decode/build/package.json +++ b/samples/client/others/typescript/encode-decode/build/package.json @@ -39,7 +39,7 @@ "url-parse": "^1.4.3" }, "devDependencies": { - "typescript": "^4.0", + "typescript": "^5.0", "@types/url-parse": "1.4.4" } } diff --git a/samples/openapi3/client/petstore/typescript/builds/browser/package.json b/samples/openapi3/client/petstore/typescript/builds/browser/package.json index 7f477ac29fd7..16368b4195a1 100644 --- a/samples/openapi3/client/petstore/typescript/builds/browser/package.json +++ b/samples/openapi3/client/petstore/typescript/builds/browser/package.json @@ -37,7 +37,7 @@ "url-parse": "^1.4.3" }, "devDependencies": { - "typescript": "^4.0", + "typescript": "^5.0", "@types/url-parse": "1.4.4" } } 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 ea8d9cce8ca6..6c7887f022be 100644 --- a/samples/openapi3/client/petstore/typescript/builds/composed-schemas/package.json +++ b/samples/openapi3/client/petstore/typescript/builds/composed-schemas/package.json @@ -36,7 +36,7 @@ "url-parse": "^1.4.3" }, "devDependencies": { - "typescript": "^4.0", + "typescript": "^5.0", "@types/url-parse": "1.4.4" } } diff --git a/samples/openapi3/client/petstore/typescript/builds/default/package.json b/samples/openapi3/client/petstore/typescript/builds/default/package.json index a18e68426adc..2921a8957073 100644 --- a/samples/openapi3/client/petstore/typescript/builds/default/package.json +++ b/samples/openapi3/client/petstore/typescript/builds/default/package.json @@ -39,7 +39,7 @@ "url-parse": "^1.4.3" }, "devDependencies": { - "typescript": "^4.0", + "typescript": "^5.0", "@types/url-parse": "1.4.4" } } 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 a18e68426adc..2921a8957073 100644 --- a/samples/openapi3/client/petstore/typescript/builds/explode-query/package.json +++ b/samples/openapi3/client/petstore/typescript/builds/explode-query/package.json @@ -39,7 +39,7 @@ "url-parse": "^1.4.3" }, "devDependencies": { - "typescript": "^4.0", + "typescript": "^5.0", "@types/url-parse": "1.4.4" } } diff --git a/samples/openapi3/client/petstore/typescript/builds/inversify/package.json b/samples/openapi3/client/petstore/typescript/builds/inversify/package.json index 1118902e6673..10be55191003 100644 --- a/samples/openapi3/client/petstore/typescript/builds/inversify/package.json +++ b/samples/openapi3/client/petstore/typescript/builds/inversify/package.json @@ -41,7 +41,7 @@ "url-parse": "^1.4.3" }, "devDependencies": { - "typescript": "^4.0", + "typescript": "^5.0", "@types/url-parse": "1.4.4" } } diff --git a/samples/openapi3/client/petstore/typescript/builds/jquery/package.json b/samples/openapi3/client/petstore/typescript/builds/jquery/package.json index aac146f24362..cf6231e7f17d 100644 --- a/samples/openapi3/client/petstore/typescript/builds/jquery/package.json +++ b/samples/openapi3/client/petstore/typescript/builds/jquery/package.json @@ -37,7 +37,7 @@ "url-parse": "^1.4.3" }, "devDependencies": { - "typescript": "^4.0", + "typescript": "^5.0", "@types/url-parse": "1.4.4" } } 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 ea853317fbd4..dbf0a316160e 100644 --- a/samples/openapi3/client/petstore/typescript/builds/nullable-enum/package.json +++ b/samples/openapi3/client/petstore/typescript/builds/nullable-enum/package.json @@ -36,7 +36,7 @@ "url-parse": "^1.4.3" }, "devDependencies": { - "typescript": "^4.0", + "typescript": "^5.0", "@types/url-parse": "1.4.4" } } 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 a18e68426adc..2921a8957073 100644 --- a/samples/openapi3/client/petstore/typescript/builds/object_params/package.json +++ b/samples/openapi3/client/petstore/typescript/builds/object_params/package.json @@ -39,7 +39,7 @@ "url-parse": "^1.4.3" }, "devDependencies": { - "typescript": "^4.0", + "typescript": "^5.0", "@types/url-parse": "1.4.4" } }