There are cases where minimizing quotes results in invalid YAML. For example, an input YAML with string "1234_1234" will be converted to YAML value 1234_1234 which is an int in YAML 1.1 (https://yaml.org/type/int.html)
The only option in these cases is to either:
- Revert the option completely to always quote values
- Provide a user-customization to disable quotes minimization
This applies the latter with the assumption that this is an edge case and users who are unaffected will default to the "prettier" version.
An alternative would be to write a custom serializer for strings, and if they are in the format of of any of the valid formats defined in YAML:
[-+]?0b[0-1_]+ # (base 2)
|[-+]?0[0-7_]+ # (base 8)
|[-+]?(0|[1-9][0-9_]*) # (base 10)
|[-+]?0x[0-9a-fA-F_]+ # (base 16)
|[-+]?[1-9][0-9_]*(:[0-5]?[0-9])+ # (base 60)
Then wrap the result in quotes. That approach was not taken because of the potential for significant performance impact on very large specs, which our users are often tasked with transforming.
This is related to #3237, which wouldn't be a viable solution because it would remove support for OpenAPI 3.0 types and remove a handful of default configurations in the new YAML factory.
Users who are affected by this edge case or others resulting in the removal of quotes will be able to generate with the system property:
-Dorg.openapitools.codegen.utils.yaml.minimize.quotes=false
This will result in quote behavior similar to the Swagger YAML 1.x/2.x implementation without removing the new expectations for OpenAPI 3.x types.
PR checklist
-
Read the contribution guidelines. -
If contributing template-only or documentation-only changes which will change sample output, build the project before. -
Run the shell script(s) under ./bin/
(or Windows batch scripts under.\bin\windows
) to update Petstore samples related to your fix. This is important, as CI jobs will verify all generator outputs of your HEAD commit, and these must match the expectations made by your contribution. You only need to run./bin/{LANG}-petstore.sh
,./bin/openapi3/{LANG}-petstore.sh
if updating the code or mustache templates for a language ({LANG}
) (e.g. php, ruby, python, etc). -
File the PR against the correct branch: master
,4.3.x
,5.0.x
. Default:master
. -
Copy the technical committee to review the pull request if your PR is targeting a particular programming language.
cc @OpenAPITools/generator-core-team