1from typing import Any
2
3
4def json_content(schema: dict[str, Any]) -> dict[str, Any]:
5 """Wrap a schema in OpenAPI's `application/json` content envelope."""
6 return {"application/json": {"schema": schema}}
7
8
9def json_body(schema: dict[str, Any], *, required: bool = True) -> dict[str, Any]:
10 """Build an `application/json` requestBody for the given schema."""
11 return {"required": required, "content": json_content(schema)}
12
13
14def link_to(
15 view_class: type, *, parameters: dict[str, str], method: str = "get"
16) -> dict[str, Any]:
17 """Build an OpenAPI link to another view's operation.
18
19 Targets the framework-default operationId — `{ViewClass}_{method}`. Pass
20 parameter expressions as values, e.g. `{"id": "$response.body#/id"}`.
21 """
22 return {
23 "operationId": f"{view_class.__name__}_{method}",
24 "parameters": parameters,
25 }