new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

FastAPI · Reference · all subjects

path operations & decorators

10 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

operation_id parameter for path operation decorators

The operation_id parameter allows you to set the OpenAPI operationId to be used in a path operation. You must ensure it is unique for each operation.

include_in_schema parameter for path operation decorators

The include_in_schema parameter allows you to exclude a path operation from the generated OpenAPI schema and automatic documentation systems. Set it to False to exclude the operation.

Docstring truncation with form feed character

Adding a \f character (escaped form feed) in a path operation function's docstring causes FastAPI to truncate the OpenAPI documentation output at that point. The truncated portion will not appear in documentation but may be used by other tools like Sphinx.

openapi_extra parameter for path operation decorators

The openapi_extra parameter allows you to extend the OpenAPI schema for a path operation. The dictionary provided in openapi_extra is merged with the automatically generated OpenAPI schema using deep merge, allowing you to add additional data to the generated schema.

OpenAPI extensions with openapi_extra

The openapi_extra parameter can be used to declare OpenAPI extensions as defined in the OpenAPI specification. Extensions are added to the operation object in the resulting OpenAPI JSON and appear in the automatic API documentation.

Custom OpenAPI schema for path operations

You can declare a custom OpenAPI schema for a path operation's request body by using openapi_extra. This allows you to define the expected schema even when not using FastAPI's automatic Pydantic validation and JSON parsing.

Custom OpenAPI content-type definition

You can use openapi_extra to define custom request content types in OpenAPI that differ from JSON. You can manually generate a JSON schema from a Pydantic model and include it in openapi_extra, then handle the actual request parsing separately with different formats like YAML.

Combining Request parameter with other path operation parameters

You can declare a Request object parameter in a path operation function alongside other parameters. Path parameters will be extracted, validated, converted to the specified type, and annotated with OpenAPI, while also being able to receive the Request object.

Custom APIRoute class to use custom Request

You can create a custom APIRoute subclass by overriding the APIRoute.get_route_handler() method. This method returns a function that receives a Request and returns a Response. The custom APIRoute can be used to instantiate a custom Request class, allowing you to apply custom logic before the request reaches path operations.

Use cases for custom Request and APIRoute classes

Common use cases for custom Request and APIRoute classes include: converting non-JSON request bodies to JSON (such as msgpack), decompressing gzip-compressed request bodies, and automatically logging all request bodies.

Give your agent this brain