Skip to content

Commit dae0582

Browse files
committed
Exclude integer types from multipleOf = 1 specification and test
Signed-off-by: Michael Edgar <michael@xlate.io>
1 parent 1b254e7 commit dae0582

3 files changed

Lines changed: 55 additions & 8 deletions

File tree

spec/src/main/asciidoc/microprofile-openapi-spec.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ maxProperties = b`
621621
| `@DecimalMax(value = a, inclusive = false)` | `number` or `integer` | `exclusiveMaximum = a`
622622
| `@DecimalMin(value = a)` | `number` or `integer` | `minimum = a`
623623
| `@DecimalMin(value = a, inclusive = false)` | `number` or `integer` | `exclusiveMinimum = a`
624-
| `@Digits(integer = <any>, fraction = f)` | `number` or `integer` | `multipleOf` equal to `1` for integer types or 10^-f for non-integer types
624+
| `@Digits(integer = <any>, fraction = f)` | `number` | `multipleOf = 1` when `fraction` is less than 1, else `multipleOf` equal to 10^-f
625625
| `@Digits(integer = i, fraction = f)` | `string` | `pattern` matching any string value that satisfies the constraint
626626
| `@Max(a)` | `number` or `integer` | `maximum = a`
627627
| `@Min(a)` | `number` or `integer` | `minimum = a`

tck/src/main/java/org/eclipse/microprofile/openapi/apps/beanvalidation/BeanValidationData.java

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,15 @@ public class BeanValidationData {
8686
@Digits(integer = 20, fraction = 10)
8787
private BigDecimal digitsDecimal;
8888

89+
@Digits(integer = 5, fraction = 0)
90+
private float digitsFloat32AsInteger;
91+
92+
@Digits(integer = 10, fraction = 0)
93+
private double digitsFloat64AsInteger;
94+
95+
@Digits(integer = 20, fraction = 0)
96+
private BigDecimal digitsDecimalAsInteger;
97+
8998
@Digits(integer = 20, fraction = 0)
9099
private BigInteger digitsInteger;
91100

@@ -94,7 +103,7 @@ public class BeanValidationData {
94103
private BigInteger digitsCustomInteger;
95104

96105
@Digits(integer = 10, fraction = 5)
97-
private BigInteger digitsString;
106+
private String digitsString;
98107

99108
@Max(5)
100109
private int maxInt;
@@ -252,6 +261,30 @@ public void setDigitsDecimal(BigDecimal digitsDecimal) {
252261
this.digitsDecimal = digitsDecimal;
253262
}
254263

264+
public float getDigitsFloat32AsInteger() {
265+
return digitsFloat32AsInteger;
266+
}
267+
268+
public void setDigitsFloat32AsInteger(float digitsFloat32AsInteger) {
269+
this.digitsFloat32AsInteger = digitsFloat32AsInteger;
270+
}
271+
272+
public double getDigitsFloat64AsInteger() {
273+
return digitsFloat64AsInteger;
274+
}
275+
276+
public void setDigitsFloat64AsInteger(double digitsFloat64AsInteger) {
277+
this.digitsFloat64AsInteger = digitsFloat64AsInteger;
278+
}
279+
280+
public BigDecimal getDigitsDecimalAsInteger() {
281+
return digitsDecimalAsInteger;
282+
}
283+
284+
public void setDigitsDecimalAsInteger(BigDecimal digitsDecimalAsInteger) {
285+
this.digitsDecimalAsInteger = digitsDecimalAsInteger;
286+
}
287+
255288
public BigInteger getDigitsInteger() {
256289
return digitsInteger;
257290
}
@@ -268,11 +301,11 @@ public void setDigitsCustomInteger(BigInteger digitsCustomInteger) {
268301
this.digitsCustomInteger = digitsCustomInteger;
269302
}
270303

271-
public BigInteger getDigitsString() {
304+
public String getDigitsString() {
272305
return digitsString;
273306
}
274307

275-
public void setDigitsString(BigInteger digitsString) {
308+
public void setDigitsString(String digitsString) {
276309
this.digitsString = digitsString;
277310
}
278311

tck/src/main/java/org/eclipse/microprofile/openapi/tck/beanvalidation/BeanValidationTest.java

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,14 @@
1919
import static org.eclipse.microprofile.openapi.tck.utils.TCKMatchers.comparesEqualToNumber;
2020
import static org.eclipse.microprofile.openapi.tck.utils.TCKMatchers.itemOrSingleton;
2121
import static org.eclipse.microprofile.openapi.tck.utils.TCKMatchers.patternMatchesValue;
22+
import static org.hamcrest.Matchers.either;
2223
import static org.hamcrest.Matchers.hasEntry;
2324
import static org.hamcrest.Matchers.hasKey;
2425
import static org.hamcrest.Matchers.is;
2526
import static org.hamcrest.Matchers.not;
2627

28+
import java.util.Arrays;
29+
2730
import org.eclipse.microprofile.openapi.apps.beanvalidation.BeanValidationApp;
2831
import org.eclipse.microprofile.openapi.tck.AppTestBase;
2932
import org.hamcrest.Matcher;
@@ -185,12 +188,23 @@ public void defaultAndOtherGroupsTest(String format) {
185188
assertProperty(vr, "defaultAndOtherGroups", hasEntry("minLength", 1));
186189
}
187190

191+
@SuppressWarnings("unchecked")
188192
@Test(dataProvider = "formatProvider", groups = BEAN_VALIDATION)
189-
public void integerDigitsTest(String format) {
193+
public <T extends Object> void integerDigitsTest(String format) {
194+
Matcher<T> isInteger = (Matcher<T>) hasEntry(is("type"), itemOrSingleton("integer"));
195+
Matcher<T> isMultipleOfOne = (Matcher<T>) hasEntry(is(MULTIPLE_OF), comparesEqualToNumber(1));
196+
190197
ValidatableResponse vr = callEndpoint(format);
191-
assertProperty(vr, "digitsInt32", hasEntry(is(MULTIPLE_OF), comparesEqualToNumber(1)));
192-
assertProperty(vr, "digitsInt64", hasEntry(is(MULTIPLE_OF), comparesEqualToNumber(1)));
193-
assertProperty(vr, "digitsInteger", hasEntry(is(MULTIPLE_OF), comparesEqualToNumber(1)));
198+
199+
for (String property : Arrays.asList(
200+
"digitsInt32",
201+
"digitsInt64",
202+
"digitsInteger",
203+
"digitsFloat32AsInteger",
204+
"digitsFloat64AsInteger",
205+
"digitsDecimalAsInteger")) {
206+
assertProperty(vr, property, either(isInteger).or(isMultipleOfOne));
207+
}
194208
}
195209

196210
@Test(dataProvider = "formatProvider", groups = BEAN_VALIDATION)

0 commit comments

Comments
 (0)