Add addErrors/removeErrors/removeOperations/removeMembers transformations - #37
Merged
Merged
Conversation
…ions addErrors and removeErrors use a single trait each with an `:is(operation, service)` selector, since both shape types carry an `errors` property. Targets are constrained by `@idRef(selector: "structure[trait|error]")`, so non-error or missing targets fail at model-load time rather than during transformation. addErrors skips errors already present, so it is idempotent. removeErrors, removeOperations and removeMembers ignore entries that aren't attached to the shape, keeping the traits usable against upstream models that may or may not declare them. None of the removals delete the referenced shapes themselves — only the containing shape's list is rewritten. removeMembers matches member names case-insensitively, mirroring both Smithy's own member name uniqueness rule and the existing addMembers behaviour. Shape builders have no removeMember, so the container is rebuilt from the surviving members. Test helpers are extracted into a shared TransformationSuite used by the new suites; the pre-existing suites keep their own copies for now. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds four transformations, following the existing
addOperations/addMemberspattern.addErrors/removeErrorsOne trait each, selector
:is(operation, service)— both shape types carry anerrorsproperty. On an operation the errors are specific to that operation; on a service they apply to every operation it contains.Targets are constrained by
@idRef(failWhenMissing: true, selector: "structure[trait|error]"), so a typo or a non-@errortarget fails at model-load time rather than during transformation.addErrorsskips errors already present on the shape, so it's idempotent.removeOperationsSelector
service, via the inheritedEntityShape.Builder.removeOperation.removeMembersSelector
:is(structure, union). Entries are plain member names rather than shape ids, matched case-insensitively — mirroring both Smithy's own member-name uniqueness rule and the existingaddMembersbehaviour. Shape builders have noremoveMember, so the container is rebuilt from the surviving members.Shared semantics for the removals
removeUnusedShapesto drop the orphans.Two caveats, documented in the README and Javadoc
@removeErrorson an operation can't remove one the service contributes — it has to be removed from the service. Smithy semantics, not a limitation here.removeMembersonly rewrites the container. Dropping a member something else depends on (an@httpLabelbinding, a@requiredcontract elsewhere) surfaces as a validation failure downstream rather than here.Notes
Builder APIs were checked against the smithy-model jar rather than assumed —
removeOperationandremoveErrorlive on different classes (EntityShape.Buildervs. the concrete builders), andAbstractShapeBuilderhas noremoveMemberat all, which shaped theRemoveMembersimplementation.Test helpers are extracted into a shared
TransformationSuiteused by the four new suites. The three pre-existing suites each had their own copy and are left alone to keep the diff focused — worth collapsing separately.70 tests pass, along with
headerCheckAll,scalafmtCheckAll,mimaReportBinaryIssuesanddoc.🤖 Generated with Claude Code