You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
Currently, the implementation of the code generator for Python can generate invalid Python code if single quotes are used within an OpenAPI specification, e.g. for default values. This stems from invalid single quote escaping within the generator.
This seems to have happened already quite a few years ago during refactoring, since the test seems might have been created as a result of this #5981.
The minimal example from there is still valid and is again used as an example below
It's kind of hard to spot, but in Java the strings "'" and "\'" (edit: in markdown too apparently 😂) are identical, so the implementation and its test were broken identically.
The simple solution is to use correct escaping in Java by double escaping the backward slash \\, so that a single backward slash is actually included in the output.
Please see here for a PR that fixes the issue as explain before.
The text was updated successfully, but these errors were encountered:
Bug Report Checklist
Description
Currently, the implementation of the code generator for Python can generate invalid Python code if single quotes are used within an OpenAPI specification, e.g. for default values. This stems from invalid single quote escaping within the generator.
This seems to have happened already quite a few years ago during refactoring, since the test seems might have been created as a result of this #5981.
The minimal example from there is still valid and is again used as an example below
openapi-generator version
7.13.0 @ 04169ec
OpenAPI declaration file content or url
Generation Details
docker run --rm -v $(pwd)/bla:/bla -v $(pwd):/local openapitools/openapi-generator-cli:latest generate -i /local/bla.yaml -g python -o /bla
Steps to reproduce
Run the above command.
Expected output
bla/openapi_client/models/single_quote_example_post_request.py
Actual output
bla/openapi_client/models/single_quote_example_post_request.py
Related issues/PRs
Issue 5981
Suggest a fix
It's kind of hard to spot, but in Java the strings "'" and "\'" (edit: in markdown too apparently 😂) are identical, so the implementation and its test were broken identically.
The simple solution is to use correct escaping in Java by double escaping the backward slash
\\
, so that a single backward slash is actually included in the output.Please see here for a PR that fixes the issue as explain before.
The text was updated successfully, but these errors were encountered: