forked from loafle/openapi-generator-original
Handle boolean enum correctly in typescript-axios (#9025)
can't use enum because of TS18033
This commit is contained in:
parent
7389446354
commit
41afcd0f86
@ -64,7 +64,7 @@ public class CodegenModel implements IJsonSchemaValidationProperties {
|
||||
public String defaultValue;
|
||||
public String arrayModelType;
|
||||
public boolean isAlias; // Is this effectively an alias of another simple type
|
||||
public boolean isString, isInteger, isLong, isNumber, isNumeric, isFloat, isDouble, isDate, isDateTime, isShort, isUnboundedInteger;
|
||||
public boolean isString, isInteger, isLong, isNumber, isNumeric, isFloat, isDouble, isDate, isDateTime, isShort, isUnboundedInteger, isBoolean;
|
||||
private boolean additionalPropertiesIsAnyType;
|
||||
public List<CodegenProperty> vars = new ArrayList<CodegenProperty>(); // all properties (without parent's properties)
|
||||
public List<CodegenProperty> allVars = new ArrayList<CodegenProperty>(); // all properties (with parent's properties)
|
||||
|
@ -728,7 +728,7 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
* @return the sanitized value for enum
|
||||
*/
|
||||
public String toEnumValue(String value, String datatype) {
|
||||
if ("number".equalsIgnoreCase(datatype)) {
|
||||
if ("number".equalsIgnoreCase(datatype) || "boolean".equalsIgnoreCase(datatype)) {
|
||||
return value;
|
||||
} else {
|
||||
return "\"" + escapeText(value) + "\"";
|
||||
@ -2578,6 +2578,8 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
} else { // type is number and without format
|
||||
m.isNumber = Boolean.TRUE;
|
||||
}
|
||||
} else if (ModelUtils.isBooleanSchema(schema)) {
|
||||
m.isBoolean = Boolean.TRUE;
|
||||
} else if (ModelUtils.isFreeFormObject(openAPI, schema)) {
|
||||
addAdditionPropertiesToCodeGenModel(m, schema);
|
||||
}
|
||||
|
@ -663,7 +663,7 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp
|
||||
|
||||
@Override
|
||||
public String toEnumValue(String value, String datatype) {
|
||||
if ("number".equals(datatype)) {
|
||||
if ("number".equals(datatype) || "boolean".equals(datatype)) {
|
||||
return value;
|
||||
} else {
|
||||
return "\'" + escapeText(value) + "\'";
|
||||
|
@ -3,6 +3,11 @@
|
||||
* @export
|
||||
* @enum {string}
|
||||
*/
|
||||
{{#isBoolean}}
|
||||
export type {{classname}} = {{#allowableValues}}{{#enumVars}}{{{value}}}{{^-last}} | {{/-last}}{{/enumVars}}{{/allowableValues}}
|
||||
{{/isBoolean}}
|
||||
|
||||
{{^isBoolean}}
|
||||
export enum {{classname}} {
|
||||
{{#allowableValues}}
|
||||
{{#enumVars}}
|
||||
@ -15,3 +20,4 @@ export enum {{classname}} {
|
||||
{{/enumVars}}
|
||||
{{/allowableValues}}
|
||||
}
|
||||
{{/isBoolean}}
|
||||
|
Loading…
x
Reference in New Issue
Block a user