Skip to content
Merged
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 88 additions & 0 deletions languages/python/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# STACKIT Python SDK Generator

## Quick Update Guide

| File | Action |
|------------------------------------|-----------------------------------------|
| `configuration.mustache` | do nothing |
| `readme.mustache` | do nothing |
| `pyproject.mustache` | check dependencies, adjust if necessary |
| `rest.mustache` | port changes |
| `api.mustache` | port changes |
| `api_client.mustache` | port changes |
| `model_generic.mustache` | port changes |
| `model_oneof.mustache` | port changes |
| `exceptions.mustache` | port changes |
| `__init__package.mustache` | port changes |
| `README_onlypackage.mustache` | do nothing, unchanged |
| `api_doc.mustache` | do nothing, unchanged |
| `api_doc_example.mustache` | do nothing, unchanged |
| `api_response.mustache` | do nothing, unchanged |
| `api_test.mustache` | do nothing, unchanged |
| `asyncio` | do nothing, unchanged |
| `common_README.mustache` | do nothing, unchanged |
| `__init__.mustache` | do nothing, unchanged |
| `__init__api.mustache` | do nothing, unchanged |
| `__init__model.mustache` | do nothing, unchanged |
| `git_push.sh.mustache` | do nothing, unchanged |
| `github-workflow.mustache` | do nothing, unchanged |
| `gitignore.mustache` | do nothing, unchanged |
| `gitlab-ci.mustache` | do nothing, unchanged |
| `model.mustache` | do nothing, unchanged |
| `model_anyof.mustache` | do nothing, unchanged |
| `model_doc.mustache` | do nothing, unchanged |
| `model_enum.mustache` | do nothing, unchanged |
| `model_test.mustache` | do nothing, unchanged |
| `partial_api.mustache` | do nothing, unchanged |
| `partial_api_args.mustache` | do nothing, unchanged |
| `partial_header.mustache` | do nothing, unchanged |
| `py.typed.mustache` | do nothing, unchanged |
| `python_doc_auth_partial.mustache` | do nothing, unchanged |
| `requirements.mustache` | do nothing, unchanged |
| `rest.mustache` | do nothing, unchanged |
| `setup.mustache` | do nothing, unchanged |
| `setup_cfg.mustache` | do nothing, unchanged |
| `signing.mustache` | do nothing, unchanged |
| `test-requirements.mustache` | do nothing, unchanged |
| `tornado` | do nothing, unchanged |
| `tox.mustache` | do nothing, unchanged |
| `travis.mustache` | do nothing, unchanged |
| `exports_api.mustache` | do nothing, unchanged |
| `exports_model.mustache` | do nothing, unchanged |
| `exports_package.mustache` | do nothing, unchanged |


If upstream contains a template, not listed here, adjust the table accordingly.

## Template adjustments

The following templates were customized but don't need to be adjusted when updating the Python SDK generator to a newer
upstream version:

- `configuration.mustache`: This template was entirely overwritten to provide a custom `HostConfiguration`. The
`Configuration` from `core` is used instead of generating a new one for each service.
- `readme.mustache`: it's the readme
- `pyproject.mustache`: heavily customized to use `uv`, just check the dependencies

The following templates were customized and need to be checked for adjustments when updating the Python SDK generator to
a newer upstream version:

