Skip to content

Commit a256ed1

Browse files
author
Joel Collins
committed
Add description to property builder
1 parent fa10acf commit a256ed1

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

examples/builder.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@
44

55
from labthings.server.quick import create_app
66
from labthings.server.view import View
7-
from labthings.server.decorators import ThingProperty, PropertySchema, use_args
7+
from labthings.server.decorators import ThingProperty, PropertySchema, use_args, Doc
88

99
from labthings.server.types import value_to_field, data_dict_to_schema
1010

1111
from components.pdf_component import PdfComponent
1212

1313

14-
def gen_property(property_object, property_name, name: str = None, readonly=False):
14+
def gen_property(
15+
property_object, property_name, name: str = None, readonly=False, description=None
16+
):
1517

1618
# Create a class name
1719
if not name:
@@ -57,6 +59,11 @@ def _put(self, args):
5759
generated_class = PropertySchema(property_schema)(generated_class)
5860
generated_class = ThingProperty(generated_class)
5961

62+
if description:
63+
generated_class = Doc(description=description, summary=description)(
64+
generated_class
65+
)
66+
6067
return generated_class
6168

6269

@@ -74,8 +81,18 @@ def _put(self, args):
7481
labthing.add_component(my_component, "org.labthings.example.mycomponent")
7582

7683
# Add routes for the API views we created
77-
labthing.add_view(gen_property(my_component, "magic_denoise"), "/denoise")
78-
labthing.add_view(gen_property(my_component, "magic_dictionary"), "/dictionary")
84+
labthing.add_view(
85+
gen_property(my_component, "magic_denoise", description="A magic denoise property"),
86+
"/denoise",
87+
)
88+
labthing.add_view(
89+
gen_property(
90+
my_component,
91+
"magic_dictionary",
92+
description="A big dictionary of little properties",
93+
),
94+
"/dictionary",
95+
)
7996

8097
# Start the app
8198
if __name__ == "__main__":

0 commit comments

Comments
 (0)