forked from loafle/openapi-generator-original
Fix cast exception when handling example/default of UUID/Long type (#16450)
* fix cast exception when handling uuid example/default * more cast exception fix * better fix in example generator * better code format * better code format
This commit is contained in:
parent
bceae5695e
commit
a0350c6533
@ -287,10 +287,8 @@ public class ExampleGenerator {
|
||||
return "https://openapi-generator.tech";
|
||||
} else if (ModelUtils.isStringSchema(property)) {
|
||||
LOGGER.debug("String property");
|
||||
String defaultValue = (String) property.getDefault();
|
||||
if (defaultValue != null && !defaultValue.isEmpty()) {
|
||||
LOGGER.debug("Default value found: '{}'", defaultValue);
|
||||
return defaultValue;
|
||||
if (property.getDefault() != null) {
|
||||
return String.valueOf(property.getDefault());
|
||||
}
|
||||
List<String> enumValues = property.getEnum();
|
||||
if (enumValues != null && !enumValues.isEmpty()) {
|
||||
|
@ -262,7 +262,7 @@ public abstract class AbstractApexCodegen extends DefaultCodegen implements Code
|
||||
return "null";
|
||||
} else if (ModelUtils.isStringSchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
String _default = (String) p.getDefault();
|
||||
String _default = String.valueOf(p.getDefault());
|
||||
if (p.getEnum() == null) {
|
||||
return "\"" + escapeText(_default) + "\"";
|
||||
} else {
|
||||
|
@ -795,7 +795,7 @@ public abstract class AbstractFSharpCodegen extends DefaultCodegen implements Co
|
||||
}
|
||||
} else if (ModelUtils.isStringSchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
String _default = (String) p.getDefault();
|
||||
String _default = String.valueOf(p.getDefault());
|
||||
if (p.getEnum() == null) {
|
||||
return "\"" + _default + "\"";
|
||||
} else {
|
||||
@ -1133,5 +1133,7 @@ public abstract class AbstractFSharpCodegen extends DefaultCodegen implements Co
|
||||
}
|
||||
|
||||
@Override
|
||||
public GeneratorLanguage generatorLanguage() { return GeneratorLanguage.F_SHARP; }
|
||||
public GeneratorLanguage generatorLanguage() {
|
||||
return GeneratorLanguage.F_SHARP;
|
||||
}
|
||||
}
|
||||
|
@ -353,7 +353,7 @@ public abstract class AbstractPythonCodegen extends DefaultCodegen implements Co
|
||||
|
||||
// correct "'"s into "'"s after toString()
|
||||
if (ModelUtils.isStringSchema(schema) && schema.getDefault() != null && !ModelUtils.isDateSchema(schema) && !ModelUtils.isDateTimeSchema(schema)) {
|
||||
example = (String) schema.getDefault();
|
||||
example = String.valueOf(schema.getDefault());
|
||||
}
|
||||
|
||||
if (StringUtils.isNotBlank(example) && !"null".equals(example)) {
|
||||
|
@ -233,8 +233,10 @@ public class ApexClientCodegen extends AbstractApexCodegen {
|
||||
// true => "true", false => "false", null => "null"
|
||||
out = String.valueOf(p.getDefault());
|
||||
} else if (ModelUtils.isLongSchema(p)) {
|
||||
Long def = (Long) p.getDefault();
|
||||
out = def == null ? out : def + "L";
|
||||
if (p.getDefault() != null) {
|
||||
Long def = Long.parseLong(String.valueOf(p.getDefault()));
|
||||
out = def == null ? out : def + "L";
|
||||
}
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
Schema inner = ModelUtils.getAdditionalProperties(p);
|
||||
String s = inner == null ? "Object" : getTypeDeclaration(inner);
|
||||
@ -313,7 +315,7 @@ public class ApexClientCodegen extends AbstractApexCodegen {
|
||||
supportingFiles.add(new SupportingFile("gitignore.mustache", "", ".gitignore"));
|
||||
|
||||
supportingFiles.add(new SupportingFile("README_ant.mustache", "README.md")
|
||||
.doNotOverwrite());
|
||||
.doNotOverwrite());
|
||||
|
||||
}
|
||||
|
||||
@ -323,10 +325,12 @@ public class ApexClientCodegen extends AbstractApexCodegen {
|
||||
supportingFiles.add(new SupportingFile("sfdx-project.json.mustache", "sfdx-project.json"));
|
||||
|
||||
supportingFiles.add(new SupportingFile("README_sfdx.mustache", "README.md")
|
||||
.doNotOverwrite());
|
||||
.doNotOverwrite());
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public GeneratorLanguage generatorLanguage() { return GeneratorLanguage.APEX; }
|
||||
public GeneratorLanguage generatorLanguage() {
|
||||
return GeneratorLanguage.APEX;
|
||||
}
|
||||
}
|
||||
|
@ -939,5 +939,7 @@ public class CLibcurlClientCodegen extends DefaultCodegen implements CodegenConf
|
||||
}
|
||||
|
||||
@Override
|
||||
public GeneratorLanguage generatorLanguage() { return GeneratorLanguage.C; }
|
||||
public GeneratorLanguage generatorLanguage() {
|
||||
return GeneratorLanguage.C;
|
||||
}
|
||||
}
|
||||
|
@ -235,9 +235,9 @@ public class ProtobufSchemaCodegen extends DefaultCodegen implements CodegenConf
|
||||
}
|
||||
|
||||
if (allowableValues.containsKey("values")) {
|
||||
List<String> values = (List<String>) allowableValues.get("values");
|
||||
for (String value : values) {
|
||||
value = prefix + "_" + value;
|
||||
List<Object> values = (List<Object>) allowableValues.get("values");
|
||||
for (Object value : values) {
|
||||
value = prefix + "_" + String.valueOf(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -435,7 +435,7 @@ public class ProtobufSchemaCodegen extends DefaultCodegen implements CodegenConf
|
||||
}
|
||||
} else if (ModelUtils.isStringSchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
if (Pattern.compile("\r\n|\r|\n").matcher((String) p.getDefault()).find())
|
||||
if (Pattern.compile("\r\n|\r|\n").matcher(String.valueOf(p.getDefault())).find())
|
||||
return "'''" + p.getDefault() + "'''";
|
||||
else
|
||||
return "'" + p.getDefault() + "'";
|
||||
|
@ -1236,7 +1236,7 @@ public class RustServerCodegen extends AbstractRustCodegen implements CodegenCon
|
||||
}
|
||||
} else if (ModelUtils.isStringSchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
defaultValue = "\"" + (String) p.getDefault() + "\".to_string()";
|
||||
defaultValue = "\"" + String.valueOf(p.getDefault()) + "\".to_string()";
|
||||
}
|
||||
}
|
||||
if ((defaultValue != null) && (ModelUtils.isNullable(p)))
|
||||
|
@ -396,9 +396,9 @@ public class SwiftCombineClientCodegen extends DefaultCodegen implements Codegen
|
||||
if (p.getEnum() != null && !p.getEnum().isEmpty()) {
|
||||
if (p.getDefault() != null) {
|
||||
if (ModelUtils.isStringSchema(p)) {
|
||||
return "." + toEnumVarName(escapeText((String) p.getDefault()), p.getType());
|
||||
return "." + toEnumVarName(escapeText(String.valueOf(p.getDefault())), p.getType());
|
||||
} else {
|
||||
return "." + toEnumVarName(escapeText(p.getDefault().toString()), p.getType());
|
||||
return "." + toEnumVarName(escapeText(String.valueOf(p.getDefault())), p.getType());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -412,9 +412,9 @@ public class SwiftCombineClientCodegen extends DefaultCodegen implements Codegen
|
||||
long epochMicro = TimeUnit.SECONDS.toMicros(instant.getEpochSecond()) + (instant.get(ChronoField.MICRO_OF_SECOND));
|
||||
return "Date(timeIntervalSince1970: " + String.valueOf(epochMicro) + ".0 / 1_000_000)";
|
||||
} else if (ModelUtils.isUUIDSchema(p)) {
|
||||
return "\"" + escapeText(p.getDefault().toString()) + "\"";
|
||||
return "\"" + escapeText(String.valueOf(p.getDefault())) + "\"";
|
||||
} else if (ModelUtils.isStringSchema(p)) {
|
||||
return "\"" + escapeText((String) p.getDefault()) + "\"";
|
||||
return "\"" + escapeText(String.valueOf(p.getDefault())) + "\"";
|
||||
}
|
||||
// TODO: Handle more cases from `ModelUtils`, such as Date
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user