Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions .github/workflows/samples-python-petstore.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ jobs:
sample:
- samples/openapi3/client/petstore/python-aiohttp
- samples/openapi3/client/petstore/python
- samples/openapi3/client/petstore/python-lazyImports
services:
petstore-api:
image: swaggerapi/petstore
Expand Down
16 changes: 16 additions & 0 deletions bin/configs/python-lazyImports.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
generatorName: python
outputDir: samples/openapi3/client/petstore/python-lazyImports
inputSpec: modules/openapi-generator/src/test/resources/3_0/python/petstore-with-fake-endpoints-models-for-testing.yaml
templateDir: modules/openapi-generator/src/main/resources/python
additionalProperties:
packageName: petstore_api
useOneOfDiscriminatorLookup: "true"
disallowAdditionalPropertiesIfNotPresent: false
mapNumberTo: StrictFloat
lazyImports: 'true'
nameMappings:
_type: underscore_type
type_: type_with_underscore
modelNameMappings:
# The OpenAPI spec ApiResponse conflicts with the internal ApiResponse
ApiResponse: ModelApiResponse
1 change: 1 addition & 0 deletions docs/generators/python.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|disallowAdditionalPropertiesIfNotPresent|If false, the 'additionalProperties' implementation (set to true by default) is compliant with the OAS and JSON schema specifications. If true (default), keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default.|<dl><dt>**false**</dt><dd>The 'additionalProperties' implementation is compliant with the OAS and JSON schema specifications.</dd><dt>**true**</dt><dd>Keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default.</dd></dl>|true|
|generateSourceCodeOnly|Specifies that only a library source code is to be generated.| |false|
|hideGenerationTimestamp|Hides the generation timestamp when files are generated.| |true|
|lazyImports|Enable lazy imports.| |false|
|library|library template (sub-template) to use: asyncio, tornado (deprecated), urllib3| |urllib3|
|mapNumberTo|Map number to Union[StrictFloat, StrictInt], StrictStr or float.| |Union[StrictFloat, StrictInt]|
|packageName|python package name (convention: snake_case).| |openapi_client|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public class PythonClientCodegen extends AbstractPythonCodegen implements Codege
public static final String DATE_FORMAT = "dateFormat";
public static final String SET_ENSURE_ASCII_TO_FALSE = "setEnsureAsciiToFalse";
public static final String POETRY1_FALLBACK = "poetry1";
public static final String LAZY_IMPORTS = "lazyImports";

@Setter protected String packageUrl;
protected String apiDocPath = "docs/";
Expand Down Expand Up @@ -151,6 +152,7 @@ public PythonClientCodegen() {
.defaultValue("%Y-%m-%d"));
cliOptions.add(new CliOption(CodegenConstants.USE_ONEOF_DISCRIMINATOR_LOOKUP, CodegenConstants.USE_ONEOF_DISCRIMINATOR_LOOKUP_DESC).defaultValue("false"));
cliOptions.add(new CliOption(POETRY1_FALLBACK, "Fallback to formatting pyproject.toml to Poetry 1.x format."));
cliOptions.add(new CliOption(LAZY_IMPORTS, "Enable lazy imports.").defaultValue(Boolean.FALSE.toString()));

supportedLibraries.put("urllib3", "urllib3-based client");
supportedLibraries.put("asyncio", "asyncio-based client");
Expand Down Expand Up @@ -264,6 +266,10 @@ public void processOpts() {
additionalProperties.put(DATE_FORMAT, dateFormat);
}

if (additionalProperties.containsKey(LAZY_IMPORTS)) {
additionalProperties.put(LAZY_IMPORTS, Boolean.valueOf(additionalProperties.get(LAZY_IMPORTS).toString()));
}

String modelPath = packagePath() + File.separatorChar + modelPackage.replace('.', File.separatorChar);
String apiPath = packagePath() + File.separatorChar + apiPackage.replace('.', File.separatorChar);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# flake8: noqa

