diff --git a/apis_core/generic/schema.py b/apis_core/generic/schema.py new file mode 100644 index 000000000..80a6dfa40 --- /dev/null +++ b/apis_core/generic/schema.py @@ -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()