diff --git a/docs/generators/typescript-axios.md b/docs/generators/typescript-axios.md index 018c52b23a7..f4a70222200 100644 --- a/docs/generators/typescript-axios.md +++ b/docs/generators/typescript-axios.md @@ -20,6 +20,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl | ------ | ----------- | ------ | ------- | |allowUnicodeIdentifiers|boolean, toggles whether unicode identifiers are allowed in names or not, default is false| |false| |apiPackage|package for generated api classes| |null| +|axiosVersion|Use this property to override the axios version in package.json| |^1.6.1| |disallowAdditionalPropertiesIfNotPresent|If false, the 'additionalProperties' implementation (set to true by default) is compliant with the OAS and JSON schema specifications. If true (default), keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default.|
**false**
The 'additionalProperties' implementation is compliant with the OAS and JSON schema specifications.
**true**
Keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default.
|true| |ensureUniqueParams|Whether to ensure parameter names are unique in an operation (rename parameters that are not).| |true| |enumNameSuffix|Suffix that will be appended to all enum names.| |Enum| diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptAxiosClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptAxiosClientCodegen.java index 7907b076062..6bc4ecfb373 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptAxiosClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptAxiosClientCodegen.java @@ -44,11 +44,16 @@ public class TypeScriptAxiosClientCodegen extends AbstractTypeScriptClientCodege public static final String STRING_ENUMS = "stringEnums"; public static final String STRING_ENUMS_DESC = "Generate string enums instead of objects for enum values."; public static final String USE_SQUARE_BRACKETS_IN_ARRAY_NAMES = "useSquareBracketsInArrayNames"; + public static final String AXIOS_VERSION = "axiosVersion"; + public static final String DEFAULT_AXIOS_VERSION = "^1.6.1"; @Getter @Setter protected String npmRepository = null; protected Boolean stringEnums = false; + @Getter @Setter + protected String axiosVersion = DEFAULT_AXIOS_VERSION; + private String tsModelPackage = ""; public TypeScriptAxiosClientCodegen() { @@ -77,6 +82,7 @@ public class TypeScriptAxiosClientCodegen extends AbstractTypeScriptClientCodege this.cliOptions.add(new CliOption(WITH_NODE_IMPORTS, "Setting this property to true adds imports for NodeJS", SchemaTypeUtil.BOOLEAN_TYPE).defaultValue(Boolean.FALSE.toString())); this.cliOptions.add(new CliOption(STRING_ENUMS, STRING_ENUMS_DESC).defaultValue(String.valueOf(this.stringEnums))); this.cliOptions.add(new CliOption(USE_SQUARE_BRACKETS_IN_ARRAY_NAMES, "Setting this property to true will add brackets to array attribute names, e.g. my_values[].", SchemaTypeUtil.BOOLEAN_TYPE).defaultValue(Boolean.FALSE.toString())); + this.cliOptions.add(new CliOption(AXIOS_VERSION, "Use this property to override the axios version in package.json").defaultValue(DEFAULT_AXIOS_VERSION)); // Templates have no mapping between formatted property names and original base names so use only "original" and remove this option removeOption(CodegenConstants.MODEL_PROPERTY_NAMING); } @@ -148,6 +154,11 @@ public class TypeScriptAxiosClientCodegen extends AbstractTypeScriptClientCodege addNpmPackageGeneration(); } + if (additionalProperties.containsKey(AXIOS_VERSION)) { + setAxiosVersion(additionalProperties.get(AXIOS_VERSION).toString()); + } + additionalProperties.put("axiosVersion", getAxiosVersion()); + } @Override diff --git a/modules/openapi-generator/src/main/resources/typescript-axios/package.mustache b/modules/openapi-generator/src/main/resources/typescript-axios/package.mustache index b5ab30bba8f..57504af7415 100644 --- a/modules/openapi-generator/src/main/resources/typescript-axios/package.mustache +++ b/modules/openapi-generator/src/main/resources/typescript-axios/package.mustache @@ -26,7 +26,7 @@ "prepare": "npm run build" }, "dependencies": { - "axios": "^1.6.1" + "axios": "{{axiosVersion}}" }, "devDependencies": { "@types/node": "12.11.5 - 12.20.42", diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/axios/TypeScriptAxiosClientCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/axios/TypeScriptAxiosClientCodegenTest.java index 8a229bf14ff..6e513a73b9e 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/axios/TypeScriptAxiosClientCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/axios/TypeScriptAxiosClientCodegenTest.java @@ -111,4 +111,23 @@ public class TypeScriptAxiosClientCodegenTest { assertThat(codegen.supportingFiles()).contains(new SupportingFile("tsconfig.mustache", "", "tsconfig.json")); assertThat(codegen.supportingFiles()).doesNotContain(new SupportingFile("tsconfig.esm.mustache", "", "tsconfig.esm.json")); } + + @Test + public void testAppliesDefaultAxiosVersion() { + TypeScriptAxiosClientCodegen codegen = new TypeScriptAxiosClientCodegen(); + + codegen.processOpts(); + + assertEquals(codegen.additionalProperties().get("axiosVersion"), TypeScriptAxiosClientCodegen.DEFAULT_AXIOS_VERSION); + } + + @Test + public void testAppliesCustomAxiosVersion() { + TypeScriptAxiosClientCodegen codegen = new TypeScriptAxiosClientCodegen(); + codegen.additionalProperties().put("axiosVersion", "^1.2.3"); + + codegen.processOpts(); + + assertEquals(codegen.additionalProperties().get("axiosVersion"), "^1.2.3"); + } }