speccy icon indicating copy to clipboard operation
speccy copied to clipboard

Escape colon

Open VonSerpe opened this issue 5 years ago • 14 comments

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

VonSerpe avatar Oct 23 '19 15:10 VonSerpe

@MikeRalphson this might a thing for oas-resolver?

philsturgeon avatar Dec 25 '19 10:12 philsturgeon

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.

MikeRalphson avatar Jan 06 '20 13:01 MikeRalphson

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?

negebauer avatar Jul 14 '20 20:07 negebauer

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.

MikeRalphson avatar Jul 14 '20 21:07 MikeRalphson

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 avatar Jul 14 '20 21:07 negebauer

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

negebauer avatar Jul 14 '20 21:07 negebauer

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.

MikeRalphson avatar Jul 14 '20 21:07 MikeRalphson

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 avatar Jul 14 '20 21:07 negebauer

I think this issue can be closed then, right?

negebauer avatar Jul 14 '20 21:07 negebauer

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 avatar Jul 14 '20 21:07 MikeRalphson

All issues here should be closed. Speccy is unmaintained.

MikeRalphson avatar Jul 14 '20 21:07 MikeRalphson

I mean that it's not a problem with speccy

negebauer avatar Jul 14 '20 21:07 negebauer

Ah, apologies for misreading.

MikeRalphson avatar Jul 14 '20 21:07 MikeRalphson

no problem, I should have been more clear :)

negebauer avatar Jul 14 '20 21:07 negebauer