Skip to content

Commit 32c5a03

Browse files
Merge pull request #216 from JordonPhillips/minmax
Allow min to equal max in range
2 parents 3829739 + 68f75ee commit 32c5a03

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/RangeTraitValidator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ private List<ValidationEvent> validateRangeTrait(Model model, Shape shape, Range
5757
// Makes sure that `min` is less than `max`
5858
trait.getMin()
5959
.flatMap(min -> trait.getMax().map(max -> Pair.of(min, max)))
60-
.filter(pair -> pair.getLeft().compareTo(pair.getRight()) >= 0)
60+
.filter(pair -> pair.getLeft().compareTo(pair.getRight()) > 0)
6161
.map(pair -> error(shape, trait, "A range trait is applied with a `min` value greater than "
62-
+ "or equal to its `max` value."))
62+
+ "its `max` value."))
6363
.map(events::add);
6464

6565
return events;

smithy-model/src/test/resources/software/amazon/smithy/model/errorfiles/validators/range-trait.errors

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
[ERROR] ns.foo#Invalid4: Shape `ns.foo#Invalid4` is marked with the `range` trait, but its `min` property is a decimal (0.5) when its shape (`long`) does not support decimals. | RangeTrait
99
[ERROR] ns.foo#Invalid5: Shape `ns.foo#Invalid5` is marked with the `range` trait, but its `max` property is a decimal (10.5) when its shape (`bigInteger`) does not support decimals. | RangeTrait
1010
[ERROR] ns.foo#Invalid5: Shape `ns.foo#Invalid5` is marked with the `range` trait, but its `min` property is a decimal (0.5) when its shape (`bigInteger`) does not support decimals. | RangeTrait
11-
[ERROR] ns.foo#Invalid6: A range trait is applied with a `min` value greater than or equal to its `max` value. | RangeTrait
11+
[ERROR] ns.foo#Invalid6: A range trait is applied with a `min` value greater than its `max` value. | RangeTrait
1212
[ERROR] ns.foo#Structure$InvalidMember1: Member `ns.foo#Structure$InvalidMember1` is marked with the `range` trait, but its `max` property is a decimal (10.5) when its target (`smithy.api#Byte`) does not support decimals. | RangeTrait
1313
[ERROR] ns.foo#Structure$InvalidMember1: Member `ns.foo#Structure$InvalidMember1` is marked with the `range` trait, but its `min` property is a decimal (0.5) when its target (`smithy.api#Byte`) does not support decimals. | RangeTrait
1414
[ERROR] ns.foo#Structure$InvalidMember2: Member `ns.foo#Structure$InvalidMember2` is marked with the `range` trait, but its `max` property is a decimal (10.5) when its target (`smithy.api#Short`) does not support decimals. | RangeTrait
@@ -19,4 +19,4 @@
1919
[ERROR] ns.foo#Structure$InvalidMember4: Member `ns.foo#Structure$InvalidMember4` is marked with the `range` trait, but its `min` property is a decimal (0.5) when its target (`smithy.api#Long`) does not support decimals. | RangeTrait
2020
[ERROR] ns.foo#Structure$InvalidMember5: Member `ns.foo#Structure$InvalidMember5` is marked with the `range` trait, but its `max` property is a decimal (10.5) when its target (`smithy.api#BigInteger`) does not support decimals. | RangeTrait
2121
[ERROR] ns.foo#Structure$InvalidMember5: Member `ns.foo#Structure$InvalidMember5` is marked with the `range` trait, but its `min` property is a decimal (0.5) when its target (`smithy.api#BigInteger`) does not support decimals. | RangeTrait
22-
[ERROR] ns.foo#Structure$InvalidMember6: A range trait is applied with a `min` value greater than or equal to its `max` value. | RangeTrait
22+
[ERROR] ns.foo#Structure$InvalidMember6: A range trait is applied with a `min` value greater than its `max` value. | RangeTrait

smithy-model/src/test/resources/software/amazon/smithy/model/errorfiles/validators/range-trait.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,13 @@
8989
"max": 10.5e4
9090
}
9191
},
92+
"ValidMember13": {
93+
"target": "smithy.api#Integer",
94+
"range": {
95+
"min": 5,
96+
"max": 5
97+
}
98+
},
9299
"InvalidMember1": {
93100
"target": "smithy.api#Byte",
94101
"range": {
@@ -210,6 +217,13 @@
210217
"max": 10.5
211218
}
212219
},
220+
"Valid12": {
221+
"type": "integer",
222+
"range": {
223+
"min": 5,
224+
"max": 5
225+
}
226+
},
213227
"Invalid1": {
214228
"type": "byte",
215229
"range": {

0 commit comments

Comments
 (0)