oas-kit: YAML output missing quotations around examples
When processing a swagger 2 YAML file with a property that is a string with a “date” format and an example provided, the objected is processed properly; however, when output back as an open api 3 YAML file the example object no longer has quotations around it. This causes the wrong example value to display in the UI. When outputting as json this is not a problem as it is a YAML specific issue to require the quotations.
Checklist
- Conversion: I have checked my source definition is valid OpenAPI 2.0
- Conversion: On valid OpenAPI 2.0 input, the conversion looks wrong
Detailed Description
In the initial swagger 2.0 I have a property “date range”, which is shown below. In this the example dates “2017-01-01” have quotations around them as required since they are a string example.
Swagger2:
date_range:
description: 'DateRange is a type of NumericRange.'
type: object
properties:
from:
description: 'The lower bound value in the DateRange.'
type: string
format: date
example: "2017-01-01"
thru:
description: 'The upper bound value in the DateRange.'
type: string
format: date
example: "2017-01-01"
When outputting this as a YAML open api 3 it is represented as:
Open API 3 YAML
date_range:
description: DateRange is a type of NumericRange.
type: object
properties:
from:
description: The lower bound value in the DateRange.
type: string
format: date
example: 2017-01-01
thru:
description: The upper bound value in the DateRange.
type: string
format: date
example: 2017-01-01
This is the exact same minus the quotes around the example. Which causes this to be represented incorrectly in the example viewer:
“from”: {}, “thru”: {}
When converting to JSON, the inherit nature of the JSON shows this correctly based on this conversion:
"date_range": {
"description": "DateRange is a type of NumericRange.",
"type": "object",
"properties": {
"from": {
"description": "The lower bound value in the DateRange.",
"type": "string",
"format": "date",
"example": "2017-01-01"
},
"thru": {
"description": "The upper bound value in the DateRange.",
"type": "string",
"format": "date",
"example": "2017-01-01"
}
}
},
Other stuff
Running version 5.2.3. Using the command line to convert using swagger2openapi --yaml --refSiblings preserve --outfile out.yaml in.yaml
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 22 (8 by maintainers)
Commits related to this issue
- test: use deepStrictEqual in comparisons, refs #169 — committed to Mermade/oas-kit by MikeRalphson 5 years ago
- test: use deepStrictEqual in comparisons, refs #169 — committed to Mermade/oas-kit by MikeRalphson 5 years ago
Investigation on the date/date-time format
Also, while investigating on issue opened by @matthewvelie. I’m a bit worried since, if I’m not wrong, the idea of the swagger2openapi tool is to convert a valid Swagger 2.0 to a valid OpenAPI 3.0 and the sample he provided may not be correct regarding the YAML specification but do are working as we expect with the official Swagger tools (see picture below on Swagger editor).
Without quotes
With quotes
As for my previous comment, you’ll find
With this new information, do you think you could make an update on your tool or should we ask for an update of the Swagger tools? 😃
random.txt random.openapi.txt
String number conversion issue
I’ve a related issue while converting a file from Swagger 2.0 to OpenAPI 3.0 but its not for the date nor the date-time but on the string that enclose a number.
To make you understand the issue, I’ve attached two sample files:
In those files, you’ll see the following behavior. A string that starts with a ‘0’ and that only contains number in it will be automatically converted to a number and lose its quotes like below:
Definition from random.txt
Converted definition in random.openapi.txt
This is particularly painful since the generated sample is not valid without the quote. Do you have any idea on how to solve this? 😃
random.openapi.txt random.txt