Skip to content

Commit

Permalink
Merge pull request #400 from swagger-api/issue-339
Browse files Browse the repository at this point in the history
Don't convert minimum, maximum to double
  • Loading branch information
fehguy authored Feb 22, 2017
2 parents 8c466c2 + b87723f commit 22ecf73
Show file tree
Hide file tree
Showing 3 changed files with 1,286 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -480,10 +480,10 @@ else if ("formData".equals(value)) {
map.put(DEFAULT, defaultValue);
sp.setDefault(defaultValue);

Double dbl = getDouble("maximum", obj, false, location, result);
if(dbl != null) {
map.put(MAXIMUM, new BigDecimal(dbl.toString()));
sp.setMaximum(new BigDecimal(dbl.toString()));
String numberAsString = getString("maximum", obj, false, location, result);
if(numberAsString != null) {
map.put(MAXIMUM, new BigDecimal(numberAsString));
sp.setMaximum(new BigDecimal(numberAsString));
}

Boolean bl = getBoolean("exclusiveMaximum", obj, false, location, result);
Expand All @@ -492,10 +492,10 @@ else if ("formData".equals(value)) {
sp.setExclusiveMaximum(bl);
}

dbl = getDouble("minimum", obj, false, location, result);
if(dbl != null) {
map.put(MINIMUM, new BigDecimal(dbl.toString()));
sp.setMinimum(new BigDecimal(dbl.toString()));
numberAsString = getString("minimum", obj, false, location, result);
if(numberAsString != null) {
map.put(MINIMUM, new BigDecimal(numberAsString.toString()));
sp.setMinimum(new BigDecimal(numberAsString.toString()));
}

bl = getBoolean("exclusiveMinimum", obj, false, location, result);
Expand Down Expand Up @@ -527,7 +527,7 @@ else if ("formData".equals(value)) {
map.put(MAX_LENGTH, iv);
sp.setMaxLength(iv);

dbl = getDouble("multipleOf", obj, false, location, result);
Double dbl = getDouble("multipleOf", obj, false, location, result);
if(dbl != null) {
map.put(MULTIPLE_OF, new BigDecimal(dbl.toString()));
sp.setMultipleOf(dbl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -670,13 +670,26 @@ public void testCodegenPetstore() {
assertNotNull(orderIdPathParam.getMinimum());

BigDecimal minimum = orderIdPathParam.getMinimum();
assertEquals(minimum.toString(), "1.0");
assertEquals(minimum.toString(), "1");

FormParameter formParam = (FormParameter)swagger.getPath("/fake").getPost().getParameters().get(3);

assertEquals(formParam.getMinimum().toString(), "32.1");
}

@Test
public void testIssue339() throws Exception {
SwaggerParser parser = new SwaggerParser();
final Swagger swagger = parser.read("src/test/resources/issue-339.json");

Parameter param = swagger.getPath("/store/order/{orderId}").getGet().getParameters().get(0);
assertTrue(param instanceof PathParameter);
PathParameter pp = (PathParameter) param;

assertTrue(pp.getMinimum().toString().equals("1"));
assertTrue(pp.getMaximum().toString().equals("5"));
}

@Test
public void testCodegenIssue4555() throws Exception {
SwaggerParser parser = new SwaggerParser();
Expand Down
Loading

0 comments on commit 22ecf73

Please sign in to comment.