wework / speccy

Well Spectually 🤓 Enforce quality rules on your OpenAPI 3.0.x specifications.
http://speccy.io
MIT License
825 stars 78 forks source link

Escape colon #371

Open VonSerpe opened 4 years ago

VonSerpe commented 4 years ago

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.

philsturgeon commented 4 years ago

@MikeRalphson this might a thing for oas-resolver?

MikeRalphson commented 4 years ago

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.

negebauer commented 4 years ago

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?

MikeRalphson commented 4 years ago

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.

negebauer commented 4 years ago

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

negebauer commented 4 years ago

Another option from the YAML spec is to use tags like example: !!str 2019-10-10 but speccy resolve also deletes the !!str part

MikeRalphson commented 4 years ago

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.

negebauer commented 4 years ago

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
negebauer commented 4 years ago

I think this issue can be closed then, right?

MikeRalphson commented 4 years ago

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.

MikeRalphson commented 4 years ago

All issues here should be closed. Speccy is unmaintained.

negebauer commented 4 years ago

I mean that it's not a problem with speccy

MikeRalphson commented 4 years ago

Ah, apologies for misreading.

negebauer commented 4 years ago

no problem, I should have been more clear :)