diff --git a/netbox/core/api/schema.py b/netbox/core/api/schema.py index 0b44a3d52..203d98922 100644 --- a/netbox/core/api/schema.py +++ b/netbox/core/api/schema.py @@ -12,6 +12,7 @@ from drf_spectacular.plumbing import ( build_basic_type, build_media_type_object, build_object_type, + get_doc, is_serializer, ) from drf_spectacular.types import OpenApiTypes @@ -222,3 +223,35 @@ class NetBoxAutoSchema(AutoSchema): if request_body_required: request_body['required'] = request_body_required return request_body + + def get_description(self): + """ + Return a string description for the ViewSet. + """ + + # If a docstring is provided, use it. + if self.view.__doc__: + return self.view.__doc__ + + # Else, generate a description from the class name. + description = self.view.__class__.__name__ + if description.endswith('ViewSet'): + description = description[:-len('ViewSet')] + + description = re.sub(r'(?