- `rest.mustache`:
- uses `requests` instead of `urllib3` for making HTTP requests. This is done to use the same library as `core` does.
`core` uses `requests` because of an ADR: "HTTP Client for Python Core Implementation" (internal link).
- upstream also configures a `urllib3.PoolManager` for each API client. In `requests` this is done by using
`requests.Session()` for doing requests. A global pool can be used by setting `custom_http_session` on `Config`.
- `api.mustache`:
- customized to use `core`'s `Configuration`
- `api_client.mustache`:
- customized to use `core`'s `Configuration`
- `update_params_for_auth` and `_apply_auth_params` removed, authentication is done in `core`
- `model_generic.mustache`:
- contains a temporary workaround for the year 0 issue
- `model_oneof.mustache`:
- workaround for pattern containing leading and trailing `/`
- removal of `ValueError` if multiple matches are found
- `exceptions.mustache`:
- use `requests` instead of `urllib3`
- `__init__package.mustache`:
- customized imports
6 changes: 6 additions & 0 deletions languages/python/templates/__init__package.mustache
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
{{! This template was customized. See https://github.com/OpenAPITools/openapi-generator/blob/v7.20.0/modules/openapi-generator/src/main/resources/python/__init__package.mustache for the original template }}
# coding: utf-8

# flake8: noqa

{{>partial_header}}


__version__ = "{{packageVersion}}"

# Define package exports
__all__ = [
{{#apiInfo}}{{#apis}}"{{classname}}",
{{/apis}}{{/apiInfo}}"ApiResponse",
"ApiClient",
{{! TEMPLATE CUSTOMIZATION - BEGIN - custom config }}
"HostConfiguration",
{{! TEMPLATE CUSTOMIZATION - END - custom config }}
"OpenApiException",
"ApiTypeError",
"ApiValueError",
Expand All @@ -23,6 +27,7 @@ __all__ = [
{{/-last}}{{#-last}},{{/-last}}{{/model}}{{/models}}
]

{{! TEMPLATE CUSTOMIZATION - BEGIN - custom imports }}
# import apis into sdk package
{{#apiInfo}}{{#apis}}from {{apiPackage}}.{{classFilename}} import {{classname}} as {{classname}}
{{/apis}}{{/apiInfo}}
Expand All @@ -46,6 +51,7 @@ from {{packageName}}.signing import HttpSigningConfiguration as HttpSigningConfi
from {{modelPackage}}.{{classFilename}} import {{classname}} as {{classname}}
{{/model}}
{{/models}}
{{! TEMPLATE CUSTOMIZATION - END - custom imports }}
{{#recursionLimit}}

__import__('sys').setrecursionlimit({{{.}}})
Expand Down
26 changes: 17 additions & 9 deletions languages/python/templates/api.mustache
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{! This template was customized. See https://github.com/OpenAPITools/openapi-generator/blob/v7.20.0/modules/openapi-generator/src/main/resources/python/api.mustache for the original template }}
# coding: utf-8

{{>partial_header}}
Expand All @@ -10,7 +11,9 @@ from typing_extensions import Annotated
{{import}}
{{/imports}}

{{! TEMPLATE CUSTOMIZATION - BEGIN - custom config }}
from stackit.core.configuration import Configuration
{{! TEMPLATE CUSTOMIZATION - END - custom config }}
from {{packageName}}.api_client import ApiClient, RequestSerialized
from {{packageName}}.api_response import ApiResponse
from {{packageName}}.rest import RESTResponseType
Expand All @@ -24,46 +27,51 @@ class {{classname}}:
Do not edit the class manually.
"""

{{! TEMPLATE CUSTOMIZATION - BEGIN - custom config }}
def __init__(self, configuration: Configuration = None) -> None:
if configuration is None:
configuration = Configuration()
self.configuration = configuration
self.api_client = ApiClient(self.configuration)
{{! TEMPLATE CUSTOMIZATION - END - custom config }}
{{#operation}}


@validate_call
{{#asyncio}}async {{/asyncio}}def {{operationId}}{{>partial_api_args}} -> {{{returnType}}}{{^returnType}}None{{/returnType}}:
{{#async}}async {{/async}}def {{operationId}}{{>partial_api_args}} -> {{{returnType}}}{{^returnType}}None{{/returnType}}:
{{>partial_api}}
response_data = {{#asyncio}}await {{/asyncio}}self.api_client.call_api(

response_data = {{#async}}await {{/async}}self.api_client.call_api(
*_param,
_request_timeout=_request_timeout
)
{{#asyncio}}await {{/asyncio}}response_data.read()
{{#async}}await {{/async}}response_data.read()
return self.api_client.response_deserialize(
response_data=response_data,
response_types_map=_response_types_map,
).data


@validate_call
{{#asyncio}}async {{/asyncio}}def {{operationId}}_with_http_info{{>partial_api_args}} -> ApiResponse[{{{returnType}}}{{^returnType}}None{{/returnType}}]:
{{#async}}async {{/async}}def {{operationId}}_with_http_info{{>partial_api_args}} -> ApiResponse[{{{returnType}}}{{^returnType}}None{{/returnType}}]:
{{>partial_api}}
response_data = {{#asyncio}}await {{/asyncio}}self.api_client.call_api(

response_data = {{#async}}await {{/async}}self.api_client.call_api(
*_param,
_request_timeout=_request_timeout
)
{{#asyncio}}await {{/asyncio}}response_data.read()
{{#async}}await {{/async}}response_data.read()
return self.api_client.response_deserialize(
response_data=response_data,
response_types_map=_response_types_map,
)


@validate_call
{{#asyncio}}async {{/asyncio}}def {{operationId}}_without_preload_content{{>partial_api_args}} -> RESTResponseType:
{{#async}}async {{/async}}def {{operationId}}_without_preload_content{{>partial_api_args}} -> RESTResponseType:
{{>partial_api}}
response_data = {{#asyncio}}await {{/asyncio}}self.api_client.call_api(

response_data = {{#async}}await {{/async}}self.api_client.call_api(
*_param,
_request_timeout=_request_timeout
)
Expand Down Expand Up @@ -183,7 +191,7 @@ class {{classname}}:
{{#constantParams}}
{{#isQueryParam}}
# Set client side default value of Query Param "{{baseName}}".
_query_params['{{baseName}}'] = {{#_enum}}'{{{.}}}'{{/_enum}}
_query_params.append(('{{baseName}}', {{#_enum}}'{{{.}}}'{{/_enum}}))
{{/isQueryParam}}
{{#isHeaderParam}}
# Set client side default value of Header Param "{{baseName}}".
Expand Down
Loading
Loading