mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-07-04 14:40:53 +00:00
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";
|
return "https://openapi-generator.tech";
|
||||||
} else if (ModelUtils.isStringSchema(property)) {
|
} else if (ModelUtils.isStringSchema(property)) {
|
||||||
LOGGER.debug("String property");
|
LOGGER.debug("String property");
|
||||||
String defaultValue = (String) property.getDefault();
|
if (property.getDefault() != null) {
|
||||||
if (defaultValue != null && !defaultValue.isEmpty()) {
|
return String.valueOf(property.getDefault());
|
||||||
LOGGER.debug("Default value found: '{}'", defaultValue);
|
|
||||||
return defaultValue;
|
|
||||||
}
|
}
|
||||||
List<String> enumValues = property.getEnum();
|
List<String> enumValues = property.getEnum();
|
||||||
if (enumValues != null && !enumValues.isEmpty()) {
|
if (enumValues != null && !enumValues.isEmpty()) {
|
||||||
|
@ -262,7 +262,7 @@ public abstract class AbstractApexCodegen extends DefaultCodegen implements Code
|
|||||||
return "null";
|
return "null";
|
||||||
} else if (ModelUtils.isStringSchema(p)) {
|
} else if (ModelUtils.isStringSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
String _default = (String) p.getDefault();
|
String _default = String.valueOf(p.getDefault());
|
||||||
if (p.getEnum() == null) {
|
if (p.getEnum() == null) {
|
||||||
return "\"" + escapeText(_default) + "\"";
|
return "\"" + escapeText(_default) + "\"";
|
||||||
} else {
|
} else {
|
||||||
|
@ -795,7 +795,7 @@ public abstract class AbstractFSharpCodegen extends DefaultCodegen implements Co
|
|||||||
}
|
}
|
||||||
} else if (ModelUtils.isStringSchema(p)) {
|
} else if (ModelUtils.isStringSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
String _default = (String) p.getDefault();
|
String _default = String.valueOf(p.getDefault());
|
||||||
if (p.getEnum() == null) {
|
if (p.getEnum() == null) {
|
||||||
return "\"" + _default + "\"";
|
return "\"" + _default + "\"";
|
||||||
} else {
|
} else {
|
||||||
@ -1133,5 +1133,7 @@ public abstract class AbstractFSharpCodegen extends DefaultCodegen implements Co
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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()
|
// correct "'"s into "'"s after toString()
|
||||||
if (ModelUtils.isStringSchema(schema) && schema.getDefault() != null && !ModelUtils.isDateSchema(schema) && !ModelUtils.isDateTimeSchema(schema)) {
|
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)) {
|
if (StringUtils.isNotBlank(example) && !"null".equals(example)) {
|
||||||
|
@ -233,8 +233,10 @@ public class ApexClientCodegen extends AbstractApexCodegen {
|
|||||||
// true => "true", false => "false", null => "null"
|
// true => "true", false => "false", null => "null"
|
||||||
out = String.valueOf(p.getDefault());
|
out = String.valueOf(p.getDefault());
|
||||||
} else if (ModelUtils.isLongSchema(p)) {
|
} else if (ModelUtils.isLongSchema(p)) {
|
||||||
Long def = (Long) p.getDefault();
|
if (p.getDefault() != null) {
|
||||||
out = def == null ? out : def + "L";
|
Long def = Long.parseLong(String.valueOf(p.getDefault()));
|
||||||
|
out = def == null ? out : def + "L";
|
||||||
|
}
|
||||||
} else if (ModelUtils.isMapSchema(p)) {
|
} else if (ModelUtils.isMapSchema(p)) {
|
||||||
Schema inner = ModelUtils.getAdditionalProperties(p);
|
Schema inner = ModelUtils.getAdditionalProperties(p);
|
||||||
String s = inner == null ? "Object" : getTypeDeclaration(inner);
|
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("gitignore.mustache", "", ".gitignore"));
|
||||||
|
|
||||||
supportingFiles.add(new SupportingFile("README_ant.mustache", "README.md")
|
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("sfdx-project.json.mustache", "sfdx-project.json"));
|
||||||
|
|
||||||
supportingFiles.add(new SupportingFile("README_sfdx.mustache", "README.md")
|
supportingFiles.add(new SupportingFile("README_sfdx.mustache", "README.md")
|
||||||
.doNotOverwrite());
|
.doNotOverwrite());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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
|
@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")) {
|
if (allowableValues.containsKey("values")) {
|
||||||
List<String> values = (List<String>) allowableValues.get("values");
|
List<Object> values = (List<Object>) allowableValues.get("values");
|
||||||
for (String value : values) {
|
for (Object value : values) {
|
||||||
value = prefix + "_" + value;
|
value = prefix + "_" + String.valueOf(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -435,7 +435,7 @@ public class ProtobufSchemaCodegen extends DefaultCodegen implements CodegenConf
|
|||||||
}
|
}
|
||||||
} else if (ModelUtils.isStringSchema(p)) {
|
} else if (ModelUtils.isStringSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
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() + "'''";
|
return "'''" + p.getDefault() + "'''";
|
||||||
else
|
else
|
||||||
return "'" + p.getDefault() + "'";
|
return "'" + p.getDefault() + "'";
|
||||||
|
@ -1236,7 +1236,7 @@ public class RustServerCodegen extends AbstractRustCodegen implements CodegenCon
|
|||||||
}
|
}
|
||||||
} else if (ModelUtils.isStringSchema(p)) {
|
} else if (ModelUtils.isStringSchema(p)) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
defaultValue = "\"" + (String) p.getDefault() + "\".to_string()";
|
defaultValue = "\"" + String.valueOf(p.getDefault()) + "\".to_string()";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((defaultValue != null) && (ModelUtils.isNullable(p)))
|
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.getEnum() != null && !p.getEnum().isEmpty()) {
|
||||||
if (p.getDefault() != null) {
|
if (p.getDefault() != null) {
|
||||||
if (ModelUtils.isStringSchema(p)) {
|
if (ModelUtils.isStringSchema(p)) {
|
||||||
return "." + toEnumVarName(escapeText((String) p.getDefault()), p.getType());
|
return "." + toEnumVarName(escapeText(String.valueOf(p.getDefault())), p.getType());
|
||||||
} else {
|
} 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));
|
long epochMicro = TimeUnit.SECONDS.toMicros(instant.getEpochSecond()) + (instant.get(ChronoField.MICRO_OF_SECOND));
|
||||||
return "Date(timeIntervalSince1970: " + String.valueOf(epochMicro) + ".0 / 1_000_000)";
|
return "Date(timeIntervalSince1970: " + String.valueOf(epochMicro) + ".0 / 1_000_000)";
|
||||||
} else if (ModelUtils.isUUIDSchema(p)) {
|
} else if (ModelUtils.isUUIDSchema(p)) {
|
||||||
return "\"" + escapeText(p.getDefault().toString()) + "\"";
|
return "\"" + escapeText(String.valueOf(p.getDefault())) + "\"";
|
||||||
} else if (ModelUtils.isStringSchema(p)) {
|
} 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
|
// TODO: Handle more cases from `ModelUtils`, such as Date
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user