[v6] Support string format "time"
See original GitHub issueA new string format, time
, is being added to autorest.
Background
The idea behind time
is that it represents time in a way that’s completely agnostic to the date.
What do other SDKs do?
In Python, there is a datetime.time class that contains the hours, minutes, seconds, and microseconds fields. Python accepts this type as input from a user and converts it into a string over the wire: HH:MM:SS.microseconds
.
Python also converts this string into a datetime.time
object when giving a response back to the user.
Issues in JavaScript
In JavaScript we only have the Date
class to represent time. While we can set the relevant fields on it, we can’t decouple the time from the date.
Potential solutions
Treat format: “time” as a string.
In this solution, the code generator treats format: “time” (TimeSchema) as a regular string. We can add documentation to the generated types that indicates the format the string should be in. Pros
- Input/Output is human readable
- No changes to core-http required
Cons
- User has to parse the string themselves if they want to work with it.
Create a “Time” interface
With this solution, we create a Time
(name up for discussion) interface in core-http that looks roughly like:
interface Time {
hours: number;
minutes: number;
seconds: number;
microseconds?: number;
}
We would need to update core-http to recognize the time
format and serialize/deserialize the Time object the user passes in appropriately.
Pros
- User can work with the components of time with type-safety.
Cons
- Changes to core-http required.
References:
Test swagger update: https://github.com/Azure/autorest.testserver/pull/163
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:7 (7 by maintainers)
I could do a string for now, that’s definitely the easiest. We can add a flag to autorest.typescript to treat “time” as an interface that aligns with Temporal (or even Temporal itself) in the future if we want to support that for future SDKs.
Support for this was added by PR#614