Skip to content

Commit

Permalink
feat(generic): introduce custom AutoSchema for schema customization
Browse files Browse the repository at this point in the history
  • Loading branch information
b1rger committed Dec 18, 2024
1 parent 7efe6a3 commit 4580a0a
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions apis_core/generic/schema.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from drf_spectacular.openapi import AutoSchema


class GenericAutoSchema(AutoSchema):
"""
Add an option to the default drf_spectacular schema that
allows to set the tags of a route via the model.
"""
def get_tags(self) -> list[str]:
model = getattr(self.view, "model", None)
if hasattr(model, "get_openapi_tags"):
return model.get_openapi_tags()
return super().get_tags()

0 comments on commit 4580a0a

Please sign in to comment.