v9.1.0
Responder 9.1 makes Python return annotations complete HTTP response
contracts, from runtime validation through OpenAPI and generated clients.
Added
- Return annotations are now complete response contracts. Any supported
PydanticTypeAdaptershape — models, dataclasses, typed dictionaries,
collections such aslist[Item], unions, generic pagination models, and
JSON scalars — drives runtime validation and serialization, OpenAPI response
schemas, and generated-client types. Class-based-view method annotations and
Flask-style tuple annotations infer the same way. Inferredstrandbytes
responses document and emittext/plainandapplication/octet-stream;
other inferred contracts useapplication/json. - Handlers may return
bool,int, andfloatJSON scalars directly, in
addition to the existing dictionaries, lists, strings, bytes, models, and
dataclasses. responses={404: ErrorModel}now declares a status-specific response
contract used for runtime validation and OpenAPI, including alternate
success statuses. A response mapping may providemodelalongside a custom
description, headers, examples, or other OpenAPI metadata.
Changed
- Response contracts now validate the final success body after after-request
hooks. A body whose shape or response channel contradicts its declared model
fails closed with500, including a list returned for a single-object model;
response_model=Falsereliably disables inference and validation. - Flask-style return tuples now require exactly
(body, status)or
(body, status, headers), a status integer from 100 through 599, and a
header mapping. Malformed tuples fail clearly instead of being partially
applied or silently ignored. - Routes with unresolved or unsupported return annotations now log a focused
registration warning with theresponse_model=Falseopt-out instead of
silently dropping the inferred contract.
Fixed
- Informational,
204,205, and304responses no longer send a body even
if a handler returned or assigned one. Their inferred OpenAPI success
responses omit content as well;HEADcontinues to validate the
correspondingGETresponse while sending headers only.