Skip to content

Commit

Permalink
fix: swagger-2-module multipleOf rounding error (#365)
Browse files Browse the repository at this point in the history
  • Loading branch information
CarstenWickner authored Jun 15, 2023
1 parent baea9b6 commit c645b5c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
#### Added
- consider `@Schema(additionalProperties = ...)` attribute (only values `TRUE` and `FALSE`), when it is annotated on a type (not on a member)

#### Fixed
- avoid rounding error when taking over the value from `@Schema(multipleOf)`

## [4.31.1] - 2023-04-28
### `jsonschema-generator`
#### Fixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ protected String resolvePattern(MemberScope<?, ?> member) {
*/
protected BigDecimal resolveMultipleOf(MemberScope<?, ?> member) {
return this.getSchemaAnnotationValue(member, Schema::multipleOf, multipleOf -> multipleOf != 0)
.map(BigDecimal::new)
.map(BigDecimal::valueOf)
.orElse(null);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Scanner;
Expand Down Expand Up @@ -96,10 +97,10 @@ static class TestClass {
@Schema(description = "field description", nullable = true, allowableValues = {"A", "B", "C", "D"}, minLength = 1, maxLength = 1)
public String fieldWithDescriptionAndAllowableValues;

@Schema(minimum = "15", maximum = "20")
public int fieldWithInclusiveNumericRange;
@Schema(minimum = "15", maximum = "20", multipleOf = 0.0123456789)
public BigDecimal fieldWithInclusiveNumericRange;

@Schema(minimum = "14", maximum = "21", exclusiveMinimum = true, exclusiveMaximum = true, required = true)
@Schema(minimum = "14", maximum = "21", exclusiveMinimum = true, exclusiveMaximum = true, required = true, multipleOf = 0.1)
public int fieldWithExclusiveNumericRange;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@
"fieldWithExclusiveNumericRange": {
"type": "integer",
"exclusiveMinimum": 14,
"exclusiveMaximum": 21
"exclusiveMaximum": 21,
"multipleOf": 0.1
},
"fieldWithInclusiveNumericRange": {
"type": "integer",
"type": "number",
"minimum": 15,
"maximum": 20
"maximum": 20,
"multipleOf": 0.0123456789
},
"fieldWithOverriddenName": {
"minItems": 1,
Expand Down

0 comments on commit c645b5c

Please sign in to comment.