-
Notifications
You must be signed in to change notification settings - Fork 218
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add intEnum validation to NodeValidationVisitor (#2357)
* Add intEnum validation to NodeValidationVisitor * Use new copyright notice Co-authored-by: Manuel Sugawara <[email protected]> --------- Co-authored-by: Maxim Korolkov <[email protected]> Co-authored-by: Manuel Sugawara <[email protected]>
- Loading branch information
1 parent
efb35c8
commit 31a6498
Showing
4 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
smithy-model/src/main/java/software/amazon/smithy/model/validation/node/IntEnumPlugin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package software.amazon.smithy.model.validation.node; | ||
|
||
import java.util.Collection; | ||
import software.amazon.smithy.model.node.NumberNode; | ||
import software.amazon.smithy.model.shapes.IntEnumShape; | ||
import software.amazon.smithy.model.validation.ValidationUtils; | ||
|
||
|
||
/** | ||
* Validates NumberNodes against intEnum shapes' allowed enum values. | ||
*/ | ||
final class IntEnumPlugin extends FilteredPlugin<IntEnumShape, NumberNode> { | ||
|
||
IntEnumPlugin() { | ||
super(IntEnumShape.class, NumberNode.class); | ||
} | ||
|
||
@Override | ||
protected void check(IntEnumShape shape, NumberNode node, Context context, Emitter emitter) { | ||
Collection<Integer> values = shape.getEnumValues().values(); | ||
if (!values.contains(node.getValue().intValue())) { | ||
emitter.accept(node, String.format( | ||
"Integer value provided for `%s` must be one of the following values: %s, but found %s", | ||
shape.getId(), ValidationUtils.tickedList(values), node.getValue())); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters