diff --git a/bin/configs/python-experimental.yaml b/bin/configs/python-experimental.yaml index 58aeadafa2c2..9e06973b1d44 100644 --- a/bin/configs/python-experimental.yaml +++ b/bin/configs/python-experimental.yaml @@ -4,3 +4,4 @@ inputSpec: modules/openapi-generator/src/test/resources/3_0/python-experimental/ templateDir: modules/openapi-generator/src/main/resources/python additionalProperties: packageName: petstore_api + recursionLimit: "1234" diff --git a/docs/generators/python-experimental.md b/docs/generators/python-experimental.md index dbb7bbbd5af1..c063b96dec8d 100644 --- a/docs/generators/python-experimental.md +++ b/docs/generators/python-experimental.md @@ -12,6 +12,7 @@ sidebar_label: python-experimental |packageUrl|python package URL.| |null| |packageVersion|python package version.| |1.0.0| |projectName|python project name in setup.py (e.g. petstore-api).| |null| +|recursionLimit|Set the recursion limit. If not set, use the system default value.| |null| |useNose|use the nose test framework| |false| ## IMPORT MAPPING diff --git a/docs/generators/python.md b/docs/generators/python.md index e1361952bb69..a56aa1530ed4 100644 --- a/docs/generators/python.md +++ b/docs/generators/python.md @@ -12,6 +12,7 @@ sidebar_label: python |packageUrl|python package URL.| |null| |packageVersion|python package version.| |1.0.0| |projectName|python project name in setup.py (e.g. petstore-api).| |null| +|recursionLimit|Set the recursion limit. If not set, use the system default value.| |null| |sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true| |useNose|use the nose test framework| |false| diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientCodegen.java index dffc0c62a192..a4061c84de6f 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientCodegen.java @@ -43,6 +43,7 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig public static final String DEFAULT_LIBRARY = "urllib3"; // nose is a python testing framework, we use pytest if USE_NOSE is unset public static final String USE_NOSE = "useNose"; + public static final String RECURSION_LIMIT = "recursionLimit"; protected String packageName = "openapi_client"; protected String packageVersion = "1.0.0"; @@ -184,6 +185,7 @@ public PythonClientCodegen() { .defaultValue(Boolean.FALSE.toString())); cliOptions.add(CliOption.newBoolean(USE_NOSE, "use the nose test framework"). defaultValue(Boolean.FALSE.toString())); + cliOptions.add(new CliOption(RECURSION_LIMIT, "Set the recursion limit. If not set, use the system default value.")); supportedLibraries.put("urllib3", "urllib3-based client"); supportedLibraries.put("asyncio", "Asyncio-based client (python 3.5+)"); @@ -253,6 +255,15 @@ public void processOpts() { setUseNose((String) additionalProperties.get(USE_NOSE)); } + // check to see if setRecursionLimit is set and whether it's an integer + if (additionalProperties.containsKey(RECURSION_LIMIT)) { + try { + Integer.parseInt((String)additionalProperties.get(RECURSION_LIMIT)); + } catch(NumberFormatException | NullPointerException e) { + throw new IllegalArgumentException("recursionLimit must be an integer, e.g. 2000."); + } + } + String readmePath = "README.md"; String readmeTemplate = "README.mustache"; if (generateSourceCodeOnly) { diff --git a/modules/openapi-generator/src/main/resources/python/__init__package.mustache b/modules/openapi-generator/src/main/resources/python/__init__package.mustache index aee16448ad8a..f81dd5735fa9 100644 --- a/modules/openapi-generator/src/main/resources/python/__init__package.mustache +++ b/modules/openapi-generator/src/main/resources/python/__init__package.mustache @@ -23,3 +23,7 @@ from {{packageName}}.exceptions import ApiException # import models into sdk package {{#models}}{{#model}}from {{modelPackage}}.{{classFilename}} import {{classname}} {{/model}}{{/models}} +{{#recursionLimit}} + +__import__('sys').setrecursionlimit({{{.}}}) +{{/recursionLimit}} diff --git a/modules/openapi-generator/src/main/resources/python/python-experimental/__init__package.mustache b/modules/openapi-generator/src/main/resources/python/python-experimental/__init__package.mustache index d0746d3aa687..d7ff5b826025 100644 --- a/modules/openapi-generator/src/main/resources/python/python-experimental/__init__package.mustache +++ b/modules/openapi-generator/src/main/resources/python/python-experimental/__init__package.mustache @@ -21,4 +21,8 @@ from {{packageName}}.exceptions import ApiAttributeError from {{packageName}}.exceptions import ApiTypeError from {{packageName}}.exceptions import ApiValueError from {{packageName}}.exceptions import ApiKeyError -from {{packageName}}.exceptions import ApiException \ No newline at end of file +from {{packageName}}.exceptions import ApiException +{{#recursionLimit}} + +__import__('sys').setrecursionlimit({{{.}}}) +{{/recursionLimit}} diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/options/PythonClientOptionsProvider.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/options/PythonClientOptionsProvider.java index f3ef0cd3d54c..551582d0f031 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/options/PythonClientOptionsProvider.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/options/PythonClientOptionsProvider.java @@ -29,6 +29,7 @@ public class PythonClientOptionsProvider implements OptionsProvider { public static final String PACKAGE_VERSION_VALUE = "1.0.0-SNAPSHOT"; public static final String PACKAGE_URL_VALUE = ""; public static final String USE_NOSE_VALUE = "false"; + public static final String RECURSION_LIMIT = "1200"; @Override public String getLanguage() { @@ -47,6 +48,7 @@ public Map createOptions() { .put(CodegenConstants.SOURCECODEONLY_GENERATION, "false") .put(CodegenConstants.LIBRARY, "urllib3") .put(PythonClientCodegen.USE_NOSE, USE_NOSE_VALUE) + .put(PythonClientCodegen.RECURSION_LIMIT, RECURSION_LIMIT) .build(); } diff --git a/samples/client/petstore/python-experimental/petstore_api/__init__.py b/samples/client/petstore/python-experimental/petstore_api/__init__.py index bd7096a81818..50dbde60cc5a 100644 --- a/samples/client/petstore/python-experimental/petstore_api/__init__.py +++ b/samples/client/petstore/python-experimental/petstore_api/__init__.py @@ -26,4 +26,4 @@ from petstore_api.exceptions import ApiTypeError from petstore_api.exceptions import ApiValueError from petstore_api.exceptions import ApiKeyError -from petstore_api.exceptions import ApiException \ No newline at end of file +from petstore_api.exceptions import ApiException diff --git a/samples/openapi3/client/extensions/x-auth-id-alias/python-experimental/x_auth_id_alias/__init__.py b/samples/openapi3/client/extensions/x-auth-id-alias/python-experimental/x_auth_id_alias/__init__.py index 2003cfda7c10..e041974817db 100644 --- a/samples/openapi3/client/extensions/x-auth-id-alias/python-experimental/x_auth_id_alias/__init__.py +++ b/samples/openapi3/client/extensions/x-auth-id-alias/python-experimental/x_auth_id_alias/__init__.py @@ -26,4 +26,4 @@ from x_auth_id_alias.exceptions import ApiTypeError from x_auth_id_alias.exceptions import ApiValueError from x_auth_id_alias.exceptions import ApiKeyError -from x_auth_id_alias.exceptions import ApiException \ No newline at end of file +from x_auth_id_alias.exceptions import ApiException diff --git a/samples/openapi3/client/features/dynamic-servers/python-experimental/dynamic_servers/__init__.py b/samples/openapi3/client/features/dynamic-servers/python-experimental/dynamic_servers/__init__.py index b7f955894f8d..64364080b716 100644 --- a/samples/openapi3/client/features/dynamic-servers/python-experimental/dynamic_servers/__init__.py +++ b/samples/openapi3/client/features/dynamic-servers/python-experimental/dynamic_servers/__init__.py @@ -26,4 +26,4 @@ from dynamic_servers.exceptions import ApiTypeError from dynamic_servers.exceptions import ApiValueError from dynamic_servers.exceptions import ApiKeyError -from dynamic_servers.exceptions import ApiException \ No newline at end of file +from dynamic_servers.exceptions import ApiException diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/__init__.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/__init__.py index db9beb2ebfb0..1605d7d67c05 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/__init__.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/__init__.py @@ -27,4 +27,6 @@ from petstore_api.exceptions import ApiTypeError from petstore_api.exceptions import ApiValueError from petstore_api.exceptions import ApiKeyError -from petstore_api.exceptions import ApiException \ No newline at end of file +from petstore_api.exceptions import ApiException + +__import__('sys').setrecursionlimit(1234) diff --git a/samples/openapi3/client/petstore/python-experimental/tests_manual/test_fake_api.py b/samples/openapi3/client/petstore/python-experimental/tests_manual/test_fake_api.py index 60dcbd549df9..89695137c6e7 100644 --- a/samples/openapi3/client/petstore/python-experimental/tests_manual/test_fake_api.py +++ b/samples/openapi3/client/petstore/python-experimental/tests_manual/test_fake_api.py @@ -9,6 +9,7 @@ Generated by: https://openapi-generator.tech """ +import sys from collections import namedtuple import unittest import json @@ -98,6 +99,12 @@ def test_boolean(self): assert endpoint.openapi_types['body'] == (bool,) assert endpoint.settings['response_type'] == (bool,) + def test_recursionlimit(self): + """Test case for recursionlimit + + """ + assert sys.getrecursionlimit() == 1234 + def test_fake_health_get(self): """Test case for fake_health_get diff --git a/samples/openapi3/client/petstore/python-experimental/tests_manual/test_shape.py b/samples/openapi3/client/petstore/python-experimental/tests_manual/test_shape.py index d4240f695300..a2b59fc6f31c 100644 --- a/samples/openapi3/client/petstore/python-experimental/tests_manual/test_shape.py +++ b/samples/openapi3/client/petstore/python-experimental/tests_manual/test_shape.py @@ -36,6 +36,12 @@ def setUp(self): def tearDown(self): pass + def test_recursionlimit(self): + """Test case for recursionlimit + + """ + assert sys.getrecursionlimit() == 1234 + def testShape(self): """Test Shape""" from petstore_api.model import complex_quadrilateral @@ -43,6 +49,7 @@ def testShape(self): from petstore_api.model import equilateral_triangle from petstore_api.model import isosceles_triangle from petstore_api.model import scalene_triangle + tri = triangle.Triangle( shape_type="Triangle", triangle_type="EquilateralTriangle"