Skip to content

Commit 0b177b5

Browse files
marceljkFyusel
andauthored
feat: update python sdk generator (#169)
* fix: not working renovate * remove not customized python templates * remove python version 3.8 * add readme for python templates * upgrade generator and templates to v7.14.0 of the openapi-generator * review finding Co-authored-by: Alexander Dahmen <[email protected]>
1 parent b0f4190 commit 0b177b5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+124
-2139
lines changed

.github/renovate.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,20 @@
1414
"customManagers": [
1515
{
1616
"customType": "regex",
17-
"fileMatch": [
18-
"(^|\\/)generate-sdk\\.sh$"
17+
"managerFilePatterns": [
18+
"/(^|\\/)generate-sdk\\.sh$/"
1919
],
2020
"matchStrings": [
21-
"# Renovate: datasource=(?<datasource>.*?) depName=(?<depName>.*?) versioning=(?<versioning>.*?)?\\sGENERATOR_VERSION=\\\"?(?<currentValue>.*?)\\\"\\s"
21+
"# Renovate: datasource=(?<datasource>.*?) depName=(?<depName>.*?) versioning=(?<versioning>.*?)?\\s+GENERATOR_VERSION=\"?(?<currentValue>.*?)\""
2222
]
2323
},
2424
{
2525
"customType": "regex",
26-
"fileMatch": [
27-
"(^|\\/)go\\.mod\\.mustache$"
26+
"managerFilePatterns": [
27+
"/(^|\\/)go\\.mod\\.mustache$/"
2828
],
2929
"matchStrings": [
30-
"{{gitHost}}\\/{{gitUserId}}\\/{{gitRepoId}}\\/core ?(?<currentValue>.*?)\\s"
30+
"github.com\/stackitcloud\/stackit-sdk-go\/core (?<currentValue>.*?)\\s"
3131
],
3232
"datasourceTemplate": "go",
3333
"depNameTemplate": "github.com/stackitcloud/stackit-sdk-go",

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ jobs:
7979
strategy:
8080
matrix:
8181
os: [ubuntu-latest, macos-latest]
82-
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
82+
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
8383
runs-on: ${{ matrix.os }}
8484
steps:
8585
- name: Install SSH Key

scripts/generate-sdk/generate-sdk.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ go)
5757
GENERATOR_VERSION="v6.6.0" # There are issues with GO SDK generation in version v7
5858
;;
5959
python)
60-
GENERATOR_VERSION="v7.9.0"
60+
# Renovate: datasource=github-tags depName=OpenAPITools/openapi-generator versioning=semver
61+
GENERATOR_VERSION="v7.14.0"
6162
;;
6263
*)
6364
echo "SDK language not supported."
@@ -90,8 +91,8 @@ python)
9091
echo -e "\n>> Generating the Python SDK..."
9192

9293
source ${LANGUAGE_GENERATORS_FOLDER_PATH}/${LANGUAGE}.sh
93-
# Usage: generate_python_sdk GENERATOR_PATH GIT_HOST GIT_USER_ID [GIT_REPO_ID] [SDK_REPO_URL]
94-
generate_python_sdk ${jar_path} ${GIT_HOST} ${GIT_USER_ID} ${GIT_REPO_ID} ${SDK_REPO_URL}
94+
# Usage: generate_python_sdk GENERATOR_PATH GIT_HOST GIT_USER_ID [GIT_REPO_ID] [SDK_REPO_URL] [SDK_BRANCH]
95+
generate_python_sdk "${jar_path}" "${GIT_HOST}" "${GIT_USER_ID}" "${GIT_REPO_ID}" "${SDK_REPO_URL}" "${SDK_BRANCH}"
9596
;;
9697
*)
9798
echo "! SDK language not supported."

