-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] OpenAPI.yaml generated returns strings without double quotes and "no" string is implicitly interpreted as boolean #3196
Comments
I also tried using a yaml file where I explicitly use double quotes around openapi: 3.0.1
info:
description: Car example
title: Car API
version: 1.0.0
servers:
- url: https://HOST/
paths:
/v1/cars:
post:
operationId: v1_cars_post
requestBody:
content:
application/json:
schema:
items:
$ref: '#/components/schemas/car'
type: array
required: true
responses:
200:
content: {}
description: Successfully updated
summary: Add cars
tags:
- Cars
x-codegen-request-body-name: body
x-openapi-router-controller: openapi_server.controllers.cars_controller
components:
schemas:
car:
properties:
name:
description: The name of the car.
maxLength: 255
type: string
test:
description: 'Buggy enum: no becomes False'
enum:
- "no"
- great
- other
type: string
required:
- name
- test
type: object Generated file: openapi: 3.0.1
info:
description: Car example
title: Car API
version: 1.0.0
servers:
- url: https://HOST/
paths:
/v1/cars:
post:
operationId: v1_cars_post
requestBody:
content:
application/json:
schema:
items:
$ref: '#/components/schemas/car'
type: array
required: true
responses:
200:
content: {}
description: Successfully updated
summary: Add cars
tags:
- Cars
x-codegen-request-body-name: body
x-openapi-router-controller: openapi_server.controllers.cars_controller
components:
schemas:
car:
properties:
name:
description: The name of the car.
maxLength: 255
type: string
test:
description: 'Buggy enum: no becomes False'
enum:
- no
- great
- other
type: string
required:
- name
- test
type: object diff: --- openapi.yaml 2019-06-27 18:22:18.785663477 -0400
+++ server/openapi_server/openapi/openapi.yaml 2019-06-27 18:22:38.901792481 -0400
@@ -37,7 +37,7 @@
test:
description: 'Buggy enum: no becomes False'
enum:
- - "no"
+ - no
- great
- other
type: string |
Ok. I found that openapi-generator are using the new tool v3 provided by swagger-codegen Lines 22 to 26 in 046db19
That why there is a difference with swagger-codegen because they still use the old version But this is mainly due to the usage of the option I also found this issue on FastXML/jackson-dataformats-text: FasterXML/jackson-dataformats-text#129 where it seems there is something weird in the formatting for Yaml spec 1.1 because the dependency for FastXML is SnakeYAML https://bitbucket.org/asomov/snakeyaml/ which is a formatter for Yaml 1.1 I think FasterXML/jackson-dataformats-text needs a fix to protect the values listed in https://yaml.org/type/bool.html. |
quotes around string value and fix compatibility with parser using yaml 1.1. Fix OpenAPITools#3196 In spec 1.1, some words without quotes can be implicitly converted to a boolean like "yes" or "on" (See https://yaml.org/type/bool.html) In v3.core.util.Yaml with MINIMIZE_QUOTES enabled, the formatter created a YAML but forget to protect some words. PRs are created to fix this in the formatter: - FasterXML/jackson-dataformats-text#137 - FasterXML/jackson-dataformats-text#138 Until the PRs will be merged and released, this patch fix it by re-adding quotes.
related: #4365 |
PR for https://github.com/FasterXML/jackson-dataformats-text is merged, the fix is only available in a new release but it implies a lot of change with the fix. |
Hey folks, sorry to revive an old issue here, but since it’s Open, it might be the right place. is there any fix already available for this string quotes problem? I face the same problem for dates (YYYY-MM-DD) and for phone numbers that actually starts with the plus sign (+00 E.164 format). |
Bug Report Checklist
Description
openapi.yaml file generated in the project with
{{{openapi-yaml}}}
like https://github.com/OpenAPITools/openapi-generator/blob/20b8eff6e3dcec5dfe955b5dda1e4b84d8bdce44/modules/openapi-generator/src/main/resources/python-flask/openapi.mustache doesn't use double quotes around string values.Because in YAML specification, it seems value true/false, yes/no and on/off can be implicitly convert to boolean unless the value have double quotes.
Here the code in PyYAML: https://github.com/yaml/pyyaml/blob/4c2e993321ad29a02a61c4818f3cef9229219003/lib3/yaml/resolver.py#L170-L175
Example: The yaml generated should return
- "no"
instead of- no
to avoid implicit convertion.openapi-generator version
4.0.3-beta
It can be a regression because it was not present in swagger-codegen
OpenAPI declaration file content or url & Command line used for generation
I am using the online version to generate python-flask server with the following JSON openapi.quote.json.zip
Steps to reproduce
Generated file by openapi generator:
Related issues/PRs
Maybe the same error in #2870
Suggest a fix
Add double quotes ?
The text was updated successfully, but these errors were encountered: