Skip to content

Commit 917fad1

Browse files
jfrench9claude
andauthored
feat: enhance API documentation and improve model structure (#26)
## Summary This PR significantly enhances the API documentation and restructures models for better maintainability and clarity across agent selection, backup operations, and graph management functionalities. ## Key Accomplishments ### 📚 Enhanced API Documentation - **Agent Selection**: Comprehensive documentation improvements for auto-select agent functionality with detailed parameter descriptions and usage examples - **Backup Operations**: Enhanced documentation for create backup, restore backup, and backup download URL endpoints with clearer response models - **Graph Management**: Expanded documentation for graph creation and limits functionality, including detailed tier information ### 🏗️ Model Structure Improvements - **New Limit Models**: Introduced granular limit models for better organization: - `backup_limits.py` - Backup-specific limitations - `credit_limits.py` - Credit system constraints - `query_limits.py` - Query execution limits - `rate_limits.py` - API rate limiting parameters - `storage_limits.py` - Storage capacity constraints - `copy_operation_limits.py` - Data copy operation limits - **Response Model Refactoring**: Replaced verbose auto-generated model names with cleaner, more intuitive alternatives: - `backup_download_url_response.py` replaces the lengthy auto-generated equivalent - `graph_limits_response.py` provides clearer structure for limit information ### 🚀 New Features - **Graph Tiers API**: Added `get_available_graph_tiers.py` endpoint for retrieving available graph tier options - **Improved Schema Definitions**: Enhanced custom schema definition models with better type safety and validation ### 🔧 Code Quality Improvements - Standardized model imports and exports in `__init__.py` - Removed redundant code from query execution module - Enhanced type annotations and field descriptions across all models - Improved consistency in naming conventions ## Breaking Changes ⚠️ **Model Import Changes**: - Some auto-generated model classes have been renamed for clarity - Applications importing the old verbose model names will need to update their imports - The model functionality remains the same, only naming has been improved ## Testing Notes - All existing API endpoints maintain backward compatibility for functionality - New limit models provide more granular access to system constraints - Graph tier endpoint returns structured information about available options - Enhanced documentation includes practical usage examples for integration testing ## Infrastructure Considerations - Models are better organized for maintainability and future extensions - The new limit structure provides foundation for more sophisticated resource management - Documentation improvements will reduce integration time for API consumers - Cleaner model names improve code readability and debugging experience --- 🤖 Generated with [Claude Code](https://claude.ai/code) **Branch Info:** - Source: `chore/improve-documentation` - Target: `main` - Type: feature Co-Authored-By: Claude <noreply@anthropic.com>
2 parents 3a2e9f4 + 78130e9 commit 917fad1

28 files changed

Lines changed: 1927 additions & 237 deletions

‎bin/generate-sdk‎

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Generate Python SDK from OpenAPI specification with post-generation patches.
4+
5+
This script handles the complete SDK generation workflow:
6+
1. Generate SDK using openapi-python-client
7+
2. Copy generated files to robosystems_client/
8+
3. Apply post-generation patches (NDJSON handling, etc.)
9+
4. Format and lint the generated code
10+
"""
11+
12+
import sys
13+
import subprocess
14+
import shutil
15+
from pathlib import Path
16+
17+
18+
def run_command(cmd: str, description: str) -> bool:
19+
"""Run a shell command and return success status."""
20+
print(f"📦 {description}...")
21+
result = subprocess.run(cmd, shell=True, cwd=Path(__file__).parent.parent)
22+
return result.returncode == 0
23+
24+
25+
def patch_ndjson_handling() -> bool:
26+
"""Add NDJSON handling to execute_cypher_query._parse_response."""
27+
28+
file_path = (
29+
Path(__file__).parent.parent
30+
/ "robosystems_client"
31+
/ "api"
32+
/ "query"
33+
/ "execute_cypher_query.py"
34+
)
35+
36+
if not file_path.exists():
37+
print(f"❌ File not found: {file_path}")
38+
return False
39+
40+
# Read the current file content
41+
content = file_path.read_text()
42+
43+
# Check if patch is already applied
44+
if "application/x-ndjson" in content:
45+
print("✅ NDJSON patch already applied")
46+
return True
47+
48+
# Define the patch to insert (note: using 4-space indentation to match generated code)
49+
ndjson_check = """ content_type = response.headers.get("content-type", "")
50+
if (
51+
"application/x-ndjson" in content_type
52+
or response.headers.get("x-stream-format") == "ndjson"
53+
):
54+
return None
55+
"""
56+
57+
# Find the location to insert the patch (raw generated code uses 4 spaces)
58+
search_pattern = " if response.status_code == 200:\n response_200 = ExecuteCypherQueryResponse200.from_dict(response.json())\n\n return response_200"
59+
60+
if search_pattern not in content:
61+
print(f"❌ Could not find expected pattern in {file_path}")
62+
print("The generated code structure may have changed.")
63+
return False
64+
65+
# Replace the pattern with the patched version
66+
replacement = f" if response.status_code == 200:\n{ndjson_check} response_200 = ExecuteCypherQueryResponse200.from_dict(response.json())\n\n return response_200"
67+
patched_content = content.replace(search_pattern, replacement)
68+
69+
# Write the patched content back
70+
_ = file_path.write_text(patched_content)
71+
72+
print(f"✅ Applied NDJSON patch to {file_path.name}")
73+
return True
74+
75+
76+
def main():
77+
"""Main SDK generation workflow."""
78+
79+
# Get OpenAPI URL from command line or use default
80+
url = sys.argv[1] if len(sys.argv) > 1 else "http://localhost:8000/openapi.json"
81+
82+
print(f"🚀 Generating Python SDK from {url}...")
83+
print()
84+
85+
# Step 1: Generate SDK
86+
if not run_command("rm -rf generated", "Cleaning previous generation"):
87+
return 1
88+
89+
if not run_command(
90+
f"uv run openapi-python-client generate --url {url} --output-path generated --config robosystems_client/sdk-config.yaml",
91+
f"Generating SDK from {url}",
92+
):
93+
return 1
94+
95+
# Step 2: Copy generated files
96+
print("📦 Copying generated code to robosystems_client/...")
97+
98+
base_path = Path(__file__).parent.parent
99+
generated_path = base_path / "generated" / "robo_systems_api_client"
100+
target_path = base_path / "robosystems_client"
101+
102+
# Remove old generated files
103+
for item in ["api", "models", "client.py", "errors.py", "types.py", "py.typed"]:
104+
item_path = target_path / item
105+
if item_path.exists():
106+
if item_path.is_dir():
107+
shutil.rmtree(item_path)
108+
else:
109+
item_path.unlink()
110+
111+
# Copy new generated files
112+
for item in ["api", "models", "client.py", "errors.py", "types.py", "py.typed"]:
113+
src = generated_path / item
114+
dst = target_path / item
115+
if src.exists():
116+
if src.is_dir():
117+
shutil.copytree(src, dst)
118+
else:
119+
shutil.copy2(src, dst)
120+
121+
# Clean up generated folder
122+
shutil.rmtree(base_path / "generated")
123+
124+
print()
125+
126+
# Step 3: Apply patches
127+
print("🔧 Applying post-generation patches...")
128+
if not patch_ndjson_handling():
129+
print("⚠️ Warning: NDJSON patch failed, but continuing...")
130+
131+
print()
132+
133+
# Step 4: Format and lint
134+
if not run_command("uv run ruff format .", "Formatting code"):
135+
return 1
136+
137+
if not run_command("uv run ruff check . --fix", "Fixing linting issues"):
138+
return 1
139+
140+
if not run_command("uv run ruff check .", "Running final linting check"):
141+
return 1
142+
143+
if not run_command("uv run ruff format --check .", "Verifying formatting"):
144+
return 1
145+
146+
print()
147+
print("✅ SDK generation complete!")
148+
print()
149+
print("Changes applied:")
150+
print(" - Generated fresh SDK from OpenAPI spec")
151+
print(" - Applied NDJSON streaming support patch")
152+
print(" - Formatted and linted all code")
153+
print()
154+
155+
return 0
156+
157+
158+
if __name__ == "__main__":
159+
sys.exit(main())

‎justfile‎

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,22 +45,7 @@ typecheck:
4545

4646
# Generate SDK from localhost API
4747
generate-sdk url="http://localhost:8000/openapi.json":
48-
@echo "🚀 Generating Client from {{url}}..."
49-
rm -rf generated
50-
uv run openapi-python-client generate --url {{url}} --output-path generated --config robosystems_client/sdk-config.yaml
51-
@echo "📦 Copying generated code to robosystems_client..."
52-
rm -rf robosystems_client/api robosystems_client/models robosystems_client/client.py robosystems_client/errors.py robosystems_client/types.py robosystems_client/py.typed
53-
cp -r generated/robo_systems_api_client/api robosystems_client/
54-
cp -r generated/robo_systems_api_client/models robosystems_client/
55-
cp generated/robo_systems_api_client/client.py robosystems_client/
56-
cp generated/robo_systems_api_client/errors.py robosystems_client/
57-
cp generated/robo_systems_api_client/types.py robosystems_client/
58-
cp generated/robo_systems_api_client/py.typed robosystems_client/
59-
rm -rf generated
60-
@just format
61-
uv run ruff check . --fix
62-
@just lint
63-
@echo "✅ Client generation complete!"
48+
bin/generate-sdk {{url}}
6449

6550
# Build python package locally (for testing)
6651
build-package:

0 commit comments

Comments
 (0)