Skip to content

Commit 14caeb6

Browse files
authored
Merge pull request #1458 from feliperuiz/allow-multipleOf-between-0-and-1
Handle multipleOf between 0 and 1
2 parents 23879c2 + 15f64d4 commit 14caeb6

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/OpenAPIDeserializer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2189,7 +2189,7 @@ public Schema getSchema(ObjectNode node, String location, ParseResult result){
21892189

21902190
BigDecimal bigDecimal = getBigDecimal("multipleOf",node,false,location,result);
21912191
if(bigDecimal != null) {
2192-
if(bigDecimal.intValue() > 0) {
2192+
if(bigDecimal.compareTo(BigDecimal.ZERO) > 0) {
21932193
schema.setMultipleOf(bigDecimal);
21942194
}else{
21952195
result.warning(location,"multipleOf value must be > 0");

modules/swagger-parser/src/test/java/io/swagger/parser/OpenAPIParserTest.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
import io.swagger.v3.parser.core.models.ParseOptions;
1515
import io.swagger.v3.parser.core.models.SwaggerParseResult;
1616
import io.swagger.v3.core.util.Json;
17+
import java.math.BigDecimal;
18+
import java.math.MathContext;
1719
import org.junit.Test;
1820
import org.testng.Assert;
1921

@@ -588,5 +590,31 @@ public void testIssue1433_ResolveSchemaWithoutType() {
588590
final Object baz = inputProperties.get("baz");
589591
assertEquals(baz.getClass(), StringSchema.class);
590592
}
593+
594+
@Test
595+
public void testMultipleOfBetweenZeroAndOne() {
596+
String spec =
597+
"openapi: 3.0.0\n" +
598+
"info:\n" +
599+
" version: 0.0.0\n" +
600+
" title: \"test\"\n" +
601+
"components:\n" +
602+
" schemas:\n" +
603+
" Test:\n" +
604+
" type: object\n" +
605+
" properties:\n" +
606+
" decimal_value:\n" +
607+
" type: number\n" +
608+
" multipleOf: 0.3\n";
609+
610+
OpenAPIParser openApiParser = new OpenAPIParser();
611+
ParseOptions options = new ParseOptions();
612+
613+
OpenAPI openAPI = openApiParser.readContents(spec, null, options).getOpenAPI();
614+
ObjectSchema schema = (ObjectSchema) openAPI.getComponents().getSchemas().get("Test");
615+
Schema decimalValue = schema.getProperties().get("decimal_value");
616+
BigDecimal multipleOf = decimalValue.getMultipleOf();
617+
assertEquals(multipleOf, new BigDecimal("0.3", new MathContext(multipleOf.precision())));
618+
}
591619
}
592620

0 commit comments

Comments
 (0)