Skip to content

Commit 6b41db8

Browse files
author
Joel Collins
committed
Made class-tags non-removable by default
1 parent c9d693c commit 6b41db8

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/labthings/server/spec/apispec.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def view_to_apispec_operations(view, apispec: APISpec):
4848
"description": getattr(view, "description", None)
4949
or get_docstring(view),
5050
"summary": getattr(view, "summary", None) or get_summary(view),
51-
"tags": view.tags,
51+
"tags": list(view.get_tags()),
5252
}
5353

5454
# Add arguments schema

src/labthings/server/view/__init__.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ class View(MethodView):
4141
schema: Schema = None
4242
args: dict = None
4343
semtype: str = None
44-
tags: list = []
44+
tags: list = [] # Custom tags the user can add
45+
_cls_tags = set() # Class tags that shouldn't be removed
4546
title: None
4647

4748
responses: dict = {}
@@ -67,6 +68,10 @@ def get_schema(cls):
6768
def get_args(cls):
6869
return cls.args
6970

71+
@classmethod
72+
def get_tags(cls):
73+
return cls._cls_tags.union(set(cls.tags))
74+
7075
def get_value(self):
7176
get_method = getattr(self, "get", None) # Look for this views GET method
7277
if get_method is None:
@@ -121,7 +126,7 @@ def represent_response(self, response):
121126

122127

123128
class ActionView(View):
124-
tags: list = ["actions"]
129+
_cls_tags = {"actions"}
125130
safe: bool = False
126131
idempotent: bool = False
127132

@@ -177,7 +182,7 @@ def dispatch_request(self, *args, **kwargs):
177182

178183

179184
class PropertyView(View):
180-
tags: list = ["properties"]
185+
_cls_tags = {"properties"}
181186

182187
@classmethod
183188
def get_args(cls):

0 commit comments

Comments
 (0)