From 44e3fdffedded18c488097efa88a53377f72b8a1 Mon Sep 17 00:00:00 2001 From: Miles Ziemer <45497130+milesziemer@users.noreply.github.com> Date: Mon, 10 Apr 2023 18:15:50 -0400 Subject: [PATCH] fix error msg for invalid operation io bindings (#1728) Fixes issue #1719, which pointed out that error messages when operation input targeted structures with the `@output` trait (and vice-versa) were incorrect. The error message was built using the operation <-> target relationship name for the name of the invalid trait, instead of using it as the operation property which targeted an invalid shape. The error message was also updated to include the shape id of the targeted shape, and existing tests were updated to reflect that change. --- .../validation/validators/OperationValidator.java | 13 ++++++++++--- .../invalid-input-output-operation-bindings.errors | 4 ++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/OperationValidator.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/OperationValidator.java index 42e48cd01fa..1b90a842d37 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/OperationValidator.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/OperationValidator.java @@ -95,7 +95,7 @@ private void validateInputOutput( } } else if (relName.equals(invalid)) { // Input shouldn't reference output, and vice versa. - events.add(emitInvalidOperationBinding(rel.getShape(), descriptor, invalid)); + events.add(emitInvalidOperationBinding(rel.getShape(), shape, relName, descriptor)); } else if (rel.getRelationshipType() == RelationshipType.MEMBER_TARGET) { // Members can't target shapes marked with @input or @output. events.add(emitInvalidMemberRef(rel.getShape().asMemberShape().get(), descriptor)); @@ -109,12 +109,19 @@ private void validateInputOutput( } } - private ValidationEvent emitInvalidOperationBinding(Shape operation, String property, String invalid) { + private ValidationEvent emitInvalidOperationBinding( + Shape operation, + Shape target, + String property, + String invalid + ) { return ValidationEvent.builder() .id(OPERATION_INPUT_OUTPUT_MISUSE) .severity(Severity.ERROR) .shape(operation) - .message("Operation " + property + " cannot target structures marked with the @" + invalid + " trait") + .message(String.format( + "Operation `%s` cannot target structures marked with the `@%s` trait: `%s`", + property, invalid, target.getId())) .build(); } diff --git a/smithy-model/src/test/resources/software/amazon/smithy/model/errorfiles/validators/operation/input-output-traits/invalid-input-output-operation-bindings.errors b/smithy-model/src/test/resources/software/amazon/smithy/model/errorfiles/validators/operation/input-output-traits/invalid-input-output-operation-bindings.errors index 3f5afdf870f..5e3f02c1e57 100644 --- a/smithy-model/src/test/resources/software/amazon/smithy/model/errorfiles/validators/operation/input-output-traits/invalid-input-output-operation-bindings.errors +++ b/smithy-model/src/test/resources/software/amazon/smithy/model/errorfiles/validators/operation/input-output-traits/invalid-input-output-operation-bindings.errors @@ -1,2 +1,2 @@ -[ERROR] smithy.example#GetFoo: Operation input cannot target structures marked with the @output trait | OperationInputOutputMisuse -[ERROR] smithy.example#GetFoo: Operation output cannot target structures marked with the @input trait | OperationInputOutputMisuse +[ERROR] smithy.example#GetFoo: Operation `input` cannot target structures marked with the `@output` trait: `smithy.example#GetFooOutput` | OperationInputOutputMisuse +[ERROR] smithy.example#GetFoo: Operation `output` cannot target structures marked with the `@input` trait: `smithy.example#GetFooInput` | OperationInputOutputMisuse