Spaces:
Running
Running
improve remote endpoints documentation
Browse files- src/api_factory.py +12 -5
- src/main.py +7 -4
src/api_factory.py
CHANGED
|
@@ -26,7 +26,7 @@ def get_param_metadata(p):
|
|
| 26 |
|
| 27 |
async def get_remote_params(base_url: str,
|
| 28 |
endpoint: str,
|
| 29 |
-
method: str = 'get'):
|
| 30 |
async with httpx.AsyncClient() as client:
|
| 31 |
headers = {}
|
| 32 |
if TENNIS_ML_API_KEY := os.getenv('TENNIS_ML_API_KEY'):
|
|
@@ -40,10 +40,17 @@ async def get_remote_params(base_url: str,
|
|
| 40 |
method_def = path_def.get(method, {})
|
| 41 |
params = method_def.get("parameters", [])
|
| 42 |
|
| 43 |
-
return
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
|
| 48 |
def openapi_type_to_python(t: str):
|
| 49 |
return {
|
|
|
|
| 26 |
|
| 27 |
async def get_remote_params(base_url: str,
|
| 28 |
endpoint: str,
|
| 29 |
+
method: str = 'get') -> Dict:
|
| 30 |
async with httpx.AsyncClient() as client:
|
| 31 |
headers = {}
|
| 32 |
if TENNIS_ML_API_KEY := os.getenv('TENNIS_ML_API_KEY'):
|
|
|
|
| 40 |
method_def = path_def.get(method, {})
|
| 41 |
params = method_def.get("parameters", [])
|
| 42 |
|
| 43 |
+
return {
|
| 44 |
+
"general": {
|
| 45 |
+
"description": method_def.get("description", ""),
|
| 46 |
+
"summary": method_def.get("summary", ""),
|
| 47 |
+
"tags": method_def.get("tags", []),
|
| 48 |
+
},
|
| 49 |
+
"params": [
|
| 50 |
+
get_param_metadata(p)
|
| 51 |
+
for p in params if p["in"] == "query"
|
| 52 |
+
]
|
| 53 |
+
}
|
| 54 |
|
| 55 |
def openapi_type_to_python(t: str):
|
| 56 |
return {
|
src/main.py
CHANGED
|
@@ -82,18 +82,21 @@ async def lifespan(app: FastAPI) -> AsyncGenerator[None, None]:
|
|
| 82 |
]
|
| 83 |
|
| 84 |
for endpoint in endpoints:
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
forward_endpoint = create_forward_endpoint(base_url=TENNIS_ML_API,
|
| 89 |
_endpoint=endpoint,
|
| 90 |
-
param_defs=
|
| 91 |
|
| 92 |
app.add_api_route(
|
| 93 |
path=f'/{endpoint}',
|
| 94 |
endpoint=forward_endpoint,
|
| 95 |
methods=["GET"],
|
| 96 |
name=f"Forward to remote {forward_endpoint.__name__}",
|
|
|
|
|
|
|
|
|
|
| 97 |
)
|
| 98 |
|
| 99 |
yield
|
|
|
|
| 82 |
]
|
| 83 |
|
| 84 |
for endpoint in endpoints:
|
| 85 |
+
endpoint_def = await get_remote_params(base_url=TENNIS_ML_API,
|
| 86 |
+
endpoint=endpoint,
|
| 87 |
+
method='get')
|
| 88 |
forward_endpoint = create_forward_endpoint(base_url=TENNIS_ML_API,
|
| 89 |
_endpoint=endpoint,
|
| 90 |
+
param_defs=endpoint_def["params"])
|
| 91 |
|
| 92 |
app.add_api_route(
|
| 93 |
path=f'/{endpoint}',
|
| 94 |
endpoint=forward_endpoint,
|
| 95 |
methods=["GET"],
|
| 96 |
name=f"Forward to remote {forward_endpoint.__name__}",
|
| 97 |
+
tags=endpoint_def["general"]["tags"],
|
| 98 |
+
description=endpoint_def["general"]["description"],
|
| 99 |
+
summary=endpoint_def["general"]["summary"],
|
| 100 |
)
|
| 101 |
|
| 102 |
yield
|