Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug allowing validation to be skipped #440

Merged
merged 2 commits into from
May 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions docs/source/1.0/spec/core/model-validation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -179,18 +179,18 @@ Suppressions
------------

Suppressions are used to suppress specific validation events.
Suppressions are created using the :ref:`suppression-trait` and
Suppressions are created using the :ref:`suppress-trait` and
:ref:`suppressions metadata <suppressions-metadata>`.


.. _suppression-trait:
.. _suppress-trait:

``suppression`` trait
``suppress`` trait
=====================

Summary
The suppression trait is used to suppress validation events(s) for a
specific shape. Each value in the ``suppression`` trait is a
The suppress trait is used to suppress validation events(s) for a
specific shape. Each value in the ``suppress`` trait is a
validation event ID to suppress for the shape.
Trait selector
``*``
Expand All @@ -208,7 +208,7 @@ for the ``smithy.example#MyString`` shape:

namespace smithy.example

@suppression(["Foo", "Bar"])
@suppress(["Foo", "Bar"])
string MyString


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@
},
"traits": {
"smithy.api#error": "client",
"smithy.api#httpError": 302
"smithy.api#httpError": 302,
"smithy.api#suppress": ["HttpResponseCodeSemantics"]
}
},
"smithy.example#OperationInput": {
Expand Down Expand Up @@ -198,14 +199,5 @@
}
}
}
},
"metadata": {
"suppressions": [
{
"ids": ["HttpResponseCodeSemantics"],
"shapes": ["smithy.example#Redirect"],
"reason": "model redirect as error"
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@
},
"traits": {
"smithy.api#error": "client",
"smithy.api#httpError": 302
"smithy.api#httpError": 302,
"smithy.api#suppress": ["HttpResponseCodeSemantics"]
}
},
"smithy.example#OperationInput": {
Expand Down Expand Up @@ -199,14 +200,5 @@
}
}
}
},
"metadata": {
"suppressions": [
{
"ids": ["HttpResponseCodeSemantics"],
"shapes": ["smithy.example#Redirect"],
"reason": "model redirect as error"
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -477,8 +477,10 @@ public ValidatedResult<Model> assemble() {
try {
return doAssemble(visitor);
} catch (SourceException e) {
visitor.onError(ValidationEvent.fromSourceException(e));
return visitor.onEnd();
ValidatedResult<Model> modelResult = visitor.onEnd();
List<ValidationEvent> events = new ArrayList<>(modelResult.getValidationEvents());
events.add(ValidationEvent.fromSourceException(e));
return new ValidatedResult<>(modelResult.getResult().orElse(null), events);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -481,4 +481,16 @@ public void canDisableValidation() {

assertFalse(result.isBroken());
}

@Test
public void canHandleBadSuppressions() {
String document = "namespace foo.baz\n"
+ "@idempotent\n" // < this is invalid
+ "string MyString\n";
ValidatedResult<Model> result = new ModelAssembler()
.addUnparsedModel("foo.smithy", document)
.putMetadata("suppressions", Node.parse("[{}]"))
.assemble();
assertTrue(result.isBroken());
}
}