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