Module adcp.compat.legacy.v2_5.list_creative_formats
v2.5 → v3 adapter for list_creative_formats.
- Request shape: identical between v2.5 and v3 — adapter passes the payload through unchanged.
- Response shape: v2.5 emits top-level
width/height/dimensionson each format object. v3 moves these into arenders[]array of{render_id, role, dimensions}entries so a single format can declare multiple renders (companion ads, adaptive, device variants).normalize_response()walks eachresponse.formats[].and rewrites the v2.5 top-level shape into the v3 renders array when no renders are present.
Direct port of src/lib/utils/format-renders.ts /
src/lib/adapters/legacy/v2-5/list_creative_formats.ts.
Functions
def normalize_response(response: dict[str, Any] | list[Any]) ‑> dict[str, typing.Any]-
Expand source code
def normalize_response(response: dict[str, Any] | list[Any]) -> dict[str, Any]: """Normalize a v2.5 ``list_creative_formats`` response into v3 shape.""" # Some agents omit the ``{formats: [...]}`` wrapper; tolerate that # by treating a top-level array as the formats list. if isinstance(response, list): return {"formats": [_normalize_format_renders(f) for f in response]} formats = response.get("formats") if not isinstance(formats, list): return response return { **response, "formats": [_normalize_format_renders(f) for f in formats], }Normalize a v2.5
list_creative_formatsresponse into v3 shape.