diff --git a/examples/builder.py b/examples/builder.py index b97aa403..dda0ef9c 100644 --- a/examples/builder.py +++ b/examples/builder.py @@ -4,14 +4,16 @@ from labthings.server.quick import create_app from labthings.server.view import View -from labthings.server.decorators import ThingProperty, PropertySchema, use_args +from labthings.server.decorators import ThingProperty, PropertySchema, use_args, Doc from labthings.server.types import value_to_field, data_dict_to_schema from components.pdf_component import PdfComponent -def gen_property(property_object, property_name, name: str = None, readonly=False): +def gen_property( + property_object, property_name, name: str = None, readonly=False, description=None +): # Create a class name if not name: @@ -57,6 +59,11 @@ def _put(self, args): generated_class = PropertySchema(property_schema)(generated_class) generated_class = ThingProperty(generated_class) + if description: + generated_class = Doc(description=description, summary=description)( + generated_class + ) + return generated_class @@ -74,8 +81,18 @@ def _put(self, args): labthing.add_component(my_component, "org.labthings.example.mycomponent") # Add routes for the API views we created -labthing.add_view(gen_property(my_component, "magic_denoise"), "/denoise") -labthing.add_view(gen_property(my_component, "magic_dictionary"), "/dictionary") +labthing.add_view( + gen_property(my_component, "magic_denoise", description="A magic denoise property"), + "/denoise", +) +labthing.add_view( + gen_property( + my_component, + "magic_dictionary", + description="A big dictionary of little properties", + ), + "/dictionary", +) # Start the app if __name__ == "__main__":