Skip to content

Commit

Permalink
add docs
Browse files Browse the repository at this point in the history
  • Loading branch information
khvn26 committed Apr 24, 2024
1 parent e9d5603 commit 415c925
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions api/api/openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,27 @@ def nullable_schema(self, schema: core_schema.NullableSchema) -> JsonSchemaValue


class PydanticResponseCapableSwaggerAutoSchema(SwaggerAutoSchema):
"""
A `SwaggerAutoSchema` subclass that allows to generate view response Swagger docs
from a Pydantic model.
Example usage:
```
@drf_yasg.utils.swagger_auto_schema(
responses={200: YourPydanticSchema},
auto_schema=PydanticResponseCapableSwaggerAutoSchema,
)
def your_view(): ...
```
To adapt Pydantic-generated schemas, the following is taken care of:
1. Pydantic-generated definitions are unwrapped and added to drf-yasg's global definitions.
2. Rather than using `anyOf`, nullable fields are annotated with `x-nullable`.
3. As there's no way to annotate a reference, all nested models are assumed to be `x-nullable`.
"""

def get_response_schemas(
self,
response_serializers: dict[str | int, Any],
Expand Down

0 comments on commit 415c925

Please sign in to comment.