Skip to content

Commit e6b5704

Browse files
committed
move scripts files
1 parent 858c47b commit e6b5704

3 files changed

Lines changed: 78 additions & 3 deletions

File tree

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ generate: setup-openapi ## Run the code generation script
3434
echo "Updating version in __init__.py to $(VERSION)"
3535
sed -e "s/__version__ = .*/__version__ = \"$(VERSION)\"/g" ./src/mistapi/__init__.py > ./src/mistapi/__init__.py.new
3636
mv ./src/mistapi/__init__.py.new ./src/mistapi/__init__.py
37-
uv run python generate_from_openapi.py $(VERSION)
37+
uv run python ./scripts/generate_from_openapi.py $(VERSION)
3838
$(MAKE) format
3939

4040
init: setup-openapi ## Development setup with OpenAPI
File renamed without changes.
Lines changed: 77 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,19 @@
2020
"boolean": "bool",
2121
}
2222

23+
DEPRECATED_METHODS = {
24+
"getSiteSleSummary": {
25+
"new_operation_id": "getSiteSleSummaryTrend",
26+
"version_deprecated": "0.59.2",
27+
"version_final": "0.65.0",
28+
},
29+
"getSiteSleClassifierDetails": {
30+
"new_operation_id": "getSiteSleClassifierSummaryTrend",
31+
"version_deprecated": "0.59.2",
32+
"version_final": "0.65.0",
33+
},
34+
}
35+
2336
# Template for __init__.py files in generated packages
2437
INIT_TEMPLATE = """'''
2538
--------------------------------------------------------------------------------
@@ -597,6 +610,52 @@ def _create_get_deprecated_device_events(
597610
return code
598611

599612

613+
def _create_get_deprecated(
614+
operation_id: str,
615+
tags: list,
616+
new_operation_id: str,
617+
version_deprecated: str,
618+
version_final: str,
619+
endpoint_path: str,
620+
path_params: list,
621+
query_params: list,
622+
) -> str:
623+
"""
624+
Create deprecated version of GET functions for backward compatibility.
625+
626+
Args:
627+
operation_id: Current OpenAPI operation ID (DeviceEvents*)
628+
endpoint_path: API endpoint path
629+
path_params: Path parameters list
630+
query_params: Query parameters list
631+
632+
Returns:
633+
str: Generated deprecated function code
634+
"""
635+
code = ""
636+
code_path_params, desc_path_params = _gen_code_params(path_params, operation_id)
637+
code_query_params, desc_query_params = _gen_code_params(query_params, operation_id)
638+
code_query = _gen_query_code(query_params)
639+
code_desc = _gen_description(
640+
operation_id, tags, desc_path_params, desc_query_params
641+
)
642+
643+
# Generate old operation ID for the deprecated function
644+
code += FUNCTION_GET_DEPRECATED_TEMPLATE.format(
645+
version_deprecated=version_deprecated,
646+
version_final=version_final,
647+
version_current=version,
648+
operation_id=new_operation_id,
649+
old_operation_id=operation_id,
650+
code_path_params=code_path_params,
651+
code_query_params=code_query_params,
652+
code_desc=code_desc,
653+
uri=_gen_uri(endpoint_path),
654+
query_code=code_query,
655+
)
656+
return code
657+
658+
600659
def _create_get(
601660
operation_id: str,
602661
tags: list,
@@ -619,13 +678,24 @@ def _create_get(
619678
"""
620679
code = ""
621680
has_deprecated = False
622-
623681
# Create deprecated version for DeviceEvents functions (backward compatibility)
624682
if operation_id.startswith("DeviceEvents"):
625683
has_deprecated = True
626684
code += _create_get_deprecated_device_events(
627685
operation_id, endpoint_path, path_params, query_params
628686
)
687+
elif DEPRECATED_METHODS.get(operation_id):
688+
has_deprecated = True
689+
code += _create_get_deprecated(
690+
operation_id,
691+
tags,
692+
DEPRECATED_METHODS[operation_id]["new_operation_id"],
693+
DEPRECATED_METHODS[operation_id]["version_deprecated"],
694+
DEPRECATED_METHODS[operation_id]["version_final"],
695+
endpoint_path,
696+
path_params,
697+
query_params,
698+
)
629699

630700
# Generate main function parameters and documentation
631701
code_path_params, desc_path_params = _gen_code_params(path_params, operation_id)
@@ -1013,7 +1083,9 @@ def _process_endpoint(
10131083
)
10141084

10151085
# Process GET method
1016-
if endpoint_data.get("get") and not endpoint_data.get("get", {}).get("deprecated"):
1086+
if endpoint_data.get(
1087+
"get"
1088+
): # and not endpoint_data.get("get", {}).get("deprecated"):
10171089
query_params = _process_query_params(
10181090
endpoint_data["get"].get("parameters", []), openapi_refs, openapi_schemas
10191091
)
@@ -1112,8 +1184,11 @@ def _is_totally_deprecated(endpoint_data: dict) -> bool:
11121184
"""
11131185
for crud in ["get", "post", "put", "delete"]:
11141186
if endpoint_data.get(crud, {}):
1187+
operation_id = endpoint_data.get(crud, {}).get("operationId")
11151188
if not endpoint_data[crud].get("deprecated"):
11161189
return False
1190+
elif operation_id and DEPRECATED_METHODS.get(operation_id):
1191+
return False
11171192
return True
11181193

11191194

0 commit comments

Comments
 (0)