Skip to content

Add addErrors/removeErrors/removeOperations/removeMembers transformations - #37

Merged
kubukoz merged 1 commit into
mainfrom
add-remove-errors-operations-members
Aug 20, 2026
Merged

kubukoz merged 1 commit into
mainfrom
add-remove-errors-operations-members

Conversation

@kubukoz

@kubukoz kubukoz commented Aug 20, 2026

Copy link
Copy Markdown
Member

Adds four transformations, following the existing addOperations / addMembers pattern.

addErrors / removeErrors

One trait each, selector :is(operation, service) — both shape types carry an errors property. 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-@error target fails at model-load time rather than during transformation.

addErrors skips errors already present on the shape, so it's idempotent.

removeOperations

Selector service, via the inherited EntityShape.Builder.removeOperation.

removeMembers

Selector :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 existing addMembers behaviour. Shape builders have no removeMember, so the container is rebuilt from the surviving members.

Shared semantics for the removals

  • Entries that aren't attached to the shape are ignored rather than an error, keeping the traits usable against upstream models that may or may not declare them.
  • Only the containing shape's list is rewritten — the referenced operation/error shapes stay in the model, since something else may still bind them. Pair with smithy-build's own removeUnusedShapes to drop the orphans.

Two caveats, documented in the README and Javadoc

  • Service-level errors can't be cancelled per-operation. Smithy has no opt-out for an error inherited from the enclosing service, so @removeErrors on an operation can't remove one the service contributes — it has to be removed from the service. Smithy semantics, not a limitation here.
  • removeMembers only rewrites the container. Dropping a member something else depends on (an @httpLabel binding, a @required contract elsewhere) surfaces as a validation failure downstream rather than here.

Notes

Builder APIs were checked against the smithy-model jar rather than assumed — removeOperation and removeError live on different classes (EntityShape.Builder vs. the concrete builders), and AbstractShapeBuilder has no removeMember at all, which shaped the RemoveMembers implementation.

Test helpers are extracted into a shared TransformationSuite used 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, mimaReportBinaryIssues and doc.

🤖 Generated with Claude Code

…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>
@kubukoz
kubukoz merged commit 404ed82 into main Aug 20, 2026
10 checks passed
@kubukoz
kubukoz deleted the add-remove-errors-operations-members branch August 20, 2026 16:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant