smithy icon indicating copy to clipboard operation
smithy copied to clipboard

Way to precisely ignore built-in validator under certain conditions

Open Baccata opened this issue 1 year ago • 2 comments

I'm currently in the process of designing some new semantics for some protocols we have a $work that utilise the standard http bindings.

In particular, these semantics would allow to accommodate existing situations in our org where http endpoints have polymorphic outputs that may issue different status codes / payloads. Supporting this usecase create a valid situation for http-bindings to be used outside of a shape that's used directly as an output of an operation. Conceptually speaking, it's gonna look roughly like this :

operation Foo {
  output := {
     @polymorphicResponse
     response: MyResponse      
  }
}

union MyResponse {
   @httpAltCode(201)
   created: Created
   @httpAltCode(200)
   ok: Ok
}

structure Created {
   @httpHeader("X-Something")
   someHeader: String
   something: String
}

structure Ok {
   @httpHeader("X-Other")
   someOtherHeader: String
   someOtherThing
}

Now the thing is that this doesn't play too well with the HttpBindingTraitIgnoredValidator, as this makes use of the http binding traits in a context that is not taken care of by the official tooling. However I don't want to ignore this validator globally because it's valuable overall.

Is there a way I could tell smithy to silence the validator when binding traits are used in the pattern I've examplified above ?

Baccata avatar Aug 12 '24 13:08 Baccata

Hm... Suppressions are the tool for this, but there isn't a built-in way to automatically suppress based on these kinds of unique combinations. You could use the suppress trait on each offending member, though that's tedious. Mixins + suppressions don't help here since these events are emitted on members and members are going to vary. You could suppress these per/namespace using a namespace suppression, though this does require your consumers to wire it up themselves. We could potentially add a selector to metadata based suppressions.

mtdowling avatar Aug 12 '24 19:08 mtdowling

We could potentially add a selector to metadata based suppressions.

If that's a possibility, it would be great 👍

Baccata avatar Aug 13 '24 08:08 Baccata