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

YAML type coercion in description documents #1016

Closed
commonism opened this issue Jun 10, 2022 · 10 comments
Closed

YAML type coercion in description documents #1016

commonism opened this issue Jun 10, 2022 · 10 comments
Labels

Comments

@commonism
Copy link

Due to yaml type coercion certain values get converted to objects.

E.g. timestamps to datetime objects:

import datetime, yaml
yaml.safe_load(str(datetime.datetime.now().date()))
# datetime.date(2022, 6, 10)

Therefore I'd like to have your opinion in having such values in a description document, such as:

DateTimeRFC3339:
example: 2020-06-11T16:32:50-03:00
format: date-time
type: string

- description: the date on which the traveler will depart from the origin to go to the destination. Dates are specified in the [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) YYYY-MM-DD format, e.g. 2017-12-25
example: 2021-02-01
in: query

- description: |
Period must have one of the following formats:
- For a day : "2018-01-01",
- For a week: "2018-W01",
- For a month: "2018-01"
- For a year: "2018"
For a range period:
- Date range: "2018-01-01/2018-01-15"
example: 2019-01-01

info:
contact:
x-twitter: api_dapp
title: ApiDapp
version: 2019-02-14T16:47:01Z

created_at:
example: 2020-09-30T07:43:32.000Z
format: date-time

@MikeRalphson
Copy link
Collaborator

Which YAML parser and version are you using? js-yaml used to have problems handling dates but I thought that had been fixed...

@commonism
Copy link
Author

Python3 - PyYAML 6.0

I do not consider this a problem with the YAML parser, from my understanding the parser does things according to the specification.

To me this is a problem of the description document not forcing this to be a string either enclosing in "" or via !!str.

I consider the dd invalid by having datetime objects where string is expected.

@MikeRalphson
Copy link
Collaborator

Do you know if pyYAML supports YAML 1.2 or 1.1 only?

@commonism
Copy link
Author

1.1

@MikeRalphson
Copy link
Collaborator

These documents are YAML 1.2, as recommended by the OpenAPI Specification:

In order to preserve the ability to round-trip between YAML and JSON formats, YAML version 1.2 is RECOMMENDED

As we basically have no control over the YAML output by our chosen yaml parser, I'm unfortunately going to close this as not-a-bug.

@MikeRalphson MikeRalphson closed this as not planned Won't fix, can't repro, duplicate, stale Feb 20, 2023
@commonism
Copy link
Author

YAML 1.2 does not change anything here.

As an example, ruamel.yaml does YAML 1.2:

from ruamel.yaml import YAML
yaml = YAML()
yaml.load("example: 2020-06-11T16:32:50-03:00")
# ordereddict([('example', TimeStamp(2020, 6, 11, 19, 32, 50))])

example expects string.

This makes this not a valid description document?

@MikeRalphson MikeRalphson reopened this Feb 20, 2023
@MikeRalphson
Copy link
Collaborator

From https://yaml.org/spec/1.2.2/ext/changes/

Changes in version 1.2 (revision 1.2.0) (2009-07-21)
The !!pairs, !!omap, !!set, !!timestamp and !!binary types have been dropped.

eemeli/yaml only parses timestamp-like strings as Dates if a YAML 1.1 directive is included or !!timestamp is added as a custom type.

@commonism
Copy link
Author

@MikeRalphson
Copy link
Collaborator

It doesn't help that the YAML 1.2 spec contains three (orphan?) references to !! timestamp without explicitly referencing where it comes from.

@MikeRalphson
Copy link
Collaborator

Closing due to inactivity - but please feel free to chase and we can reopen the issue if necessary.

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

No branches or pull requests

2 participants