[BUG] Python generator generating reserved word ("from")
See original GitHub issueBug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- What’s the version of OpenAPI Generator used? v4.3.1 (implementation-version: 4.3.1)
- Have you search for related issues/PRs? Yes
- What’s the actual output vs expected output? See below
- [Optional] Bounty to sponsor the fix (example)
Description
When using the python generator (not the experimental one) the provided spec generates a python test that uses a reserved word as a variable name. This causes python to blow up.
The spec has to have this property: A python reserved word is used as a nested property in a schema (FailureStats -> FailureStat -> from). From is a reserved word in python but is not escaped because it’s nested. In the provided sample it ends up being generated in a test file:
def make_instance(self, include_optional):
"""Test FailureStats
include_option is a boolean, when False only required
params are included, when True both required and
optional params are included """
# model = openapi_client.models.failure_stats.FailureStats() # noqa: E501
if include_optional :
return FailureStats(
version = 56,
status = '0',
code = 56,
offset = 56,
count = 56,
failure_stats = [
openapi_client.models.failure_stat.FailureStat(
samples = 56,
subject = '0',
from = '0', # HERE!
domain = '0',
first_occurrence = datetime.datetime.strptime('2013-10-20 19:20:30.00', '%Y-%m-%d %H:%M:%S.%f'),
last_occurrence = datetime.datetime.strptime('2013-10-20 19:20:30.00', '%Y-%m-%d %H:%M:%S.%f'),
ip_count = 56,
links = [
'0'
], )
]
)
else :
return FailureStats(
)
openapi-generator version
v4.3.1 (implementation-version: 4.3.1). Does not appear to be a regression that I can see.
OpenAPI declaration file content or url
Command line used for generation
java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -i spec3.yaml -g python -o ./output/
Steps to reproduce
Download openapi-generator-cli.jar from github. java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -i spec3.yaml -g python -o ./output/ pytest ./output/test/
Related issues/PRs
I couldnt find any that seemed to mimic this issue for python.
Suggest a fix
In PythonClientCodegen.java. On line 872. Just add the following:
if (isReservedWord(propname)) {
propname = escapeReservedWord(propname);
}
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:7 (2 by maintainers)
Top GitHub Comments
I have the same exact issue, were you able to find a past version that this was resolved in?
Having the same problem with a nested “self” unfortunately.
TypeError: wrapped_init() got multiple values for argument 'self'
.Tested with v5.0.0-beta3 and 4.3.1.