mirror of
https://github.com/jlengrand/openapi-generator.git
synced 2026-03-10 08:31:23 +00:00
Add option to set recursion limit (#7491)
* add option to set recursion limit * fix test failure * update doc * add tests * add missing import * rename option to recursionLimit
This commit is contained in:
@@ -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"
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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|
|
||||
|
||||
|
||||
@@ -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 class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
.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 class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
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) {
|
||||
|
||||
@@ -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}}
|
||||
|
||||
@@ -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
|
||||
from {{packageName}}.exceptions import ApiException
|
||||
{{#recursionLimit}}
|
||||
|
||||
__import__('sys').setrecursionlimit({{{.}}})
|
||||
{{/recursionLimit}}
|
||||
|
||||
@@ -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 class PythonClientOptionsProvider implements OptionsProvider {
|
||||
.put(CodegenConstants.SOURCECODEONLY_GENERATION, "false")
|
||||
.put(CodegenConstants.LIBRARY, "urllib3")
|
||||
.put(PythonClientCodegen.USE_NOSE, USE_NOSE_VALUE)
|
||||
.put(PythonClientCodegen.RECURSION_LIMIT, RECURSION_LIMIT)
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
@@ -26,4 +26,4 @@ from petstore_api.exceptions import ApiAttributeError
|
||||
from petstore_api.exceptions import ApiTypeError
|
||||
from petstore_api.exceptions import ApiValueError
|
||||
from petstore_api.exceptions import ApiKeyError
|
||||
from petstore_api.exceptions import ApiException
|
||||
from petstore_api.exceptions import ApiException
|
||||
|
||||
@@ -26,4 +26,4 @@ from x_auth_id_alias.exceptions import ApiAttributeError
|
||||
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
|
||||
from x_auth_id_alias.exceptions import ApiException
|
||||
|
||||
@@ -26,4 +26,4 @@ from dynamic_servers.exceptions import ApiAttributeError
|
||||
from dynamic_servers.exceptions import ApiTypeError
|
||||
from dynamic_servers.exceptions import ApiValueError
|
||||
from dynamic_servers.exceptions import ApiKeyError
|
||||
from dynamic_servers.exceptions import ApiException
|
||||
from dynamic_servers.exceptions import ApiException
|
||||
|
||||
@@ -27,4 +27,6 @@ from petstore_api.exceptions import ApiAttributeError
|
||||
from petstore_api.exceptions import ApiTypeError
|
||||
from petstore_api.exceptions import ApiValueError
|
||||
from petstore_api.exceptions import ApiKeyError
|
||||
from petstore_api.exceptions import ApiException
|
||||
from petstore_api.exceptions import ApiException
|
||||
|
||||
__import__('sys').setrecursionlimit(1234)
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
Generated by: https://openapi-generator.tech
|
||||
"""
|
||||
|
||||
import sys
|
||||
from collections import namedtuple
|
||||
import unittest
|
||||
import json
|
||||
@@ -98,6 +99,12 @@ class TestFakeApi(unittest.TestCase):
|
||||
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
|
||||
|
||||
|
||||
@@ -36,6 +36,12 @@ class TestShape(unittest.TestCase):
|
||||
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 @@ class TestShape(unittest.TestCase):
|
||||
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"
|
||||
|
||||
Reference in New Issue
Block a user