|
1 | 1 | import datetime |
2 | 2 | from collections import OrderedDict |
3 | | -from typing import Dict, List, Optional, Set |
| 3 | +from typing import Union, Dict, List, Optional, Set |
4 | 4 |
|
5 | 5 | from flask import request |
6 | 6 | from flask.views import MethodView |
|
12 | 12 | from ..marshalling import marshal_with, use_args |
13 | 13 | from ..representations import DEFAULT_REPRESENTATIONS |
14 | 14 | from ..schema import ActionSchema, EventSchema, Schema, build_action_schema |
| 15 | +from ..fields import Field |
15 | 16 | from ..utilities import unpack |
16 | 17 | from . import builder, op |
17 | 18 |
|
18 | 19 | __all__ = ["MethodView", "View", "ActionView", "PropertyView", "op", "builder"] |
19 | 20 |
|
| 21 | +# Type alias for convenience |
| 22 | +OptionalSchema = Optional[Union[Schema, Dict[str, Field]]] |
| 23 | + |
20 | 24 |
|
21 | 25 | class View(MethodView): |
22 | 26 | """A LabThing Resource class should make use of functions |
@@ -108,8 +112,8 @@ class ActionView(View): |
108 | 112 | """ """ |
109 | 113 |
|
110 | 114 | # Data formatting |
111 | | - schema: Optional[Schema] = None # Schema for Action response |
112 | | - args: Optional[dict] = None # Schema for input arguments |
| 115 | + schema: OptionalSchema = None # Schema for Action response |
| 116 | + args: OptionalSchema = None # Schema for input arguments |
113 | 117 | semtype: Optional[str] = None # Semantic type string |
114 | 118 |
|
115 | 119 | # Spec overrides |
@@ -205,7 +209,7 @@ class PropertyView(View): |
205 | 209 | """ """ |
206 | 210 |
|
207 | 211 | # Data formatting |
208 | | - schema: Optional[Schema] = None # Schema for input AND output |
| 212 | + schema: OptionalSchema = None # Schema for input AND output |
209 | 213 | semtype: Optional[str] = None # Semantic type string |
210 | 214 |
|
211 | 215 | # Spec overrides |
@@ -245,7 +249,7 @@ class EventView(View): |
245 | 249 | """ """ |
246 | 250 |
|
247 | 251 | # Data formatting |
248 | | - schema: Optional[Schema] = None # Schema for Event data |
| 252 | + schema: OptionalSchema = None # Schema for Event data |
249 | 253 | semtype: Optional[str] = None # Semantic type string |
250 | 254 |
|
251 | 255 | # Spec overrides |
|
0 commit comments