Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix maximum, minimum for
Integer
(#4335)
* fix int/long max, min value (removing decimal) * fix integer min/max in parameter
- Loading branch information
Showing
7 changed files
with
70 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1444,8 +1444,28 @@ public CodegenProperty fromProperty(String name, Property p) { | |
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; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
wing328
Author
Contributor
|
||
} | ||
|
||
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 CodegenParameter fromParameter(Parameter param, Set<String> imports) { | |
} | ||
|
||
// 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(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
nit: By default, minimum is set to null. Explicitly setting it to null is redundant.