Skip to content

Commit

Permalink
Rename to allowConstraintErrors
Browse files Browse the repository at this point in the history
  • Loading branch information
srchase committed Aug 31, 2023
1 parent edef8b8 commit e5bcfd3
Show file tree
Hide file tree
Showing 13 changed files with 31 additions and 30 deletions.
4 changes: 2 additions & 2 deletions docs/source-2.0/spec/documentation-traits.rst
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ Each ``example`` trait value is a structure with the following members:
- :ref:`examples-ErrorExample-structure`
- Provides an error shape ID and example error parameters for the
operation.
* - disableConstraints
* - allowConstraintErrors
- ``boolean``
- Set to true to lower input constraint trait validations to warnings.
This can only be set when ``error`` is provided.
Expand Down Expand Up @@ -186,7 +186,7 @@ MUST NOT be defined for the same example.
message: "Invalid 'foo'. Special character not allowed."
}
},
disableConstraints: true
allowConstraintErrors: true
}
])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,15 @@ public static final class Example implements ToNode, ToSmithyBuilder<Example> {
private final ObjectNode input;
private final ObjectNode output;
private final ErrorExample error;
private final boolean disableConstraints;
private final boolean allowConstraintErrors;

private Example(Builder builder) {
this.title = Objects.requireNonNull(builder.title, "Example title must not be null");
this.documentation = builder.documentation;
this.input = builder.input;
this.output = builder.output;
this.error = builder.error;
this.disableConstraints = builder.disableConstraints;
this.allowConstraintErrors = builder.allowConstraintErrors;
}

/**
Expand Down Expand Up @@ -166,10 +166,10 @@ public Optional<ErrorExample> getError() {
}

/**
* @return Returns true if input constraints validation has been disabled.
* @return Returns true if input constraints errors are allowed.
*/
public boolean getDisableConstraints() {
return disableConstraints;
public boolean getAllowConstraintErrors() {
return allowConstraintErrors;
}

@Override
Expand All @@ -178,7 +178,8 @@ public Node toNode() {
.withMember("title", Node.from(title))
.withOptionalMember("documentation", getDocumentation().map(Node::from))
.withOptionalMember("error", getError().map(ErrorExample::toNode))
.withOptionalMember("disableConstraints", BooleanNode.from(disableConstraints).asBooleanNode());
.withOptionalMember("allowConstraintErrors", BooleanNode.from(allowConstraintErrors)
.asBooleanNode());

if (!input.isEmpty()) {
builder.withMember("input", input);
Expand All @@ -193,7 +194,7 @@ public Node toNode() {
@Override
public Builder toBuilder() {
return new Builder().documentation(documentation).title(title).input(input).output(output).error(error)
.disableConstraints(disableConstraints);
.allowConstraintErrors(allowConstraintErrors);
}

public static Builder builder() {
Expand All @@ -209,7 +210,7 @@ public static final class Builder implements SmithyBuilder<Example> {
private ObjectNode input = Node.objectNode();
private ObjectNode output;
private ErrorExample error;
private boolean disableConstraints;
private boolean allowConstraintErrors;

@Override
public Example build() {
Expand Down Expand Up @@ -241,8 +242,8 @@ public Builder error(ErrorExample error) {
return this;
}

public Builder disableConstraints(Boolean disableConstraints) {
this.disableConstraints = disableConstraints;
public Builder allowConstraintErrors(Boolean allowConstraintErrors) {
this.allowConstraintErrors = allowConstraintErrors;
return this;
}
}
Expand Down Expand Up @@ -339,7 +340,7 @@ private static Example exampleFromNode(ObjectNode node) {
.getObjectMember("input", builder::input)
.getObjectMember("output", builder::output)
.getMember("error", ErrorExample::fromNode, builder::error)
.getBooleanMember("disableConstraints", builder::disableConstraints);
.getBooleanMember("allowConstraintErrors", builder::allowConstraintErrors);
return builder.build();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public enum Feature {
RANGE_TRAIT_ZERO_VALUE_WARNING,

// Lowers severity of constraint trait validations to WARNING.
DISABLE_CONSTRAINTS;
ALLOW_CONSTRAINT_ERRORS;

public static Feature fromNode(Node node) {
return Feature.valueOf(node.expectStringNode().getValue());
Expand Down Expand Up @@ -328,7 +328,7 @@ public List<ValidationEvent> structureShape(StructureShape shape) {

for (MemberShape member : members.values()) {
if (member.isRequired() && !object.getMember(member.getMemberName()).isPresent()) {
Severity severity = this.validationContext.hasFeature(Feature.DISABLE_CONSTRAINTS)
Severity severity = this.validationContext.hasFeature(Feature.ALLOW_CONSTRAINT_ERRORS)
? Severity.WARNING : Severity.ERROR;
events.add(event(String.format(
"Missing required structure member `%s` for `%s`",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ protected void check(Shape shape, LengthTrait trait, StringNode node, Context co
}

private Severity getSeverity(Context context) {
return context.hasFeature(NodeValidationVisitor.Feature.DISABLE_CONSTRAINTS)
return context.hasFeature(NodeValidationVisitor.Feature.ALLOW_CONSTRAINT_ERRORS)
? Severity.WARNING : Severity.ERROR;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ protected void check(Shape shape, LengthTrait trait, ObjectNode node, Context co
}

private Severity getSeverity(Context context) {
return context.hasFeature(NodeValidationVisitor.Feature.DISABLE_CONSTRAINTS)
return context.hasFeature(NodeValidationVisitor.Feature.ALLOW_CONSTRAINT_ERRORS)
? Severity.WARNING : Severity.ERROR;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ protected void check(Shape shape, PatternTrait trait, StringNode node, Context c


private Severity getSeverity(Context context) {
return context.hasFeature(NodeValidationVisitor.Feature.DISABLE_CONSTRAINTS)
return context.hasFeature(NodeValidationVisitor.Feature.ALLOW_CONSTRAINT_ERRORS)
? Severity.WARNING : Severity.ERROR;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,12 @@ protected void check(Shape shape, Context context, RangeTrait trait, NumberNode
private Severity getSeverity(NumberNode node, Context context) {
boolean zeroValueWarning = context
.hasFeature(NodeValidationVisitor.Feature.RANGE_TRAIT_ZERO_VALUE_WARNING);
boolean rangeTraitWarning = context.hasFeature(NodeValidationVisitor.Feature.DISABLE_CONSTRAINTS);
boolean rangeTraitWarning = context.hasFeature(NodeValidationVisitor.Feature.ALLOW_CONSTRAINT_ERRORS);
return (zeroValueWarning && node.isZero()) || rangeTraitWarning ? Severity.WARNING : Severity.ERROR;
}

private Severity getSeverity(Context context) {
return context.hasFeature(NodeValidationVisitor.Feature.DISABLE_CONSTRAINTS)
return context.hasFeature(NodeValidationVisitor.Feature.ALLOW_CONSTRAINT_ERRORS)
? Severity.WARNING : Severity.ERROR;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ protected void check(Shape shape, LengthTrait trait, StringNode node, Context co
}

private Severity getSeverity(Context context) {
return context.hasFeature(NodeValidationVisitor.Feature.DISABLE_CONSTRAINTS)
return context.hasFeature(NodeValidationVisitor.Feature.ALLOW_CONSTRAINT_ERRORS)
? Severity.WARNING : Severity.ERROR;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ private List<ValidationEvent> validateExamples(Model model, OperationShape shape

model.getShape(shape.getInputShape()).ifPresent(input -> {
NodeValidationVisitor validator;
if (example.getDisableConstraints() && !isErrorDefined) {
if (example.getAllowConstraintErrors() && !isErrorDefined) {
events.add(error(shape, trait, String.format(
"Example: `%s` has disableConstraints enabled, so error must be defined.",
"Example: `%s` has allowConstraintErrors enabled, so error must be defined.",
example.getTitle())));
}
validator = createVisitor("input", example.getInput(), model, shape, example);
Expand Down Expand Up @@ -103,8 +103,8 @@ private NodeValidationVisitor createVisitor(
.value(value)
.startingContext("Example " + name + " of `" + example.getTitle() + "`")
.eventId(getName());
if (example.getDisableConstraints()) {
builder.addFeature(NodeValidationVisitor.Feature.DISABLE_CONSTRAINTS);
if (example.getAllowConstraintErrors()) {
builder.addFeature(NodeValidationVisitor.Feature.ALLOW_CONSTRAINT_ERRORS);
}
return builder.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ structure Example {

error: ExampleError

disableConstraints: Boolean
allowConstraintErrors: Boolean
}

@private
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void loadsTrait() {
.withMember("error", Node.objectNode()
.withMember(Node.from("shapeId"), Node.from("smithy.example#FooError"))
.withMember(Node.from("content"), Node.objectNode().withMember("e", Node.from("f"))))
.withMember("disableConstraints", Node.from(true)));
.withMember("allowConstraintErrors", Node.from(true)));

Optional<Trait> trait = provider.createTrait(
ShapeId.from("smithy.api#examples"), ShapeId.from("ns.qux#foo"), node);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[WARNING] ns.foo#Operation: Example output of `Testing 2`: Invalid structure member `additional` found for `ns.foo#OperationOutput` | ExamplesTrait
[ERROR] ns.foo#Operation: Example output of `Testing 2`: Missing required structure member `bam` for `ns.foo#OperationOutput` | ExamplesTrait
[WARNING] ns.foo#Operation: Example error of `Testing 1`: Invalid structure member `extra` found for `ns.foo#OperationError` | ExamplesTrait
[ERROR] ns.foo#Operation: Example: `Testing 4` has disableConstraints enabled, so error must be defined. | ExamplesTrait
[ERROR] ns.foo#Operation: Example: `Testing 4` has allowConstraintErrors enabled, so error must be defined. | ExamplesTrait
[WARNING] ns.foo#Operation: Example input of `Testing 5`.blobMin: Value provided for `ns.foo#OperationInput$blobMin` must have at least 3 bytes, but the provided value only has 1 bytes | ExamplesTrait
[WARNING] ns.foo#Operation: Example input of `Testing 5`.blobMax: Value provided for `ns.foo#OperationInput$blobMax` must have no more than 3 bytes, but the provided value has 6 bytes | ExamplesTrait
[WARNING] ns.foo#Operation: Example input of `Testing 5`: Missing required structure member `foo` for `ns.foo#OperationInput` | ExamplesTrait
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"output": {
"bam": "value3"
},
"disableConstraints": true
"allowConstraintErrors": true
},
{
"title": "Testing 5",
Expand Down Expand Up @@ -91,7 +91,7 @@
"bat": "baz"
}
},
"disableConstraints": true
"allowConstraintErrors": true
}
]
}
Expand Down

0 comments on commit e5bcfd3

Please sign in to comment.