forked from loafle/openapi-generator-original
Fix ClassCastException when uuid has default value (#13698)
* fix cast error for uuid default * fix java uuid default value
This commit is contained in:
parent
daf475a96d
commit
cafdf64ca5
@ -1050,7 +1050,7 @@ public abstract class AbstractCSharpCodegen 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 {
|
||||
|
@ -970,7 +970,7 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
return null;
|
||||
} else if (ModelUtils.isURISchema(schema)) {
|
||||
if (schema.getDefault() != null) {
|
||||
return "URI.create(\"" + escapeText((String) schema.getDefault()) + "\")";
|
||||
return "URI.create(\"" + escapeText(String.valueOf(schema.getDefault())) + "\")";
|
||||
}
|
||||
return null;
|
||||
} else if (ModelUtils.isStringSchema(schema)) {
|
||||
@ -992,8 +992,10 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} else if (schema.getDefault() instanceof UUID) {
|
||||
return "UUID.fromString(\"" + String.valueOf(schema.getDefault()) + "\")";
|
||||
} else {
|
||||
_default = (String) schema.getDefault();
|
||||
_default = String.valueOf(schema.getDefault());
|
||||
}
|
||||
|
||||
if (schema.getEnum() == null) {
|
||||
|
@ -1061,7 +1061,7 @@ public abstract class AbstractKotlinCodegen 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 "\"" + escapeText(_default) + "\"";
|
||||
} else {
|
||||
|
@ -161,7 +161,7 @@ abstract public class AbstractRubyCodegen extends DefaultCodegen implements Code
|
||||
} else if (p.getDefault() instanceof java.time.OffsetDateTime) {
|
||||
return "Time.parse(\"" + String.format(Locale.ROOT, ((java.time.OffsetDateTime) p.getDefault()).atZoneSameInstant(ZoneId.systemDefault()).toString(), "") + "\")";
|
||||
} else {
|
||||
return "'" + escapeText((String) p.getDefault()) + "'";
|
||||
return "'" + escapeText((String.valueOf(p.getDefault()))) + "'";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -718,7 +718,7 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp
|
||||
return UNDEFINED_VALUE;
|
||||
} else if (ModelUtils.isStringSchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
return "'" + escapeText((String) p.getDefault()) + "'";
|
||||
return "'" + escapeText(String.valueOf(p.getDefault())) + "'";
|
||||
}
|
||||
return UNDEFINED_VALUE;
|
||||
} else {
|
||||
|
@ -828,7 +828,7 @@ public class CrystalClientCodegen extends DefaultCodegen {
|
||||
} else if (p.getDefault() instanceof java.time.OffsetDateTime) {
|
||||
return "Time.parse(\"" + String.format(Locale.ROOT, ((java.time.OffsetDateTime) p.getDefault()).atZoneSameInstant(ZoneId.systemDefault()).toString(), "") + "\")";
|
||||
} else {
|
||||
return "\"" + escapeText((String) p.getDefault()) + "\"";
|
||||
return "\"" + escapeText((String.valueOf(p.getDefault()))) + "\"";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -848,10 +848,10 @@ public class RClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
}
|
||||
} else if (ModelUtils.isStringSchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
if (Pattern.compile("\r\n|\r|\n").matcher((String) p.getDefault()).find())
|
||||
return "'''" + p.getDefault() + "'''";
|
||||
if (Pattern.compile("\r\n|\r|\n").matcher((String.valueOf(p.getDefault()))).find())
|
||||
return "'''" + p.getDefault().toString() + "'''";
|
||||
else
|
||||
return "\"" + ((String) p.getDefault()).replaceAll("\"", "\\\"") + "\"";
|
||||
return "\"" + ((String.valueOf(p.getDefault()))).replaceAll("\"", "\\\"") + "\"";
|
||||
}
|
||||
} else if (ModelUtils.isArraySchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
|
@ -1504,6 +1504,10 @@ components:
|
||||
type: string
|
||||
format: uuid
|
||||
example: 72f98069-206d-4f12-9f12-3d1e525a8e84
|
||||
uuid_with_default:
|
||||
type: string
|
||||
format: uuid
|
||||
default: 11111111-206d-4f12-9f12-3d1e525a8e84
|
||||
password:
|
||||
type: string
|
||||
format: password
|
||||
|
@ -1496,6 +1496,10 @@ components:
|
||||
example: 72f98069-206d-4f12-9f12-3d1e525a8e84
|
||||
format: uuid
|
||||
type: string
|
||||
uuid_with_default:
|
||||
default: 11111111-206d-4f12-9f12-3d1e525a8e84
|
||||
format: uuid
|
||||
type: string
|
||||
password:
|
||||
format: password
|
||||
maxLength: 64
|
||||
|
@ -20,6 +20,7 @@
|
||||
|**date** | **LocalDate** | | |
|
||||
|**dateTime** | **OffsetDateTime** | | [optional] |
|
||||
|**uuid** | **UUID** | | [optional] |
|
||||
|**uuidWithDefault** | **UUID** | | [optional] |
|
||||
|**password** | **String** | | |
|
||||
|**patternWithDigits** | **String** | A string that is a 10 digit number. Can have leading zeros. | [optional] |
|
||||
|**patternWithDigitsAndDelimiter** | **String** | A string starting with 'image_' (case insensitive) and one to three digits following i.e. Image_01. | [optional] |
|
||||
|
@ -106,6 +106,10 @@ public class FormatTest {
|
||||
@SerializedName(SERIALIZED_NAME_UUID)
|
||||
private UUID uuid;
|
||||
|
||||
public static final String SERIALIZED_NAME_UUID_WITH_DEFAULT = "uuid_with_default";
|
||||
@SerializedName(SERIALIZED_NAME_UUID_WITH_DEFAULT)
|
||||
private UUID uuidWithDefault = UUID.fromString("11111111-206d-4f12-9f12-3d1e525a8e84");
|
||||
|
||||
public static final String SERIALIZED_NAME_PASSWORD = "password";
|
||||
@SerializedName(SERIALIZED_NAME_PASSWORD)
|
||||
private String password;
|
||||
@ -430,6 +434,29 @@ public class FormatTest {
|
||||
}
|
||||
|
||||
|
||||
public FormatTest uuidWithDefault(UUID uuidWithDefault) {
|
||||
|
||||
this.uuidWithDefault = uuidWithDefault;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get uuidWithDefault
|
||||
* @return uuidWithDefault
|
||||
**/
|
||||
@javax.annotation.Nullable
|
||||
@ApiModelProperty(value = "")
|
||||
|
||||
public UUID getUuidWithDefault() {
|
||||
return uuidWithDefault;
|
||||
}
|
||||
|
||||
|
||||
public void setUuidWithDefault(UUID uuidWithDefault) {
|
||||
this.uuidWithDefault = uuidWithDefault;
|
||||
}
|
||||
|
||||
|
||||
public FormatTest password(String password) {
|
||||
|
||||
this.password = password;
|
||||
@ -557,6 +584,7 @@ public class FormatTest {
|
||||
Objects.equals(this.date, formatTest.date) &&
|
||||
Objects.equals(this.dateTime, formatTest.dateTime) &&
|
||||
Objects.equals(this.uuid, formatTest.uuid) &&
|
||||
Objects.equals(this.uuidWithDefault, formatTest.uuidWithDefault) &&
|
||||
Objects.equals(this.password, formatTest.password) &&
|
||||
Objects.equals(this.patternWithDigits, formatTest.patternWithDigits) &&
|
||||
Objects.equals(this.patternWithDigitsAndDelimiter, formatTest.patternWithDigitsAndDelimiter)&&
|
||||
@ -565,7 +593,7 @@ public class FormatTest {
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(integer, int32, int64, number, _float, _double, decimal, string, Arrays.hashCode(_byte), binary, date, dateTime, uuid, password, patternWithDigits, patternWithDigitsAndDelimiter, additionalProperties);
|
||||
return Objects.hash(integer, int32, int64, number, _float, _double, decimal, string, Arrays.hashCode(_byte), binary, date, dateTime, uuid, uuidWithDefault, password, patternWithDigits, patternWithDigitsAndDelimiter, additionalProperties);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -585,6 +613,7 @@ public class FormatTest {
|
||||
sb.append(" date: ").append(toIndentedString(date)).append("\n");
|
||||
sb.append(" dateTime: ").append(toIndentedString(dateTime)).append("\n");
|
||||
sb.append(" uuid: ").append(toIndentedString(uuid)).append("\n");
|
||||
sb.append(" uuidWithDefault: ").append(toIndentedString(uuidWithDefault)).append("\n");
|
||||
sb.append(" password: ").append(toIndentedString(password)).append("\n");
|
||||
sb.append(" patternWithDigits: ").append(toIndentedString(patternWithDigits)).append("\n");
|
||||
sb.append(" patternWithDigitsAndDelimiter: ").append(toIndentedString(patternWithDigitsAndDelimiter)).append("\n");
|
||||
@ -624,6 +653,7 @@ public class FormatTest {
|
||||
openapiFields.add("date");
|
||||
openapiFields.add("dateTime");
|
||||
openapiFields.add("uuid");
|
||||
openapiFields.add("uuid_with_default");
|
||||
openapiFields.add("password");
|
||||
openapiFields.add("pattern_with_digits");
|
||||
openapiFields.add("pattern_with_digits_and_delimiter");
|
||||
@ -661,6 +691,9 @@ public class FormatTest {
|
||||
if ((jsonObj.get("uuid") != null && !jsonObj.get("uuid").isJsonNull()) && !jsonObj.get("uuid").isJsonPrimitive()) {
|
||||
throw new IllegalArgumentException(String.format("Expected the field `uuid` to be a primitive type in the JSON string but got `%s`", jsonObj.get("uuid").toString()));
|
||||
}
|
||||
if ((jsonObj.get("uuid_with_default") != null && !jsonObj.get("uuid_with_default").isJsonNull()) && !jsonObj.get("uuid_with_default").isJsonPrimitive()) {
|
||||
throw new IllegalArgumentException(String.format("Expected the field `uuid_with_default` to be a primitive type in the JSON string but got `%s`", jsonObj.get("uuid_with_default").toString()));
|
||||
}
|
||||
if (!jsonObj.get("password").isJsonPrimitive()) {
|
||||
throw new IllegalArgumentException(String.format("Expected the field `password` to be a primitive type in the JSON string but got `%s`", jsonObj.get("password").toString()));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user