scripts/generate-sdk/languages/python.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ generate_python_sdk() {
2121
# Optional parameters
2222
local GIT_REPO_ID=$4
2323
local SDK_REPO_URL=$5
24+
local SDK_BRANCH=$6
2425

2526
# Check required parameters
2627
if [[ -z ${GIT_HOST} ]]; then
@@ -54,7 +55,7 @@ generate_python_sdk() {
5455
echo "Old SDK repo clone was found, it will be removed."
5556
rm -rf ${SDK_REPO_LOCAL_PATH}
5657
fi
57-
git clone --quiet ${SDK_REPO_URL} ${SDK_REPO_LOCAL_PATH}
58+
git clone --quiet -b ${SDK_BRANCH} ${SDK_REPO_URL} ${SDK_REPO_LOCAL_PATH}
5859

5960
# Install SDK project tools
6061
cd ${ROOT_DIR}

templates/python/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Python templates
2+
3+
This folder contains only our customized python templates. Beside these customized templates,
4+
the original templates of openapi-generator for python are used. These can be found in the
5+
official GitHub repo of the [openapi-generator](https://github.com/OpenAPITools/openapi-generator/tree/v7.14.0/modules/openapi-generator/src/main/resources/python).
6+
7+
If you need to change something in the Python Generator, try always first to add
8+
[user-defined templates](https://openapi-generator.tech/docs/customization#user-defined-templates),
9+
instead of overwriting existing templates. These ensure an easier upgrade process, to newer
10+
versions of the openapi-generator.
11+
12+
If it's required to customize the original templates, you can copy them into this directory.
13+
Try to minimize the customization as much as possible, to ensure, that we can easily upgrade
14+
to newer versions in the future.

templates/python/README_onlypackage.mustache

Lines changed: 0 additions & 44 deletions
This file was deleted.

templates/python/__init__.mustache

Whitespace-only changes.

templates/python/__init__api.mustache

Lines changed: 0 additions & 5 deletions
This file was deleted.

templates/python/__init__model.mustache

Lines changed: 0 additions & 11 deletions
This file was deleted.

templates/python/__init__package.mustache

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,44 @@
66

77
__version__ = "{{packageVersion}}"
88

9+
# Define package exports
10+
__all__ = [
11+
{{#apiInfo}}{{#apis}}"{{classname}}",
12+
{{/apis}}{{/apiInfo}}"ApiResponse",
13+
"ApiClient",
14+
"HostConfiguration",
15+
"OpenApiException",
16+
"ApiTypeError",
17+
"ApiValueError",
18+
"ApiKeyError",
19+
"ApiAttributeError",
20+
"ApiException",
21+
{{#hasHttpSignatureMethods}}"HttpSigningConfiguration",
22+
{{/hasHttpSignatureMethods}}{{#models}}{{#model}}"{{classname}}"{{^-last}},
23+
{{/-last}}{{#-last}},{{/-last}}{{/model}}{{/models}}
24+
]
25+
926
# import apis into sdk package
10-
{{#apiInfo}}{{#apis}}from {{apiPackage}}.{{classFilename}} import {{classname}}
27+
{{#apiInfo}}{{#apis}}from {{apiPackage}}.{{classFilename}} import {{classname}} as {{classname}}
1128
{{/apis}}{{/apiInfo}}
1229
# import ApiClient
13-
from {{packageName}}.api_response import ApiResponse
14-
from {{packageName}}.api_client import ApiClient
15-
from {{packageName}}.configuration import HostConfiguration
16-
from {{packageName}}.exceptions import OpenApiException
17-
from {{packageName}}.exceptions import ApiTypeError
18-
from {{packageName}}.exceptions import ApiValueError
19-
from {{packageName}}.exceptions import ApiKeyError
20-
from {{packageName}}.exceptions import ApiAttributeError
21-
from {{packageName}}.exceptions import ApiException
30+
from {{packageName}}.api_response import ApiResponse as ApiResponse
31+
from {{packageName}}.api_client import ApiClient as ApiClient
32+
from {{packageName}}.configuration import HostConfiguration as HostConfiguration
33+
from {{packageName}}.exceptions import OpenApiException as OpenApiException
34+
from {{packageName}}.exceptions import ApiTypeError as ApiTypeError
35+
from {{packageName}}.exceptions import ApiValueError as ApiValueError
36+
from {{packageName}}.exceptions import ApiKeyError as ApiKeyError
37+
from {{packageName}}.exceptions import ApiAttributeError as ApiAttributeError
38+
from {{packageName}}.exceptions import ApiException as ApiException
2239
{{#hasHttpSignatureMethods}}
23-
from {{packageName}}.signing import HttpSigningConfiguration
40+
from {{packageName}}.signing import HttpSigningConfiguration as HttpSigningConfiguration
2441
{{/hasHttpSignatureMethods}}
2542

2643
# import models into sdk package
2744
{{#models}}
2845
{{#model}}
29-
from {{modelPackage}}.{{classFilename}} import {{classname}}
46+
from {{modelPackage}}.{{classFilename}} import {{classname}} as {{classname}}
3047
{{/model}}
3148
{{/models}}
3249
{{#recursionLimit}}

0 commit comments

Comments
 (0)