Fix blog OpenAPI agent path parameters
All checks were successful
build / build (push) Successful in 3s

This commit is contained in:
2026-05-27 13:53:35 -03:00
parent 2a0f2fc3fc
commit 74f42338d2

View File

@@ -2,6 +2,7 @@ from __future__ import annotations
import base64
import json
import re
from typing import Any
import httpx
@@ -30,6 +31,41 @@ OPERATIONS = json.loads("{\n \"create_blog_post\": {\n \"description\": \"Cr
ROOT_SECURITY = json.loads("[]")
SECURITY_SCHEMES = json.loads("{\n \"apiKeyAuth\": {\n \"description\": \"Use the configured `BLOG_API_KEY` value.\",\n \"in\": \"header\",\n \"name\": \"x-api-key\",\n \"type\": \"apiKey\"\n },\n \"bearerAuth\": {\n \"description\": \"Use `Authorization: Bearer $BLOG_API_KEY`.\",\n \"scheme\": \"bearer\",\n \"type\": \"http\"\n }\n}")
SECURITY_FIELDS = json.loads("{\n \"apiKeyAuth\": {\n \"field\": \"BLOG_API_KEY\",\n \"kind\": \"apiKey\",\n \"location\": \"header\",\n \"name\": \"x-api-key\"\n },\n \"bearerAuth\": {\n \"field\": \"BLOG_API_KEY\",\n \"kind\": \"http\",\n \"scheme\": \"bearer\"\n }\n}")
PATH_PARAMETER_RE = re.compile(r"{([^}/]+)}")
def _ensure_path_parameters() -> None:
for operation in OPERATIONS.values():
path = str(operation.get("path") or "")
parameters = operation.get("parameters")
if not isinstance(parameters, list):
parameters = []
operation["parameters"] = parameters
seen = {
(param.get("name"), param.get("in"))
for param in parameters
if isinstance(param, dict)
}
insert_at = 0
for name in PATH_PARAMETER_RE.findall(path):
key = (name, "path")
if key in seen:
continue
parameters.insert(
insert_at,
{
"name": name,
"in": "path",
"required": True,
"description": f"Path parameter `{name}`.",
"schema": {"type": "string"},
},
)
insert_at += 1
seen.add(key)
_ensure_path_parameters()
class OperationInput(BaseModel):
@@ -349,6 +385,10 @@ class BlogOpenapiAgent(A2AAgent):
headers[name] = str(value)
elif location == "cookie":
cookies[name] = value
unresolved = PATH_PARAMETER_RE.findall(path)
if unresolved:
missing = ", ".join(sorted(set(unresolved)))
raise ValueError("missing required path parameter(s): " + missing)
if cookies:
headers["cookie"] = "; ".join(f"{key}={value}" for key, value in cookies.items())
auth_headers, auth_query = self._auth_for_operation(ctx, operation)