Skip to content

Commit 60d133f

Browse files
CAIP-99 Regenerate code using latest openapi generator (#374)
* try * regenerate * Added script and new generator * Fix unittests on auth * Fix unittests on application service * Fix unittests on application service * Fix unittests on signal and presence service * Fix unittests on connection and message service * Fix unittests on api_client_factory and stream services * Fix unittests on group .. still need attention * Fix unittests on message service ... added new multi_attachment api * Formatted code * New generated api_client * Update the generation script and init * small fixes * Headers index seems to be changed * Small fixes for user service * Fix tests * Check if config was async * Fix multi part request * generate using 7.14 * Removed url_safe function * Fix tests * Remove test for pool_manager .. now it's initiated at use * Fix lint errors * Update readme * Add typer to pyproject * Update cve scan command * Revert "Update cve scan command" This reverts commit 2c49c90. * Revert "Add typer to pyproject" This reverts commit 95e491f. * Update build * Update build release * CAIP-119 Fix datahose loop (#376) * Fix datahose implementation: use datahose api in datahose loop replacing the datafeed api * Add version * Generate code using latest commit available * Update to latest version of specs (without form values changes) * Update version to beta
1 parent 5c67a1d commit 60d133f

503 files changed

Lines changed: 90439 additions & 134718 deletions

File tree

Some content is hidden

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

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ on:
44
push:
55
branches: [ "main", "*-rc" ]
66
pull_request:
7-
branches: [ "main", "*-rc" ]
7+
branches: [ "main", "*-rc", "release/3.x" ]
88

99
jobs:
1010
build:

README.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,31 @@ _NOTE:_ Ensure you have an active Individual Contributor License Agreement (ICLA
7070

7171
For further inquiries, email [help@finos.org](mailto:help@finos.org).
7272

73-
7473
### Updating Generated Code
7574

7675
Python BDK uses [OpenAPITools/openapi-generator](https://github.com/OpenAPITools/openapi-generator/) to generate code.
7776
To update the generated code, follow these steps:
7877

78+
1. Download desired version of openapi generator.
79+
```bash
80+
cd api_client_generation
81+
curl -L https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/7.14.0/openapi-generator-cli-7.14.0.jar -o openapi-generator-cli.jar
82+
```
83+
2. Adjust the commit for which the code is generated(inside generate.sh script)
84+
3. Execute the generation script:
85+
```bash
86+
./generate.sh
87+
```
88+
4. Commit and push the newly generated code along with the updated JAR file.
89+
90+
Note: There are a few files that are not replaced(EX. api_client.py), those files require some modifications after code is generated.
91+
92+
93+
### OLD Updating Generated Code (Deprecated)
94+
95+
Python BDK uses [OpenAPITools/openapi-generator](https://github.com/OpenAPITools/openapi-generator/) to generate code.
96+
To update the generated code, follow these steps:
97+
7998
1. Checkout the latest branch of the fork (e.g., [sym-python-5.5.0](https://github.com/SymphonyPlatformSolutions/openapi-generator/tree/sym-python-5.5.0)).
8099
2. Update the fork source code, review, and merge it.
81100
3. Generate the JAR file in `openapi-generatormodules/openapi-generator-cli/target/openapi-generator-cli.jar`:

api_client_generation/generate.sh

Lines changed: 90 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -4,92 +4,113 @@ code_gen_dir=`pwd`
44
project_root=$code_gen_dir/..
55
echo $code_gen_dir
66

7-
commit_hash=b63d67cc0ed7c5a3962e72f21001df4d2ed482f2
7+
commit_hash=64977061b376680aaf09b088877bcaa9c3acc6a8
88
api_spec_base_url=https://raw.githubusercontent.com/symphonyoss/symphony-api-spec/${commit_hash}
99
echo $api_spec_base_url
1010

11-
#local_api_spec_base_url=./local
12-
1311
# This function accepts the following parameters (in order):
1412
# - name of the module we want to generate
1513
# - uri of the file to be used for generation
1614
# - uri of the support file needed for the generation
1715
download_and_generate_files() {
18-
name=$1
19-
file_url=$2
20-
file_name=${file_url##*/}
21-
support_file_url=$3
22-
support_file_name=${support_file_url##*/}
23-
24-
download_files ${file_url} ${file_name} ${support_file_url} ${support_file_name}
25-
generate_files ${name} ${file_name}
26-
cleanup_files ${file_name} ${support_file_name}
16+
name=$1
17+
file_url=$2
18+
file_name=${file_url##*/}
19+
support_file_url=$3
20+
support_file_name=${support_file_url##*/}
21+
22+
download_files "${file_url}" "${file_name}" "${support_file_url}" "${support_file_name}"
23+
generate_files "${name}" "${file_name}"
24+
cleanup_files "${file_name}" "${support_file_name}"
2725
}
2826

2927
download_files() {
30-
# download files
31-
file_url=$1
32-
file_name=$2
33-
support_file_url=$3
34-
support_file_name=$4
35-
36-
cd $code_gen_dir
37-
curl $file_url -o $file_name
38-
if [ ! -z "${support_file_name}" ]
39-
then
40-
curl $support_file_url -o $support_file_name
41-
fi
28+
file_url=$1
29+
file_name=$2
30+
support_file_url=$3
31+
support_file_name=$4
32+
33+
cd "$code_gen_dir"
34+
curl -s "$file_url" -o "$file_name"
35+
if [ -n "$support_file_name" ]; then
36+
curl -s "$support_file_url" -o "$support_file_name"
37+
fi
4238
}
4339

4440
generate_files() {
45-
46-
name=$1
47-
file_name=$2
48-
49-
# generate files
50-
java -jar openapi-generator-cli.jar generate -g python -i $file_name --package-name symphony.bdk.gen -o output
51-
52-
# update api files
53-
cd $code_gen_dir/output/symphony/bdk/gen/api/
54-
sed -i "s/symphony\.bdk\.gen\.model\./symphony\.bdk\.gen\.${name}_model\./g" *.py
55-
sed -i "s/ api\./ ${name}_api\./g" *.py
56-
rm __init__.py # we don't care about __init__.py files
57-
cp *.py $project_root/symphony/bdk/gen/${name}_api
58-
59-
# update model files
60-
cd $code_gen_dir/output/symphony/bdk/gen/model/
61-
sed -i "s/symphony\.bdk\.gen\.model\./symphony\.bdk\.gen\.${name}_model\./g" *.py
62-
sed -i "s/model /${name}_model /g" *.py
63-
rm __init__.py # we don't care about __init__.py files
64-
cp *.py $project_root/symphony/bdk/gen/${name}_model
65-
66-
# update rest.py
67-
cd $code_gen_dir/output/symphony/bdk/gen
68-
cp rest.py $project_root/symphony/bdk/gen/rest.py
69-
70-
cd $code_gen_dir
71-
rm -r output
41+
name=$1
42+
file_name=$2
43+
44+
# Generate files
45+
java -jar openapi-generator-cli.jar generate -g python -i "$file_name" --library asyncio --package-name symphony.bdk.gen -o output
46+
47+
# Define source and destination directories
48+
new_api_dir="$code_gen_dir/output/symphony/bdk/gen/api/"
49+
new_models_dir="$code_gen_dir/output/symphony/bdk/gen/models/"
50+
final_models_dir="$project_root/symphony/bdk/gen/${name}_model/"
51+
final_api_dir="$project_root/symphony/bdk/gen/${name}_api/"
52+
final_main_models_dir="$project_root/symphony/bdk/gen/models/"
53+
54+
# Update and copy API files
55+
echo "Updating and copying API files..."
56+
mkdir -p "$final_api_dir"
57+
cd "$new_api_dir"
58+
sed -i "s/symphony\.bdk\.gen\.models\./symphony\.bdk\.gen\.${name}_model\./g" *.py
59+
sed -i "s/ api\./ ${name}_api\./g" *.py
60+
rm __init__.py
61+
cp *.py "$final_api_dir"
62+
63+
# Update and copy model files
64+
echo "Updating and copying Model files..."
65+
mkdir -p "$final_models_dir"
66+
cd "$new_models_dir"
67+
# Capture the imports from the generated __init__.py before removing it
68+
# Use awk to filter out comments and empty lines and then sed to replace the import path
69+
awk '/^from symphony\.bdk\.gen\.models\./' __init__.py | sed "s/symphony\.bdk\.gen\.models\./symphony\.bdk\.gen\.${name}_model\./" >> "$final_main_models_dir/__init__.py"
70+
sed -i "s/symphony\.bdk\.gen\.models\./symphony\.bdk\.gen\.${name}_model\./g" *.py
71+
rm __init__.py
72+
73+
# Copy the actual model files
74+
cp *.py "$final_models_dir"
75+
76+
# The rest of the files
77+
# Here we have more files generated that are not updated because they require changes(EX. api_client)
78+
cd "$code_gen_dir/output/symphony/bdk/gen"
79+
cp rest.py "$project_root/symphony/bdk/gen/rest.py"
80+
81+
# Clean up
82+
cd "$code_gen_dir"
83+
rm -r output
7284
}
7385

7486
cleanup_files() {
75-
file_name=$1
76-
support_file_name=$2
77-
78-
# remove downloaded files
79-
cd $code_gen_dir
80-
rm -r output
81-
rm $file_name
82-
if [ ! -z "${support_file_name}" ]
83-
then
84-
rm $support_file_name
85-
fi
87+
file_name=$1
88+
support_file_name=$2
89+
90+
# remove downloaded files
91+
cd "$code_gen_dir"
92+
rm "$file_name"
93+
if [ -n "$support_file_name" ]; then
94+
rm "$support_file_name"
95+
fi
8696
}
8797

98+
main() {
99+
# Prepare the target directory for the models
100+
rm -rf "$project_root/symphony/bdk/gen/models"
101+
mkdir -p "$project_root/symphony/bdk/gen/models"
102+
103+
# Add initial header to the main __init__.py
104+
echo "# coding: utf-8" > "$project_root/symphony/bdk/gen/models/__init__.py"
105+
echo "" >> "$project_root/symphony/bdk/gen/models/__init__.py"
106+
echo "# This file is auto-generated by a script. Do not edit manually." >> "$project_root/symphony/bdk/gen/models/__init__.py"
107+
echo "" >> "$project_root/symphony/bdk/gen/models/__init__.py"
108+
109+
download_and_generate_files agent "${api_spec_base_url}/agent/agent-api-public-deprecated.yaml"
110+
download_and_generate_files auth "${api_spec_base_url}/authenticator/authenticator-api-public-deprecated.yaml"
111+
download_and_generate_files login "${api_spec_base_url}/login/login-api-public.yaml"
112+
download_and_generate_files pod "${api_spec_base_url}/pod/pod-api-public.yaml"
113+
download_and_generate_files group "${api_spec_base_url}/profile-manager/profile-manager-api.yaml" "${api_spec_base_url}/profile-manager/symphony-common-definitions.yaml"
114+
}
88115

89-
generate_files agent ${api_spec_base_url}/agent/agent-api-public-deprecated.yaml
90-
generate_files auth ${api_spec_base_url}/authenticator/authenticator-api-public-deprecated.yaml
91-
generate_files login ${api_spec_base_url}/login/login-api-public.yaml
92-
generate_files pod ${api_spec_base_url}/pod/pod-api-public.yaml
93-
generate_files group ${api_spec_base_url}/profile-manager/profile-manager-api.yaml ${api_spec_base_url}/profile-manager/symphony-common-definitions.yaml
94-
95-
#generate_files agent ${local_api_spec_base_url}/agent-api-public-deprecated-formValues-modified.yaml
116+
main
4.87 MB
Binary file not shown.

0 commit comments

Comments
 (0)