OpenApi
The OpenAPI documentation is automatically set up when you create a Nexios app. The documentation is available at:
/openapi.json
- The OpenAPI specification in JSON format/docs
- Interactive Swagger UI documentation
Documenting Routes
When you define routes using the standard decorators (@app.get
, @app.post
, etc.), the OpenAPI documentation is automatically generated based on the route parameters you provide.
Example Route with Documentation
Route Documentation Parameters
All route decorators (get
, post
, put
, etc.) accept the following documentation parameters:
summary
: Short summary of the endpointdescription
: Detailed description of the endpointrequest_model
: Pydantic model for the request bodyresponses
: Dictionary mapping status codes to response models or descriptionstags
: List of tags for grouping endpointssecurity
: Security requirements for the endpointoperation_id
: Unique identifier for the operationdeprecated
: Mark endpoint as deprecated (True/False)parameters
: List ofParameter
objects for path/query parametersexclude_from_schema
: Exclude endpoint from OpenAPI docs (True/False)
Path Parameters
Path parameters are automatically detected from your route path and documented. For example:
Query Parameters
For query parameters, you can define them using the parameters
argument:
Security Schemes
The default configuration includes a bearer token security scheme. You can add additional security schemes using:
Then reference it in your route:
Customizing OpenAPI Config
You can customize the OpenAPI configuration when creating your app:
Excluding Routes from Documentation
To exclude a route from the OpenAPI documentation:
Viewing Documentation
After setting up your routes, you can view the documentation at:
Swagger UI:
http://localhost:8000/docs
OpenAPI JSON:
http://localhost:8000/openapi.json
Last updated