### GitHub Actions Workflow for Dolphin API Type Generation Source: https://context7.com/tonycash13/dolphin-anty-integration/llms.txt A GitHub Actions workflow file (`.github/workflows/generate-types.yml`) that automates the process of generating Dolphin API types on push or schedule events. It checks out code, sets up Python and Node.js, installs dependencies, runs the type generation script, and checks for git diffs. ```yaml name: Generate API Typeson: [push, schedule] jobs: generate: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - uses: actions/setup-python@v4 with: python-version: '3.10' - uses: actions/setup-node@v3 - run: pip install -r requirements-dev.txt - run: python3 generate_dolphin_types.py - run: git diff --exit-code || echo "Types updated" ``` -------------------------------- ### GET /proxy Source: https://context7.com/tonycash13/dolphin-anty-integration/llms.txt Lists proxies with optional pagination and filtering. ```APIDOC ## GET /proxy ### Description Retrieves a list of proxies, supporting pagination and filtering via a query parameter. ### Method GET ### Endpoint `/proxy` ### Parameters #### Path Parameters None #### Query Parameters - **limit** (int) - Optional - The maximum number of proxies to return (default is 50). - **query** (str) - Optional - A string to filter proxies by name or other attributes. ### Request Example ``` GET /proxy?limit=20&query=my_proxy ``` ### Response #### Success Response (200) - **data** (array) - A list of proxy objects. - Each object contains details like `id`, `type`, `host`, `port`, `login`, `password`, `name`, and `browser_profiles_count`. - **total** (int) - The total number of proxies matching the query. - **limit** (int) - The limit applied to the returned list. #### Response Example ```json { "status": "success", "data": [ { "id": 123, "type": "http", "host": "proxy.example.com", "port": 8080, "login": "username", "password": "secret", "name": "My Primary Proxy", "browser_profiles_count": 2 }, { "id": 124, "type": "socks5", "host": "socks.example.net", "port": 1080, "login": null, "password": null, "name": "Secondary SOCKS Proxy", "browser_profiles_count": 0 } ], "total": 10, "limit": 20 } ``` ``` -------------------------------- ### Manage Dolphin Anty Proxies using Python API Source: https://context7.com/tonycash13/dolphin-anty-integration/llms.txt This snippet shows how to list and filter proxies using the Dolphin Anty API. It includes examples of fetching proxy data, printing found proxies, and deleting a previously created proxy. Assumes an initialized 'api' object and a 'created' variable holding proxy details. ```python proxies = api.list_proxies(limit=100, query="Primary") if proxies and proxies.get("data"): print(f"Found {len(proxies['data'])} proxies") for p in proxies["data"]: print(f" - {p['name']} ({p['host']})") # Delete proxy if created: success = api.delete_proxy(created["id"]) print(f"Deleted: {success}") ``` -------------------------------- ### Interactive API Playground Source: https://context7.com/tonycash13/dolphin-anty-integration/llms.txt Provides an interactive CLI for exploring Dolphin Anty API endpoints, generating request code snippets with proper payload structures, and saving executable Python scripts to the `generated/` directory. ```APIDOC ## Interactive API Playground ### Description Provides an interactive CLI for exploring Dolphin Anty API endpoints, generating request code snippets with proper payload structures, and saving executable Python scripts to the `generated/` directory. ### Method Not applicable (CLI interaction or programmatic use) ### Endpoint Not applicable (dynamically determined) ### Parameters None (interactive prompts or programmatic configuration) ### Request Example ```python # Run interactively # $ python playground.py # Or use programmatically from playground import build_python_snippet, save_snippet, example_value_for_schema # Assuming fetch_openapi_yaml() is defined elsewhere and returns OpenAPI spec # openapi = fetch_openapi_yaml()[1] # Generate code snippet for POST /proxy endpoint # snippet = build_python_snippet( # base_url="https://dolphin-anty-api.com", # path_template="/proxy", # method="POST", # openapi=openapi # ) # print(snippet) # Save to file # filepath = save_snippet(snippet, "POST", "/proxy") # print(f"Saved to: {filepath}") # generated/post_proxy.py ``` ### Response #### Success Response (200) Prints the generated Python code snippet and the file path where it was saved. #### Response Example ```python import requests payload = { "type": "", "host": "", "port": 0, "login": "", "password": "", "name": "", "changeIpUrl": "", "provider": "" } resp = requests.post( "https://dolphin-anty-api.com/proxy", json=payload, headers={ "Authorization": "Bearer ", "Content-Type": "application/json" } ) print(resp.status_code) print(resp.text) # Saved to: generated/post_proxy.py ``` ``` -------------------------------- ### Full Type Generation Workflow Source: https://context7.com/tonycash13/dolphin-anty-integration/llms.txt Orchestrates the complete type generation process: fetches OpenAPI spec, generates both TypeScript and Python type definitions, saves output files, and optionally stages changes to git. ```APIDOC ## Full Type Generation Workflow ### Description Orchestrates the complete type generation process: fetches OpenAPI spec, generates both TypeScript and Python type definitions, saves output files, and optionally stages changes to git. ### Method Not applicable (script execution) ### Endpoint Not applicable (script execution) ### Parameters None ### Request Example ```python from generate_dolphin_types import generate_all import subprocess # Run complete generation workflow try: generate_all() print("✅ Type generation complete") print("Generated files:") print(" - src/types/dolphin_api.ts (TypeScript)") print(" - src/types/dolphin_models.py (Python TypedDict)") except Exception as e: print(f"❌ Generation failed: {e}") exit(1) ``` ### Response #### Success Response (200) Prints confirmation messages for generated files. #### Response Example ``` ✅ Type generation complete Generated files: - src/types/dolphin_api.ts (TypeScript) - src/types/dolphin_models.py (Python TypedDict) ``` ``` -------------------------------- ### Interactive API Playground (Python) Source: https://context7.com/tonycash13/dolphin-anty-integration/llms.txt Provides an interactive command-line interface (CLI) for exploring Dolphin Anty API endpoints. It generates request code snippets with proper payload structures and saves executable Python scripts to the 'generated/' directory. This script uses the 'playground' module and requires fetching OpenAPI specifications. ```python # Run interactively # $ python playground.py # 📌 Dolphin Anty Playground # Базовый URL (по умолчанию https://dolphin-anty-api.com): # Путь эндпоинта (например /browser_profiles): /proxy # Доступные методы для /proxy: GET, POST # Выберите метод [GET]: POST # ✅ Код сохранён в: generated/post_proxy.py # Or use programmatically from playground import build_python_snippet, save_snippet, example_value_for_schema openapi = fetch_openapi_yaml()[1] # Generate code snippet for POST /proxy endpoint snippet = build_python_snippet( base_url="https://dolphin-anty-api.com", path_template="/proxy", method="POST", openapi=openapi ) print(snippet) # Output: # import requests # # payload = { # "type": "", # "host": "", # "port": 0, # "login": "", # "password": "", # "name": "", # "changeIpUrl": "", # "provider": "" # } # # resp = requests.post( # "https://dolphin-anty-api.com/proxy", # json=payload, # headers={ # "Authorization": "Bearer ", # "Content-Type": "application/json" # } # ) # # print(resp.status_code) # print(resp.text) # Save to file filepath = save_snippet(snippet, "POST", "/proxy") print(f"Saved to: {filepath}") # generated/post_proxy.py ``` -------------------------------- ### POST /proxy Source: https://context7.com/tonycash13/dolphin-anty-integration/llms.txt Creates a new proxy with a type-safe payload, ensuring proper data structure and type checking. ```APIDOC ## POST /proxy ### Description Creates a new proxy. This operation uses type-safe payloads, ensuring data integrity and providing autocompletion in IDEs. ### Method POST ### Endpoint `/proxy` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **type** (str) - Required - The type of the proxy (e.g., 'http', 'socks4', 'socks5'). - **host** (str) - Required - The hostname or IP address of the proxy server. - **port** (int) - Required - The port number of the proxy server. - **login** (str) - Optional - The username for proxy authentication. - **password** (str) - Optional - The password for proxy authentication. - **name** (str) - Optional - A descriptive name for the proxy. - **changeIpUrl** (str) - Optional - URL to trigger an IP change (if supported by the provider). - **provider** (str) - Optional - The provider of the proxy service. ### Request Example ```json { "type": "http", "host": "proxy.example.com", "port": 8080, "login": "username", "password": "secret", "name": "My New Proxy" } ``` ### Response #### Success Response (200) - **data** (object) - Contains the details of the created proxy. - **id** (int) - The unique identifier of the created proxy. - **type** (str) - The type of the proxy. - **host** (str) - The host of the proxy. - **port** (int) - The port of the proxy. - **login** (str) - The login for the proxy. - **password** (str) - The password for the proxy. - **name** (str) - The name of the proxy. - **browser_profiles_count** (int) - The number of browser profiles currently using this proxy. #### Response Example ```json { "status": "success", "data": { "id": 123, "type": "http", "host": "proxy.example.com", "port": 8080, "login": "username", "password": "secret", "name": "My New Proxy", "browser_profiles_count": 0 } } ``` ``` -------------------------------- ### Full Type Generation Workflow (Python) Source: https://context7.com/tonycash13/dolphin-anty-integration/llms.txt Orchestrates the complete type generation process. It fetches the OpenAPI specification, generates TypeScript and Python type definitions, saves the output files, and optionally stages changes to git. Requires the 'generate_dolphin_types' module. ```python from generate_dolphin_types import generate_all import subprocess # Run complete generation workflow try: generate_all() print("✅ Type generation complete") print("Generated files:") print(" - src/types/dolphin_api.ts (TypeScript)") print(" - src/types/dolphin_models.py (Python TypedDict)") except Exception as e: print(f"❌ Generation failed: {e}") exit(1) # Use generated types in your code from src.types.dolphin_models import proxy_create, BrowserProfileCreateRequest import requests # Create type-safe proxy configuration proxy: proxy_create = { "type": "http", "host": "proxy.example.com", "port": 8080, "login": "username", "password": "secret" } # Make API request with typed payload response = requests.post( "https://dolphin-anty-api.com/proxy", json=proxy, headers={"Authorization": "Bearer YOUR_TOKEN"} ) print(f"Status: {response.status_code}") print(f"Proxy ID: {response.json()['data']['id']}") ``` -------------------------------- ### Type-Safe API Client Usage (Python) Source: https://context7.com/tonycash13/dolphin-anty-integration/llms.txt Demonstrates end-to-end usage of generated types for making type-safe API requests with proper IDE support and compile-time type checking. This class simplifies interactions with the Dolphin Anty API, providing methods for creating, listing, and deleting proxies. It relies on the generated type definitions from 'src.types.dolphin_models'. ```python from src.types.dolphin_models import ( proxy_create, proxy, proxy_list, browser_profile_status, SuccessResponse ) import requests from typing import Optional class DolphinAPI: def __init__(self, api_token: str, base_url: str = "https://dolphin-anty-api.com"): self.base_url = base_url self.headers = { "Authorization": f"Bearer {api_token}", "Content-Type": "application/json" } def create_proxy(self, proxy_data: proxy_create) -> Optional[proxy]: """Create a new proxy with type-safe payload""" response = requests.post( f"{self.base_url}/proxy", json=proxy_data, headers=self.headers ) if response.status_code == 200: return response.json()["data"] return None def list_proxies(self, limit: int = 50, query: str = "") -> Optional[proxy_list]: """List proxies with pagination""" params = {"limit": limit} if query: params["query"] = query response = requests.get( f"{self.base_url}/proxy", params=params, headers=self.headers ) if response.status_code == 200: return response.json() return None def delete_proxy(self, proxy_id: int) -> bool: """Delete proxy by ID""" response = requests.delete( f"{self.base_url}/proxy/{proxy_id}", headers=self.headers ) return response.status_code == 200 # Usage with full type safety api = DolphinAPI("your_api_token_here") # Create proxy with IDE autocompletion new_proxy: proxy_create = { "type": "http", "host": "195.123.45.67", "port": 8080, "login": "proxyuser", "password": "proxypass", "name": "My Primary Proxy" } created = api.create_proxy(new_proxy) if created: print(f"✅ Created proxy ID: {created['id']}") print(f" Host: {created['host']}:{created['port']}") print(f" Profiles using: {created.get('browser_profiles_count', 0)}") ``` -------------------------------- ### Automated Dolphin API Type Generation for CI/CD (Python) Source: https://context7.com/tonycash13/dolphin-anty-integration/llms.txt Python script designed to be used as a CI/CD hook or pre-commit hook to automatically generate Dolphin API types. It runs the type generation script, checks for generated file existence, and reports any changes using git diff. Requires Python 3 and git. ```python #!/usr/bin/env python3 """ CI/CD hook for automated type generation Run this in .github/workflows or as a pre-commit hook """ import sys import subprocess from pathlib import Path def ci_generate_types(): """Generate types and check for changes""" print("🔄 Running type generation...") try: # Run generator result = subprocess.run( ["python3", "generate_dolphin_types.py"], capture_output=True, text=True, timeout=120 ) if result.returncode != 0: print("❌ Type generation failed:") print(result.stderr) return False print(result.stdout) # Check if generated files exist ts_file = Path("src/types/dolphin_api.ts") py_file = Path("src/types/dolphin_models.py") if not ts_file.exists() or not py_file.exists(): print("❌ Generated files not found") return False # Check git diff diff_result = subprocess.run( ["git", "diff", "--name-only", str(ts_file), str(py_file)], capture_output=True, text=True ) if diff_result.stdout.strip(): print("⚠️ Type definitions have changed:") print(diff_result.stdout) print("📝 Run 'git add src/types/*' to commit changes") else: print("✅ Type definitions are up to date") return True except subprocess.TimeoutExpired: print("❌ Type generation timed out") return False except Exception as e: print(f"❌ Unexpected error: {e}") return False if __name__ == "__main__": success = ci_generate_types() sys.exit(0 if success else 1) ``` -------------------------------- ### Fetch Dolphin Anty OpenAPI Specification (Python) Source: https://context7.com/tonycash13/dolphin-anty-integration/llms.txt Downloads and parses the Dolphin Anty OpenAPI specification from the official CDN. It validates the response and returns the raw YAML text and parsed dictionary structure. This is the first step in generating type definitions. ```python from generate_dolphin_types import fetch_openapi_yaml # Fetch OpenAPI specification from Dolphin Anty CDN yaml_text, openapi_dict = fetch_openapi_yaml() if openapi_dict is None: print("Failed to fetch OpenAPI spec") exit(1) # Access API metadata print(f"API Title: {openapi_dict['info']['title']}") print(f"API Version: {openapi_dict['info']['version']}") print(f"Base URL: {openapi_dict['servers'][0]['url']}") # List available endpoints for path, methods in openapi_dict['paths'].items(): print(f"Endpoint: {path} - Methods: {list(methods.keys())}") ``` -------------------------------- ### OpenAPI Schema Utilities for Python Type Generation Source: https://context7.com/tonycash13/dolphin-anty-integration/llms.txt Provides helper functions for sanitizing names, converting OpenAPI schema types to Python type hints, and merging schemas. Useful for generating Python code from OpenAPI specifications. Dependencies include 'generate_dolphin_types' module. ```python from generate_dolphin_types import sanitize_name, openapi_type_to_py, merge_schemas # Sanitize invalid Python identifiers print(sanitize_name("proxy-config")) # proxy_config print(sanitize_name("2fa-settings")) # N_2fa_settings print(sanitize_name("browser@profile")) # browser_profile # Convert OpenAPI types to Python type hints array_schema = { "type": "array", "items": {"type": "string"} } print(openapi_type_to_py(array_schema)) # List[str] object_schema = { "type": "object", "properties": { "name": {"type": "string"}, "port": {"type": "integer"} } } print(openapi_type_to_py(object_schema)) # Dict[str, Any] union_schema = { "oneOf": [ {"type": "string"}, {"type": "integer"} ] } print(openapi_type_to_py(union_schema)) # Union[str, int] # Merge schemas (for allOf handling) schema_a = { "type": "object", "properties": {"id": {"type": "integer"}}, "required": ["id"] } schema_b = { "type": "object", "properties": {"name": {"type": "string"}}, "required": ["name"] } merged = merge_schemas(schema_a, schema_b) print(merged["properties"]) # {'id': {...}, 'name': {...}} print(merged["required"]) # ['id', 'name'] ``` -------------------------------- ### Resolve OpenAPI Schema References (Python) Source: https://context7.com/tonycash13/dolphin-anty-integration/llms.txt Recursively resolves OpenAPI `$ref` references, merges `allOf` schemas, and handles `oneOf`/`anyOf` unions to produce fully dereferenced schema objects. This function is crucial for correctly interpreting complex OpenAPI definitions with internal links. ```python from generate_dolphin_types import dereference_schema, resolve_ref # Example OpenAPI spec with references openapi = { "components": { "schemas": { "ProxyBase": { "type": "object", "properties": { "host": {"type": "string"}, "port": {"type": "integer"} } }, "ProxyWithAuth": { "allOf": [ {"$ref": "#/components/schemas/ProxyBase"}, { "type": "object", "properties": { "login": {"type": "string"}, "password": {"type": "string"} } } ] } } } } # Resolve a specific reference proxy_base = resolve_ref("#/components/schemas/ProxyBase", openapi) print(proxy_base) # {'type': 'object', 'properties': {...}} # Dereference complex schema with allOf proxy_schema = dereference_schema( openapi["components"]["schemas"]["ProxyWithAuth"], openapi ) print(proxy_schema["properties"]) # Output: {'host': {...}, 'port': {...}, 'login': {...}, 'password': {...}} ``` -------------------------------- ### Generate Python TypedDict from OpenAPI Schema (Python) Source: https://context7.com/tonycash13/dolphin-anty-integration/llms.txt Converts OpenAPI schemas into Python TypedDict classes, providing proper type annotations. It handles optional fields, nested objects, arrays, unions, and incorporates schema descriptions as docstrings for generated fields. ```python from generate_dolphin_types import generate_typedicts openapi = { "components": { "schemas": { "proxy_create": { "type": "object", "description": "Parameters required to create a proxy", "properties": { "type": { "type": "string", "description": "Proxy protocol type" }, "host": {"type": "string"}, "port": {"type": "integer"}, "login": {"type": "string"} }, "required": ["type", "host", "port"] } } } } # Generate Python TypedDict code python_code = generate_typedicts(openapi) print(python_code) # Output: # """ # Автогенерируемые TypedDict типы для Dolphin Anty API # """ # from typing import TypedDict, Optional, List, Dict, Any, Union # # class proxy_create(TypedDict, total=False): # """Parameters required to create a proxy""" # type: str # Proxy protocol type # host: str # port: int ``` -------------------------------- ### DELETE /proxy/{proxy_id} Source: https://context7.com/tonycash13/dolphin-anty-integration/llms.txt Deletes a specific proxy by its unique identifier. ```APIDOC ## DELETE /proxy/{proxy_id} ### Description Deletes a proxy identified by its unique ID. This action is irreversible. ### Method DELETE ### Endpoint `/proxy/{proxy_id}` ### Parameters #### Path Parameters - **proxy_id** (int) - Required - The unique identifier of the proxy to delete. #### Query Parameters None #### Request Body None ### Request Example ``` DELETE /proxy/123 ``` ### Response #### Success Response (200) - **status** (str) - Indicates the success of the operation (e.g., 'success'). #### Response Example ```json { "status": "success" } ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.