Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,13 @@ public Model definition(ObjectNode node, String location, ParseResult result) {
impl.setUniqueItems(bp);
}


BigDecimal bd = getBigDecimal("minimum", node, false, location, result);
impl.setMinimum(bd);

bd = getBigDecimal("maximum", node, false, location, result);
impl.setMaximum(bd);

bp = getBoolean("exclusiveMaximum", node, false, location, result);
if(bp != null) {
impl.setExclusiveMaximum(bp);
Expand Down Expand Up @@ -816,6 +823,7 @@ public Model definition(ObjectNode node, String location, ParseResult result) {
impl.setMultipleOf(multipleOf);
}


ap = node.get("enum");
if(ap != null) {
ArrayNode arrayNode = getArray("enum", node, false, location, result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import io.swagger.models.properties.Property;
import io.swagger.models.properties.RefProperty;
import io.swagger.models.properties.StringProperty;
import io.swagger.parser.util.TestUtils;
import io.swagger.parser.util.SwaggerDeserializationResult;
import io.swagger.parser.util.TestUtils;
import io.swagger.util.Json;
Expand Down Expand Up @@ -956,6 +957,7 @@ public void testIssue393() {
assertNotNull(swagger.getVendorExtensions().get("x-error-defs"));
}

@Test
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add forgotten @Test annotation

public void testBadFormat() throws Exception {
SwaggerParser parser = new SwaggerParser();
final Swagger swagger = parser.read("src/test/resources/bad_format.yaml");
Expand Down Expand Up @@ -994,6 +996,57 @@ public void testBadFormat() throws Exception {
assertEquals(queryParameter.getCollectionFormat(), "multi");
assertEquals(queryParameter.isUniqueItems(), true);
}
@Test
public void testNumberAttributes() throws Exception {
SwaggerParser parser = new SwaggerParser();
Swagger swagger = parser.read(TestUtils.getResourceAbsolutePath("/number_attributes.yaml"));

ModelImpl numberType = (ModelImpl)swagger.getDefinitions().get("NumberType");
assertNotNull(numberType);
assertNotNull(numberType.getEnum());
assertEquals(numberType.getEnum().size(), 2);
List<String> numberTypeEnumValues = numberType.getEnum();
assertEquals(numberTypeEnumValues.get(0), "1.0");
assertEquals(numberTypeEnumValues.get(1), "2.0");
assertEquals(numberType.getDefaultValue(), new BigDecimal("1.0"));
assertEquals(numberType.getMinimum(), new BigDecimal("1.0"));
assertEquals(numberType.getMaximum(), new BigDecimal("2.0"));

ModelImpl numberDoubleType = (ModelImpl)swagger.getDefinitions().get("NumberDoubleType");
assertNotNull(numberDoubleType);
assertNotNull(numberDoubleType.getEnum());
assertEquals(numberDoubleType.getEnum().size(), 2);
List<String> numberDoubleTypeEnumValues = numberDoubleType.getEnum();
assertEquals(numberDoubleTypeEnumValues.get(0), "1.0");
assertEquals(numberDoubleTypeEnumValues.get(1), "2.0");
assertEquals(numberDoubleType.getDefaultValue(), new BigDecimal("1.0"));
assertEquals(numberDoubleType.getMinimum(), new BigDecimal("1.0"));
assertEquals(numberDoubleType.getMaximum(), new BigDecimal("2.0"));

ModelImpl integerType = (ModelImpl)swagger.getDefinitions().get("IntegerType");
assertNotNull(integerType);
assertNotNull(integerType.getEnum());
assertEquals(integerType.getEnum().size(), 2);
List<String> integerTypeEnumValues = integerType.getEnum();
assertEquals(integerTypeEnumValues.get(0), "1");
assertEquals(integerTypeEnumValues.get(1), "2");
assertEquals(integerType.getDefaultValue(), new Integer("1"));
assertEquals(integerType.getMinimum(), new BigDecimal("1"));
assertEquals(integerType.getMaximum(), new BigDecimal("2"));

ModelImpl integerInt32Type = (ModelImpl)swagger.getDefinitions().get("IntegerInt32Type");
assertNotNull(integerInt32Type);
assertNotNull(integerInt32Type.getEnum());
assertEquals(integerInt32Type.getEnum().size(), 2);
List<String> integerInt32TypeEnumValues = integerInt32Type.getEnum();
assertEquals(integerInt32TypeEnumValues.get(0), "1");
assertEquals(integerInt32TypeEnumValues.get(1), "2");
assertEquals(integerInt32Type.getDefaultValue(), new Integer("1"));
assertEquals(integerInt32Type.getMinimum(), new BigDecimal("1"));
assertEquals(integerInt32Type.getMaximum(), new BigDecimal("2"));


}

@Test
public void testDefinitionExample() throws Exception {
Expand Down
45 changes: 45 additions & 0 deletions modules/swagger-parser/src/test/resources/number_attributes.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
swagger: '2.0'
info:
version: 1.0.0
title: Pets Store
paths: {}
definitions:

NumberType:
type: number
enum:
- 1.0
- 2.0
default: 1.0
minimum: 1.0
maximum: 2.0

NumberDoubleType:
type: number
format: double
enum:
- 1.0
- 2.0
default: 1.0
minimum: 1.0
maximum: 2.0

IntegerType:
type: integer
enum:
- 1
- 2
default: 1
minimum: 1
maximum: 2

IntegerInt32Type:
type: integer
format: int32
enum:
- 1
- 2
default: 1
minimum: 1
maximum: 2