speccy
speccy copied to clipboard
Escape colon
Detailed description
When I create an example with a value that contains a colon like this:
range:
summary: Bla bla bla
value:
range: '4:23'
speccy resolve
command converts the range value string in a value without quote:
range:
summary: Bla bla bla
value:
range: 4:23
and in SwaggerHub editor I see this:
{
"range": 263
}
Possible implementation
When quotes are used to define the value of a variable, speccy resolve
command can consider the quotes and apply them to the generated file
Your environment
Include as many relevant details about the environment you experienced the bug in and how to reproduce it.
- Node Version: v10.16.3
- Operating system and version (e.g. Ubuntu 16.04, Windows 7): macOS High Sierra 10.13.6
@MikeRalphson this might a thing for oas-resolver?
This is unrelated to oas-resolver
. This is purely due to Speccy's yaml
parsing and serialization functions. 4:23
cannot be interpreted as a boolean, number or null, therefore it is a string by default and does not require any quoting. Probably a bug in SwaggerHub.
I'm having a similar issue with a date. I have the following
example: '2019-10-10'
That speccy transforms to
example: 2019-10-10
But I want the example to be treated as a string, is there any way I can force speccy to respect this quote? It should respect it by default right?
2019-10-10 cannot be interpreted as a boolean, number or null, therefore it is a string by default and does not require any quoting. Probably a bug in SwaggerHub.
It can be interpreted as a date, which is what's happening. That's why the quotes should be preserved in this case. It's not a string by default.
js-yaml issue where it's mentioned that 2019-10-10
is read as a date https://github.com/nodeca/js-yaml/issues/198
swagger-ui issue where a similar case is mentioned with the solution being to add the quotes https://github.com/swagger-api/swagger-ui/issues/5061#issuecomment-445286984
Another option from the YAML spec is to use tags like example: !!str 2019-10-10
but speccy resolve
also deletes the !!str
part
From the OpenAPI spec:
In order to preserve the ability to round-trip between YAML and JSON formats, YAML version 1.2 is RECOMMENDED along with some additional constraints:
Tags MUST be limited to those allowed by the JSON Schema ruleset.
Keys used in YAML maps MUST be limited to a scalar string, as defined by the YAML Failsafe schema ruleset.
The JSON Schema ruleset does not include the date
type.
Oh it's because of the JSON Schema then. It's not a bug then as you said. Thanks!
For anyone that ends up here I used this workaround to preserve the quotes:
example: |
2019-10-10
I think this issue can be closed then, right?
I said it was probably a bug in SwaggerHub. If they're not limiting their yaml parsing to the JSON Schema ruleset, then that's a bug.
All issues here should be closed. Speccy is unmaintained.
I mean that it's not a problem with speccy
Ah, apologies for misreading.
no problem, I should have been more clear :)