You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
How can I write a operation that supports an endpoint whose input can be one of a set of inputs?
Through the use of oneOf, endpoints can validate the input based on the object type. However, operations in Smithy take in a single input shape.
In my use case, the inputs common fields with some unique fields distinguishing them.
Sample OpenAPI spec of an endpoint that supports multiple input types
The similarity between inputs makes it seem like a good candidate for mixins. However, mixins are not meant to be used for polymorphism and operations with mixins may not define input shape
The union data structure seemed like it could work at first. However, Smithy implements unions as tagged unions, meaning each member must have a unique tag/key. This extra tag/key results in extra nesting when serializing JSON.
These restrictions make it seem like I'd need to define the same operation multiple times for each supported input. So rather than having:
operationCreateDataType {
input: CreateDataTypeInput
...
}
structureCreateDataTypeInput {
// Something that supports both the String and Integer type
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
How can I write a operation that supports an endpoint whose input can be one of a set of inputs?
Through the use of oneOf, endpoints can validate the input based on the object type. However, operations in Smithy take in a single input shape.
In my use case, the inputs common fields with some unique fields distinguishing them.
Sample OpenAPI spec of an endpoint that supports multiple input types
The similarity between inputs makes it seem like a good candidate for mixins. However, mixins are not meant to be used for polymorphism and operations with mixins may not define input shape
The union data structure seemed like it could work at first. However, Smithy implements unions as tagged unions, meaning each member must have a unique tag/key. This extra tag/key results in extra nesting when serializing JSON.
These restrictions make it seem like I'd need to define the same operation multiple times for each supported input. So rather than having:
I need to define
Please advise the best way to implement this and correct me if I misunderstood anything. Thanks
Beta Was this translation helpful? Give feedback.
All reactions