Skip to content

Commit 0e28f5f

Browse files
authored
Updated code generator to use new version of OpenAPI specification (opensearch-project#721)
* Updated code generator to use new version of OpenAPI specification Signed-off-by: saimedhi <saimedhi@amazon.com> * Updated code generator to use native OpenAPI specification Signed-off-by: saimedhi <saimedhi@amazon.com> --------- Signed-off-by: saimedhi <saimedhi@amazon.com>
1 parent 58e9b1d commit 0e28f5f

File tree

7 files changed

+174
-204
lines changed

7 files changed

+174
-204
lines changed

.github/workflows/update_api.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ jobs:
4444
commit-message: Updated opensearch-py to reflect the latest OpenSearch API spec (${{ steps.date.outputs.date }})
4545
title: Updated opensearch-py to reflect the latest OpenSearch API spec
4646
body: |
47-
Updated [opensearch-py](https://github.com/opensearch-project/opensearch-py) to reflect the latest [OpenSearch API spec](https://github.com/opensearch-project/opensearch-api-specification/blob/main/OpenSearch.openapi.json)
47+
Updated [opensearch-py](https://github.com/opensearch-project/opensearch-py) to reflect the latest [OpenSearch API spec](https://github.com/opensearch-project/opensearch-api-specification/releases/download/main/opensearch-openapi.yaml)
4848
Date: ${{ steps.date.outputs.date }}
4949
branch: automated-api-update
5050
base: main

CHANGELOG.md

+5-4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
1010
### Removed
1111
- Removed support for Python 3.6, 3.7 ([#717](https://github.com/opensearch-project/opensearch-py/pull/717))
1212
### Fixed
13+
- Updated code generator to use native OpenAPI specification ([#721](https://github.com/opensearch-project/opensearch-py/pull/721))
1314
### Updated APIs
1415
### Security
1516
### Dependencies
@@ -18,10 +19,10 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
1819

1920
## [2.5.0]
2021
### Added
21-
- Added pylint `assignment-from-no-return` and `unused-variable` (([#658](https://github.com/opensearch-project/opensearch-py/pull/658))
22-
- Added pylint `unnecessary-dunder-calls` (([#655](https://github.com/opensearch-project/opensearch-py/pull/655))
23-
- Changed to use .pylintrc files in root and any directory with override requirements (([#654](https://github.com/opensearch-project/opensearch-py/pull/654))
24-
- Added pylint `unspecified-encoding` and `missing-function-docstring` and ignored opensearchpy for lints (([#643](https://github.com/opensearch-project/opensearch-py/pull/643)))
22+
- Added pylint `assignment-from-no-return` and `unused-variable` ([#658](https://github.com/opensearch-project/opensearch-py/pull/658))
23+
- Added pylint `unnecessary-dunder-calls` ([#655](https://github.com/opensearch-project/opensearch-py/pull/655))
24+
- Changed to use .pylintrc files in root and any directory with override requirements ([#654](https://github.com/opensearch-project/opensearch-py/pull/654))
25+
- Added pylint `unspecified-encoding` and `missing-function-docstring` and ignored opensearchpy for lints ([#643](https://github.com/opensearch-project/opensearch-py/pull/643))
2526
- Added pylint `line-too-long` and `invalid-name` ([#590](https://github.com/opensearch-project/opensearch-py/pull/590))
2627
- Added pylint `pointless-statement` ([#611](https://github.com/opensearch-project/opensearch-py/pull/611))
2728
- Added a log collection guide ([#579](https://github.com/opensearch-project/opensearch-py/pull/579))

DEVELOPER_GUIDE.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ Open `docs/build/html/index.html` to see results.
125125

126126
## Client Code Generator
127127

128-
OpenSearch publishes an [OpenAPI specification](https://github.com/opensearch-project/opensearch-api-specification/blob/main/OpenSearch.openapi.json) in the [opensearch-api-specification](https://github.com/opensearch-project/opensearch-api-specification) repository, which is used to auto-generate the less interesting parts of the client.
128+
OpenSearch publishes an [OpenAPI specification](https://github.com/opensearch-project/opensearch-api-specification/releases/download/main/opensearch-openapi.yaml) in the [opensearch-api-specification](https://github.com/opensearch-project/opensearch-api-specification) repository, which is used to auto-generate the less interesting parts of the client.
129129

130130
```
131131
nox -rs generate

test_opensearchpy/test_server/__init__.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -31,24 +31,24 @@
3131
from opensearchpy.helpers import test
3232
from opensearchpy.helpers.test import OpenSearchTestCase as BaseTestCase
3333

34-
client: Any = None
34+
CLIENT: Any = None
3535

3636

3737
def get_client(**kwargs: Any) -> Any:
38-
global client
39-
if client is False:
38+
global CLIENT
39+
if CLIENT is False:
4040
raise SkipTest("No client is available")
41-
if client is not None and not kwargs:
42-
return client
41+
if CLIENT is not None and not kwargs:
42+
return CLIENT
4343

4444
try:
4545
new_client = test.get_test_client(**kwargs)
4646
except SkipTest:
47-
client = False
47+
CLIENT = False
4848
raise
4949

5050
if not kwargs:
51-
client = new_client
51+
CLIENT = new_client
5252

5353
return new_client
5454

utils/changelog_updater.py

+42-75
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77
# Modifications Copyright OpenSearch Contributors. See
88
# GitHub history for details.
99

10-
import filecmp
11-
import os
12-
import shutil
10+
import subprocess
1311

1412
import requests
1513

@@ -18,82 +16,51 @@ def main() -> None:
1816
"""
1917
Update CHANGELOG.md when API generator produces new code differing from existing.
2018
"""
21-
root_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
22-
23-
after_paths = [
24-
os.path.join(root_dir, f"opensearchpy/{folder}")
25-
for folder in ["client", "_async/client"]
26-
]
27-
28-
before_paths = [
29-
os.path.join(root_dir, f"before_generate/{folder}")
30-
for folder in ["client", "async_client"]
31-
]
32-
33-
# Compare only .py files and take their union for client and async_client directories
34-
before_files_client = set(
35-
file for file in os.listdir(before_paths[0]) if file.endswith(".py")
36-
)
37-
after_files_client = set(
38-
file for file in os.listdir(after_paths[0]) if file.endswith(".py")
39-
)
40-
41-
before_files_async_client = set(
42-
file for file in os.listdir(before_paths[1]) if file.endswith(".py")
43-
)
44-
after_files_async_client = set(
45-
file for file in os.listdir(after_paths[1]) if file.endswith(".py")
46-
)
47-
48-
all_files_union_client = before_files_client.union(after_files_client)
49-
all_files_union_async_client = before_files_async_client.union(
50-
after_files_async_client
51-
)
19+
git_command = "git status"
20+
try:
21+
git_status = subprocess.check_output(
22+
git_command, shell=True, stderr=subprocess.STDOUT
23+
)
24+
if (
25+
"Changes to be committed:" in git_status.decode()
26+
or "Changes not staged for commit:" in git_status.decode()
27+
or "Untracked files:" in git_status.decode()
28+
):
29+
print("Changes detected; updating changelog.")
5230

53-
# Compare files and check for mismatches or errors for client and async_client directories
54-
mismatch_client, errors_client = filecmp.cmpfiles(
55-
before_paths[0], after_paths[0], all_files_union_client, shallow=True
56-
)[1:]
57-
mismatch_async_client, errors_async_client = filecmp.cmpfiles(
58-
before_paths[1], after_paths[1], all_files_union_async_client, shallow=True
59-
)[1:]
31+
base_url = "https://api.github.com/repos/opensearch-project/opensearch-api-specification/commits"
32+
url_with_per_page = base_url + "?per_page=1"
33+
response = requests.get(url_with_per_page)
34+
if response.ok:
35+
commit_info = response.json()[0]
36+
commit_url = commit_info["html_url"]
37+
latest_commit_sha = commit_info.get("sha")
38+
else:
39+
raise Exception(
40+
f"Failed to fetch opensearch-api-specification commit information. Status code: {response.status_code}"
41+
)
6042

61-
if mismatch_client or errors_client or mismatch_async_client or errors_async_client:
62-
print("Changes detected")
63-
response = requests.get(
64-
"https://api.github.com/repos/opensearch-project/opensearch-api-specification/commits"
65-
)
66-
if response.ok:
67-
commit_info = response.json()[0]
68-
commit_url = commit_info["html_url"]
69-
latest_commit_sha = commit_info.get("sha")
43+
with open("CHANGELOG.md", "r+", encoding="utf-8") as file:
44+
content = file.read()
45+
if commit_url not in content:
46+
if "### Updated APIs" in content:
47+
file_content = content.replace(
48+
"### Updated APIs",
49+
f"### Updated APIs\n- Updated opensearch-py APIs to reflect [opensearch-api-specification@{latest_commit_sha[:7]}]({commit_url})",
50+
1,
51+
)
52+
file.seek(0)
53+
file.write(file_content)
54+
file.truncate()
55+
else:
56+
raise Exception(
57+
"'Updated APIs' section is not present in CHANGELOG.md"
58+
)
7059
else:
71-
raise Exception(
72-
f"Failed to fetch opensearch-api-specification commit information. Status code: {response.status_code}"
73-
)
74-
75-
with open("CHANGELOG.md", "r+", encoding="utf-8") as file:
76-
content = file.read()
77-
if commit_url not in content:
78-
if "### Updated APIs" in content:
79-
file_content = content.replace(
80-
"### Updated APIs",
81-
f"### Updated APIs\n- Updated opensearch-py APIs to reflect [opensearch-api-specification@{latest_commit_sha[:7]}]({commit_url})",
82-
1,
83-
)
84-
file.seek(0)
85-
file.write(file_content)
86-
file.truncate()
87-
else:
88-
raise Exception(
89-
"'Updated APIs' section is not present in CHANGELOG.md"
90-
)
91-
else:
92-
print("No changes detected")
60+
print("No changes detected")
9361

94-
# Clean up
95-
for path in before_paths:
96-
shutil.rmtree(path)
62+
except subprocess.CalledProcessError as e:
63+
print(f"Error occurred while checking Git status: {e}")
9764

9865

9966
if __name__ == "__main__":

0 commit comments

Comments
 (0)