forked from loafle/openapi-generator-original
[typescript-axios] add config parameter to specify custom axios version (#19103)
* feat(typescript-axios): allow configuration of axios version * docs(typescript-axios): add readme docs for axiosVersion config option * test(typescript-axios): add unit tests for custom axios version * docs(typescript-axios): fix up typescript-axios generator docs
This commit is contained in:
parent
5612852fb6
commit
011acc9950
@ -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.|<dl><dt>**false**</dt><dd>The 'additionalProperties' implementation is compliant with the OAS and JSON schema specifications.</dd><dt>**true**</dt><dd>Keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default.</dd></dl>|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|
|
||||
|
@ -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
|
||||
|
@ -26,7 +26,7 @@
|
||||
"prepare": "npm run build"
|
||||
},
|
||||
"dependencies": {
|
||||
"axios": "^1.6.1"
|
||||
"axios": "{{axiosVersion}}"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "12.11.5 - 12.20.42",
|
||||
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user