Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Merge requests
  • !5933

[feat] Allow configuration of yaml minimize quotes

  • Review changes

  • Download
  • Email patches
  • Plain diff
Merged Jim Schubert requested to merge yaml-formatting-python-flask into master Apr 15, 2020
  • Overview 0
  • Commits 1
  • Pipelines 0
  • Changes 2

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

Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: yaml-formatting-python-flask