Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate example for time format #120

Closed
magicmatatjahu opened this issue Dec 14, 2020 · 7 comments
Closed

Generate example for time format #120

magicmatatjahu opened this issue Dec 14, 2020 · 7 comments

Comments

@magicmatatjahu
Copy link
Contributor

magicmatatjahu commented Dec 14, 2020

This is a feature request.

Would be great if lib supports generation example for time format, like in spec:

{
  "type": "string",
  "format": "time"
}

and then output should be:

14:15:22

At the moment lib supports generation for date and date-time, but time should be also supported. As I know format is a open value, so it shouldn't be against the OpenAPI specification link, but maybe there are issues as to why time format is not documented.

We have a reported issue in our library (which uses openapi-sampler) to supports time format and we don't want to make example inside library, but want to have support in used package.

I can make PR for it if you'll accept my request :)

Btw. Very helpful library :)

@adamaltman
Copy link
Member

What about time zone properties? For example +00:00?

@c-pius
Copy link

c-pius commented Dec 21, 2020

openapi-sampler uses Z notation for time offset in date-time. so I guess RFC 3339 full-time with Z time offset would make sense?

let res = toRFCDateTime(new Date('2019-08-24T14:15:22.123Z'), omitTime, false);

export function toRFCDateTime(date, omitTime, milliseconds) {

@magicmatatjahu
Copy link
Contributor Author

Exactly as @c-pius wrote. For example 15:59:60-08:00 will mean 15:59:60 time, 8 hours behind UTC.

Additionally, following with the RFC 3339 there should be partial-time (time should use this format, but I don't know if this is a good idea -> ref: OAI/OpenAPI-Specification#845) format without offset and full-time with offset.

@adamaltman
Copy link
Member

I think it would be better to use a format of "partial-time" or "full-time" for clarity and alignment with the RFC 3339.

@c-pius
Copy link

c-pius commented Dec 22, 2020

@magicmatatjahu you are right, even appears like the discussions from your reference lean towards time format using partial-time from the RFC?

I don't really have an opinion whether time should use partial-time or full-time. Also not sure if it is a good idea to provide different formats "partial-time" and "full-time".

@magicmatatjahu
Copy link
Contributor Author

@c-pius "partial-time" and "full-time" should be provide for this same cases like date and date-time, I mean you should have possibility to define time without timezone and with timezone. If there will be only full-time for example, then specifying time with a zero offset (if an offset is not needed) may be confusing

I can create PR for that, but after read the issue, which I mentioned it might be better to wait for the official support for the time format or for the format registry.

@magicmatatjahu
Copy link
Contributor Author

As I see the time format is added in #122 PR, so I close the issue, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants