openapi-directory
openapi-directory copied to clipboard
YAML type coercion in description documents
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:
https://github.com/APIs-guru/openapi-directory/blob/3b4280061cea37f1faa8ef63a56c26a40702b681/APIs/1password.com/events/1.0.0/openapi.yaml#L176-L179
https://github.com/APIs-guru/openapi-directory/blob/3b4280061cea37f1faa8ef63a56c26a40702b681/APIs/amadeus.com/2.2.0/openapi.yaml#L54-L56
https://github.com/APIs-guru/openapi-directory/blob/3b4280061cea37f1faa8ef63a56c26a40702b681/APIs/api.video/1/openapi.yaml#L76-L84
https://github.com/APIs-guru/openapi-directory/blob/3b4280061cea37f1faa8ef63a56c26a40702b681/APIs/apidapp.com/2019-02-14T164701Z/openapi.yaml#L4-L8
https://github.com/APIs-guru/openapi-directory/blob/3b4280061cea37f1faa8ef63a56c26a40702b681/APIs/apideck.com/accounting/8.32.1/openapi.yaml#L4720-L4722
Which YAML parser and version are you using? js-yaml
used to have problems handling dates but I thought that had been fixed...
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.
Do you know if pyYAML supports YAML 1.2 or 1.1 only?
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.
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?
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.
I wrongly assumed that ruamel.yaml would use the Core schema for 1.2 documents.
Seems I'm all wrong with this one.
It doesn't help that the YAML 1.2 spec contains three (orphan?) references to !! timestamp without explicitly referencing where it comes from.
Closing due to inactivity - but please feel free to chase and we can reopen the issue if necessary.