speccy
speccy copied to clipboard
Support setting yaml version to 1.1
hi! thanks for making speccy!
for this PR, the tests pass, and this would be nice to have because of the following issues i've also had:
https://github.com/swagger-api/swagger-ui/issues/5061 https://github.com/Mermade/oas-kit/issues/169#issuecomment-516769823 https://github.com/eemeli/yaml/issues/117
in a nutshell, i want to compile my yaml into a mega yaml using speccy (along with lint), but when my example strings are formatted like so: "2016-09-08", the resulting mega yaml removes the quotes and translates them to simply 2016-09-08. this is because the underlying yaml package parses yaml v1.1 (leaves quotes) spec differently from yaml v1.2 spec (removes quotes).
quoting eemeli from the npm yaml package:
The
yamlstringifier verifies that its output will also be parsed to the same type as its input; this is why the string"1"gets stringified as"1", rather than just1. What's happening here with"2012-10-12"is that the re-parsing test is defaulting to use the YAML core schema, which does not include timestamps as a data type, and hence allows the default unquoted style to be used.
the issue is most easily resolved by using an older, less "smart" spec (1.1) of yaml where the parser doesn't attempt to turn a string into its unquoted form. longer term, you guys might want to consider being more in control of your document parsing and stringifying by using the Document api provided by the yaml npm package, as opposed to just using the plain parse/stringify functions. or just maybe allow users to use a pass through options object or something, i dunno.
i would like to use 1.2, but i don't see and easy way to do that and get what i need quickly without a lot of work. this is a pretty quick and easy solution for my needs and I hope you'll accept it!
thanks, Josh
As per https://github.com/Mermade/oas-kit/issues/169#issuecomment-525636607 if you need YAML 1.1 support, consider including a YAML version directive in your input file. Speccy only supports OAS 3.0 where YAML 1.2 is recommended, so this will (likely) remain the output format version.