restJson service serialisation behaviour for Timestamps #1156
Replies: 1 comment
-
Hi @codemedian. Just to confirm my understanding, you want a way to default all timestamp formats in your restJson service model to a particular value ( If so, then I'm afraid there's no service-level or model-level mechanism to declare a default timestamp format. Instead, timestamp formats are resolved in this order (from most to least granular):
The easiest way to share a common format among all timestamps in your model is to declare a common A common @mixin
@timestampFormat("date-time")
timestamp TimestampFormatMixin
@required
timestamp RequiredTimestamp with [ TimestampFormatMixin ]
@default("1985-04-12T23:20:50.52Z")
timestamp DefaultedTimestamp with [ TimestampFormatMixin ] Neither of these two options (single common Does this answer your question? |
Beta Was this translation helpful? Give feedback.
-
Hi all.
I'm have a smithy service with the
@restJson1
protocol that I generate an API GW spec and OpenApi based server/client stubs from. I'm currently looking at small stylistic issues that I'd like to address and one item that's on my list is inconsistent timestamp formatting. Based on the trait documentation the serialisation for JSON shapes uses epoch seconds in double fields which I can see in my generated spec.Now to my question:
I use
Timestamp
fields both in query params, e.g.from
field as well as in the response JSON payload, e.g.start
and what I found is thatI would like my service to standardise on ISO_INSTANT for all, input as well as output timestamps.
Is the required as well as recommended approach to add an
@timestampFormat
trait to each and every operation and shape? This feels very error prone and can very easily lead to my standardisation efforts being ignored by a future change that simply forgets to add it.Curious to hear thoughts/best practices to achieve what I'm trying to do
Thanks
Beta Was this translation helpful? Give feedback.
All reactions