forked from loafle/openapi-generator-original
fix java incompatible types error for number (#8018)
This commit is contained in:
parent
8cfc9b015a
commit
ca6c63f7e5
@ -883,8 +883,10 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
|||||||
if (schema.getDefault() != null) {
|
if (schema.getDefault() != null) {
|
||||||
if (SchemaTypeUtil.FLOAT_FORMAT.equals(schema.getFormat())) {
|
if (SchemaTypeUtil.FLOAT_FORMAT.equals(schema.getFormat())) {
|
||||||
return schema.getDefault().toString() + "f";
|
return schema.getDefault().toString() + "f";
|
||||||
} else {
|
} else if (SchemaTypeUtil.DOUBLE_FORMAT.equals(schema.getFormat())) {
|
||||||
return schema.getDefault().toString() + "d";
|
return schema.getDefault().toString() + "d";
|
||||||
|
} else {
|
||||||
|
return "new BigDecimal(\"" + schema.getDefault().toString() + "\")";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
@ -448,6 +448,18 @@ public class AbstractJavaCodegenTest {
|
|||||||
dateSchema.setDefault(date);
|
dateSchema.setDefault(date);
|
||||||
defaultValue = codegen.toDefaultValue(dateSchema);
|
defaultValue = codegen.toDefaultValue(dateSchema);
|
||||||
Assert.assertEquals(defaultLocalDate, LocalDate.parse(defaultValue));
|
Assert.assertEquals(defaultLocalDate, LocalDate.parse(defaultValue));
|
||||||
|
|
||||||
|
// Test default value for number without format
|
||||||
|
NumberSchema numberSchema = new NumberSchema();
|
||||||
|
Double doubleValue = 100.0;
|
||||||
|
numberSchema.setDefault(doubleValue);
|
||||||
|
defaultValue = codegen.toDefaultValue(numberSchema);
|
||||||
|
Assert.assertEquals(defaultValue, "new BigDecimal(\"" + doubleValue.toString() + "\")");
|
||||||
|
|
||||||
|
// Test default value for number with format set to double
|
||||||
|
numberSchema.setFormat("double");
|
||||||
|
defaultValue = codegen.toDefaultValue(numberSchema);
|
||||||
|
Assert.assertEquals(defaultValue, doubleValue + "d");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Loading…
x
Reference in New Issue
Block a user