OpenAPI (Swagger) Integration in Panther#
Panther automatically generates an OpenAPI (Swagger) specification for your APIs. This makes it easy to document, test, and share your API endpoints.
How to Enable OpenAPI in Your Project#
To enable OpenAPI documentation, simply add the Panther OpenAPI URL routing to your project's URL configuration:
core/urls.py | |
---|---|
1 2 3 4 5 6 |
|
This will make your OpenAPI documentation available at the /swagger/
endpoint.
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.
model
inOutputSchema
can be either apydantic.BaseModel
or apanther.serializer.ModelSerializer
.status_code
should 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 |
|
If output_schema
is not provided, Panther will attempt to infer the status code and response structure by analyzing your code with ast
. However, for best results and more accurate documentation, it is recommended to always specify output_schema
.
Note: The OpenAPI integration is currently in beta. Contributions, feedback, and ideas are very welcome!