forked from loafle/openapi-generator-original
Fix maximum, minimum for Integer (#4335)
* fix int/long max, min value (removing decimal) * fix integer min/max in parameter
This commit is contained in:
@@ -32,7 +32,7 @@ public class CodegenParameter {
|
||||
/**
|
||||
* See http://json-schema.org/latest/json-schema-validation.html#anchor17.
|
||||
*/
|
||||
public Number maximum;
|
||||
public String maximum;
|
||||
/**
|
||||
* See http://json-schema.org/latest/json-schema-validation.html#anchor17
|
||||
*/
|
||||
@@ -40,7 +40,7 @@ public class CodegenParameter {
|
||||
/**
|
||||
* See http://json-schema.org/latest/json-schema-validation.html#anchor21
|
||||
*/
|
||||
public Number minimum;
|
||||
public String minimum;
|
||||
/**
|
||||
* See http://json-schema.org/latest/json-schema-validation.html#anchor21
|
||||
*/
|
||||
|
||||
@@ -30,8 +30,8 @@ public class CodegenProperty implements Cloneable {
|
||||
public String example;
|
||||
|
||||
public String jsonSchema;
|
||||
public Double minimum;
|
||||
public Double maximum;
|
||||
public String minimum;
|
||||
public String maximum;
|
||||
public Boolean exclusiveMinimum;
|
||||
public Boolean exclusiveMaximum;
|
||||
public Boolean hasMore, required, secondaryParam;
|
||||
|
||||
@@ -1444,8 +1444,28 @@ public class DefaultCodegen {
|
||||
String type = getSwaggerType(p);
|
||||
if (p instanceof AbstractNumericProperty) {
|
||||
AbstractNumericProperty np = (AbstractNumericProperty) p;
|
||||
property.minimum = np.getMinimum();
|
||||
property.maximum = np.getMaximum();
|
||||
if (np.getMinimum() != null) {
|
||||
if (p instanceof BaseIntegerProperty) { // int, long
|
||||
property.minimum = String.valueOf(np.getMinimum().longValue());
|
||||
} else { // double, decimal
|
||||
property.minimum = String.valueOf(np.getMinimum());
|
||||
}
|
||||
} else {
|
||||
// set to null (empty) in mustache
|
||||
property.minimum = null;
|
||||
}
|
||||
|
||||
if (np.getMaximum() != null) {
|
||||
if (p instanceof BaseIntegerProperty) { // int, long
|
||||
property.maximum = String.valueOf(np.getMaximum().longValue());
|
||||
} else { // double, decimal
|
||||
property.maximum = String.valueOf(np.getMaximum());
|
||||
}
|
||||
} else {
|
||||
// set to null (empty) in mustache
|
||||
property.maximum = null;
|
||||
}
|
||||
|
||||
property.exclusiveMinimum = np.getExclusiveMinimum();
|
||||
property.exclusiveMaximum = np.getExclusiveMaximum();
|
||||
|
||||
@@ -2314,9 +2334,15 @@ public class DefaultCodegen {
|
||||
}
|
||||
|
||||
// validation
|
||||
p.maximum = qp.getMaximum();
|
||||
// handle maximum, minimum properly for int/long by removing the trailing ".0"
|
||||
if ("integer".equals(type)) {
|
||||
p.maximum = qp.getMaximum() == null ? null : String.valueOf(qp.getMaximum().longValue());
|
||||
p.minimum = qp.getMinimum() == null ? null : String.valueOf(qp.getMinimum().longValue());
|
||||
} else {
|
||||
p.maximum = qp.getMaximum() == null ? null : String.valueOf(qp.getMaximum());
|
||||
p.minimum = qp.getMinimum() == null ? null : String.valueOf(qp.getMinimum());
|
||||
}
|
||||
p.exclusiveMaximum = qp.isExclusiveMaximum();
|
||||
p.minimum = qp.getMinimum();
|
||||
p.exclusiveMinimum = qp.isExclusiveMinimum();
|
||||
p.maxLength = qp.getMaxLength();
|
||||
p.minLength = qp.getMinLength();
|
||||
|
||||
@@ -553,20 +553,20 @@ public class FlaskConnexionCodegen extends DefaultCodegen implements CodegenConf
|
||||
example = "'" + escapeText(example) + "'";
|
||||
} else if ("Integer".equals(type) || "int".equals(type)) {
|
||||
if(p.minimum != null) {
|
||||
example = "" + (p.minimum.intValue() + 1);
|
||||
example = "" + (Integer.valueOf(p.minimum) + 1);
|
||||
}
|
||||
if(p.maximum != null) {
|
||||
example = "" + p.maximum.intValue();
|
||||
example = "" + p.maximum;
|
||||
} else if (example == null) {
|
||||
example = "56";
|
||||
}
|
||||
|
||||
} else if ("Long".equalsIgnoreCase(type)) {
|
||||
if(p.minimum != null) {
|
||||
example = "" + (p.minimum.longValue() + 1);
|
||||
example = "" + (Long.valueOf(p.minimum) + 1);
|
||||
}
|
||||
if(p.maximum != null) {
|
||||
example = "" + p.maximum.longValue();
|
||||
example = "" + p.maximum;
|
||||
} else if (example == null) {
|
||||
example = "789";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user