[BUG][Python] "SyntaxError: more than 255 arguments" when a data type has 255 or more properties
Created by: sebastien-rosset
Bug 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? -
Have you search for related issues/PRs? -
What's the actual output vs expected output? -
[Optional] Bounty to sponsor the fix (example)
Description
The Python model.mustache template generates a __init__ function. The function arguments are the properties defined in the data type. However, because the OpenAPI spec does not set a max limit for the number of properties in a data type, this means a data type could have a list of 300 properties. But until version 3.7, python functions cannot have more than 255 arguments. The generated python code will fail with a syntax error:
SyntaxError: more than 255 arguments
Note that as a comparison point, Java also has a limit of 255 function arguments, but the generated Java class does not exhibit a similar problem. The Java constructor is not generated with a long list of arguments.
openapi-generator version
4.2.1
OpenAPI declaration file content or url
I don't think a OAS content sample is needed. It's obvious from the mustache template that the generated init function could have more than 255 arguments: https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/resources/python/model.mustache#L60
Command line used for generation
Steps to reproduce
- Create a OpenAPI spec with a data type that has 255 or more properties (possibly from "inherited" classes using allOf
- Run the Python code generator. In the generated model file, the __init__ method will have more than 255 arguments.
- Try to execute the SDK using Python 3.6 or earlier. The python interpreter will report a syntax err. With python 3.7 and above, the python interpreter will execute without error.
Related issues/PRs
Suggest a fix
One workaround is to use Python 3.7 or above. However, several Linux distributions do not support 3.7 yet, so it may be operationally complex to require SDK users to install Python 3.7. Another workaround is to ensure that OAS data types should not have more than 254 arguments, which is a good idea anyway. The first argument of __init__ is "self", hence 254. This could be documented in the wiki. Having caveats in the wiki would be helpful. A fix would be to remove the arguments from the __init__ function, but this will break backward compatibility.