if __import__("typing").TYPE_CHECKING:
{{^lazyImports}}
{{>exports_api}}
{{/lazyImports}}
{{#lazyImports}}if __import__("typing").TYPE_CHECKING:
{{>exports_api}}
else:
from lazy_imports import LazyModule, as_package, load
Expand All @@ -13,3 +16,4 @@ else:
doc=__doc__,
)
)
{{/lazyImports}}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
# flake8: noqa
{{>partial_header}}


if __import__("typing").TYPE_CHECKING:
{{^lazyImports}}
{{>exports_model}}
{{/lazyImports}}
{{#lazyImports}}if __import__("typing").TYPE_CHECKING:
{{>exports_model}}
else:
from lazy_imports import LazyModule, as_package, load
Expand All @@ -17,3 +19,4 @@ else:
doc=__doc__,
)
)
{{/lazyImports}}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ __all__ = [
{{/-last}}{{#-last}},{{/-last}}{{/model}}{{/models}}
]

if __import__("typing").TYPE_CHECKING:
{{^lazyImports}}
{{>exports_package}}
{{/lazyImports}}
{{#lazyImports}}if __import__("typing").TYPE_CHECKING:
{{>exports_package}}
else:
from lazy_imports import LazyModule, as_package, load
Expand All @@ -39,6 +42,7 @@ else:
doc=__doc__,
)
)
{{/lazyImports}}
{{#recursionLimit}}

__import__('sys').setrecursionlimit({{{.}}})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ pycryptodome = ">= 3.9.0"
{{/hasHttpSignatureMethods}}
pydantic = ">= 2"
typing-extensions = ">= 4.7.1"
{{#lazyImports}}
lazy-imports = ">= 1, < 2"
{{/lazyImports}}
{{/poetry1}}
{{^poetry1}}
requires-python = ">=3.9"
Expand All @@ -64,7 +66,9 @@ dependencies = [
{{/hasHttpSignatureMethods}}
"pydantic (>=2)",
"typing-extensions (>=4.7.1)",
{{#lazyImports}}
"lazy-imports (>=1,<2)"
{{/lazyImports}}
]

[project.urls]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ pycryptodome >= 3.9.0
{{/hasHttpSignatureMethods}}
pydantic >= 2
typing-extensions >= 4.7.1
{{#lazyImports}}
lazy-imports >= 1, < 2
{{/lazyImports}}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ REQUIRES = [
{{/hasHttpSignatureMethods}}
"pydantic >= 2",
"typing-extensions >= 4.7.1",
{{#lazyImports}}
"lazy-imports >= 1, < 2",
{{/lazyImports}}
]

setup(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,49 +48,7 @@
"TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter",
]

if __import__("typing").TYPE_CHECKING:
# import apis into sdk package
from openapi_client.api.auth_api import AuthApi as AuthApi
from openapi_client.api.body_api import BodyApi as BodyApi
from openapi_client.api.form_api import FormApi as FormApi
from openapi_client.api.header_api import HeaderApi as HeaderApi
from openapi_client.api.path_api import PathApi as PathApi
from openapi_client.api.query_api import QueryApi as QueryApi

# import ApiClient
from openapi_client.api_response import ApiResponse as ApiResponse
from openapi_client.api_client import ApiClient as ApiClient
from openapi_client.configuration import Configuration as Configuration
from openapi_client.exceptions import OpenApiException as OpenApiException
from openapi_client.exceptions import ApiTypeError as ApiTypeError
from openapi_client.exceptions import ApiValueError as ApiValueError
from openapi_client.exceptions import ApiKeyError as ApiKeyError
from openapi_client.exceptions import ApiAttributeError as ApiAttributeError
from openapi_client.exceptions import ApiException as ApiException

# import models into sdk package
from openapi_client.models.bird import Bird as Bird
from openapi_client.models.category import Category as Category
from openapi_client.models.data_query import DataQuery as DataQuery
from openapi_client.models.default_value import DefaultValue as DefaultValue
from openapi_client.models.number_properties_only import NumberPropertiesOnly as NumberPropertiesOnly
from openapi_client.models.pet import Pet as Pet
from openapi_client.models.query import Query as Query
from openapi_client.models.string_enum_ref import StringEnumRef as StringEnumRef
from openapi_client.models.tag import Tag as Tag
from openapi_client.models.test_form_object_multipart_request_marker import TestFormObjectMultipartRequestMarker as TestFormObjectMultipartRequestMarker
from openapi_client.models.test_query_style_deep_object_explode_true_object_all_of_query_object_parameter import TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter as TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter
from openapi_client.models.test_query_style_form_explode_true_array_string_query_object_parameter import TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter as TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter

else:
from lazy_imports import LazyModule, as_package, load

load(
LazyModule(
*as_package(__file__),
("__version__", __version__),
("__all__", __all__),
"""# import apis into sdk package
# import apis into sdk package
from openapi_client.api.auth_api import AuthApi as AuthApi
from openapi_client.api.body_api import BodyApi as BodyApi
from openapi_client.api.form_api import FormApi as FormApi
Expand Down Expand Up @@ -123,8 +81,3 @@
from openapi_client.models.test_query_style_deep_object_explode_true_object_all_of_query_object_parameter import TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter as TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter
from openapi_client.models.test_query_style_form_explode_true_array_string_query_object_parameter import TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter as TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter

""",
name=__name__,
doc=__doc__,
)
)
Original file line number Diff line number Diff line change
@@ -1,30 +1,10 @@
# flake8: noqa

if __import__("typing").TYPE_CHECKING:
# import apis into api package
from openapi_client.api.auth_api import AuthApi
from openapi_client.api.body_api import BodyApi
from openapi_client.api.form_api import FormApi
from openapi_client.api.header_api import HeaderApi
from openapi_client.api.path_api import PathApi
from openapi_client.api.query_api import QueryApi

else:
from lazy_imports import LazyModule, as_package, load

load(
LazyModule(
*as_package(__file__),
"""# import apis into api package
# import apis into api package
from openapi_client.api.auth_api import AuthApi
from openapi_client.api.body_api import BodyApi
from openapi_client.api.form_api import FormApi
from openapi_client.api.header_api import HeaderApi
from openapi_client.api.path_api import PathApi
from openapi_client.api.query_api import QueryApi

""",
name=__name__,
doc=__doc__,
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,7 @@
Do not edit the class manually.
""" # noqa: E501


if __import__("typing").TYPE_CHECKING:
# import models into model package
from openapi_client.models.bird import Bird
from openapi_client.models.category import Category
from openapi_client.models.data_query import DataQuery
from openapi_client.models.default_value import DefaultValue
from openapi_client.models.number_properties_only import NumberPropertiesOnly
from openapi_client.models.pet import Pet
from openapi_client.models.query import Query
from openapi_client.models.string_enum_ref import StringEnumRef
from openapi_client.models.tag import Tag
from openapi_client.models.test_form_object_multipart_request_marker import TestFormObjectMultipartRequestMarker
from openapi_client.models.test_query_style_deep_object_explode_true_object_all_of_query_object_parameter import TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter
from openapi_client.models.test_query_style_form_explode_true_array_string_query_object_parameter import TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter

else:
from lazy_imports import LazyModule, as_package, load

load(
LazyModule(
*as_package(__file__),
"""# import models into model package
# import models into model package
from openapi_client.models.bird import Bird
from openapi_client.models.category import Category
from openapi_client.models.data_query import DataQuery
Expand All @@ -49,8 +27,3 @@
from openapi_client.models.test_query_style_deep_object_explode_true_object_all_of_query_object_parameter import TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter
from openapi_client.models.test_query_style_form_explode_true_array_string_query_object_parameter import TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter

""",
name=__name__,
doc=__doc__,
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ dependencies = [
"python-dateutil (>=2.8.2)",
"pydantic (>=2)",
"typing-extensions (>=4.7.1)",
"lazy-imports (>=1,<2)"
]

[project.urls]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@ urllib3 >= 2.1.0, < 3.0.0
python_dateutil >= 2.8.2
pydantic >= 2
typing-extensions >= 4.7.1
lazy-imports >= 1, < 2
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
"python-dateutil >= 2.8.2",
"pydantic >= 2",
"typing-extensions >= 4.7.1",
"lazy-imports >= 1, < 2",
]

setup(
Expand Down
49 changes: 1 addition & 48 deletions samples/client/echo_api/python/openapi_client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,49 +48,7 @@
"TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter",
]

if __import__("typing").TYPE_CHECKING:
# import apis into sdk package
from openapi_client.api.auth_api import AuthApi as AuthApi
from openapi_client.api.body_api import BodyApi as BodyApi
from openapi_client.api.form_api import FormApi as FormApi
from openapi_client.api.header_api import HeaderApi as HeaderApi
from openapi_client.api.path_api import PathApi as PathApi
from openapi_client.api.query_api import QueryApi as QueryApi

# import ApiClient
from openapi_client.api_response import ApiResponse as ApiResponse
from openapi_client.api_client import ApiClient as ApiClient
from openapi_client.configuration import Configuration as Configuration
from openapi_client.exceptions import OpenApiException as OpenApiException
from openapi_client.exceptions import ApiTypeError as ApiTypeError
from openapi_client.exceptions import ApiValueError as ApiValueError
from openapi_client.exceptions import ApiKeyError as ApiKeyError
from openapi_client.exceptions import ApiAttributeError as ApiAttributeError
from openapi_client.exceptions import ApiException as ApiException

# import models into sdk package
from openapi_client.models.bird import Bird as Bird
from openapi_client.models.category import Category as Category
from openapi_client.models.data_query import DataQuery as DataQuery
from openapi_client.models.default_value import DefaultValue as DefaultValue
from openapi_client.models.number_properties_only import NumberPropertiesOnly as NumberPropertiesOnly
from openapi_client.models.pet import Pet as Pet
from openapi_client.models.query import Query as Query
from openapi_client.models.string_enum_ref import StringEnumRef as StringEnumRef
from openapi_client.models.tag import Tag as Tag
from openapi_client.models.test_form_object_multipart_request_marker import TestFormObjectMultipartRequestMarker as TestFormObjectMultipartRequestMarker
from openapi_client.models.test_query_style_deep_object_explode_true_object_all_of_query_object_parameter import TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter as TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter
from openapi_client.models.test_query_style_form_explode_true_array_string_query_object_parameter import TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter as TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter

else:
from lazy_imports import LazyModule, as_package, load

load(
LazyModule(
*as_package(__file__),
("__version__", __version__),
("__all__", __all__),
"""# import apis into sdk package
# import apis into sdk package
from openapi_client.api.auth_api import AuthApi as AuthApi
from openapi_client.api.body_api import BodyApi as BodyApi
from openapi_client.api.form_api import FormApi as FormApi
Expand Down Expand Up @@ -123,8 +81,3 @@
from openapi_client.models.test_query_style_deep_object_explode_true_object_all_of_query_object_parameter import TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter as TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter
from openapi_client.models.test_query_style_form_explode_true_array_string_query_object_parameter import TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter as TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter

""",
name=__name__,
doc=__doc__,
)
)
22 changes: 1 addition & 21 deletions samples/client/echo_api/python/openapi_client/api/__init__.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,10 @@
# flake8: noqa

if __import__("typing").TYPE_CHECKING:
# import apis into api package
from openapi_client.api.auth_api import AuthApi
from openapi_client.api.body_api import BodyApi
from openapi_client.api.form_api import FormApi
from openapi_client.api.header_api import HeaderApi
from openapi_client.api.path_api import PathApi
from openapi_client.api.query_api import QueryApi

else:
from lazy_imports import LazyModule, as_package, load

load(
LazyModule(
*as_package(__file__),
"""# import apis into api package
# import apis into api package
from openapi_client.api.auth_api import AuthApi
from openapi_client.api.body_api import BodyApi
from openapi_client.api.form_api import FormApi
from openapi_client.api.header_api import HeaderApi
from openapi_client.api.path_api import PathApi
from openapi_client.api.query_api import QueryApi

""",
name=__name__,
doc=__doc__,
)
)
Loading
Loading