OpenAPI Integration in Panther#
Panther automatically generates an OpenAPI specification for your APIs. This makes it easy to document, test, and share your API endpoints.
How to Enable OpenAPI in Your Project#
Panther provides multiple OpenAPI UI options that you can import directly into your project. You don't need to add the bundled openapi.urls.url_routing - instead, you can choose the specific UI component you prefer.
Available OpenAPI UI Components#
Panther offers several OpenAPI UI options available in panther.openapi.views:
ScalarOpenAPI- Modern, customizable API documentation UISwaggerOpenAPI- Classic Swagger UI interfaceRedocOpenAPI- Clean, responsive documentation interfaceRapiDocOpenAPI- Fast, lightweight API documentationSpotlightOpenAPI- Stoplight Elements integration
Adding OpenAPI to Your Project#
You can import and use any of these UI components directly in your URL configuration:
| urls.py | |
|---|---|
1 2 3 4 5 6 7 8  |  | 
Alternative: Using All UI Components#
If you want to include all OpenAPI UI options at once, you can still use the bundled routing:
| urls.py | |
|---|---|
1 2 3 4 5 6  |  | 
This will make the following endpoints available:
/docs/scalar/- Scalar UI/docs/swagger/- Swagger UI/docs/redoc/- ReDoc UI/docs/rapidoc/- RapiDoc UI/docs/spotlight/- Spotlight UI
How Panther Determines Response Models and Status Codes#
Panther follows a specific logic to generate the OpenAPI YAML for your APIs:
output_schema: Panther first looks for anoutput_schemaattribute to generate the OpenAPI documentation. This is the recommended and most accurate way to specify your response model and status code.output_model: Ifoutput_schemadoes not exist, Panther looks for anoutput_modelattribute to generate the response type. It will also attempt to extract the status code from your source code.- Source Code Analysis: If neither 
output_schemanoroutput_modelis available, Panther tries to extract the response data and status code directly from your source code using static analysis withast. 
For best results and more accurate documentation, always specify output_schema in your APIs.
How Panther Generates OpenAPI Docs#
Panther inspects your API views for an output_schema attribute. This attribute should be an instance of panther.openapi.OutputSchema, which describes the response model and status code for your endpoint.
modelinOutputSchemacan be either apydantic.BaseModelor apanther.serializer.ModelSerializer.status_codeshould be an integer (e.g.,status.HTTP_200_OK).
Example#
1 2 3 4 5 6 7 8 9 10 11 12  |  | 
1 2 3 4 5 6 7 8 9 10 11 12  |  | 
Note: The OpenAPI integration is currently in beta. Contributions, feedback, and ideas are very welcome!