Selaa lähdekoodia

add doc and todos

Bastien Sevajol 6 vuotta sitten
vanhempi
commit
9c6121e60d

+ 6 - 2
hapic/context.py Näytä tiedosto

30
 
30
 
31
     def get_response(
31
     def get_response(
32
         self,
32
         self,
33
+        # TODO BS 20171228: rename into response_content
33
         response: dict,
34
         response: dict,
34
         http_code: int,
35
         http_code: int,
35
     ) -> typing.Any:
36
     ) -> typing.Any:
48
     ) -> RouteRepresentation:
49
     ) -> RouteRepresentation:
49
         raise NotImplementedError()
50
         raise NotImplementedError()
50
 
51
 
52
+    # TODO BS 20171228: rename into openapi !
51
     def get_swagger_path(self, contextualised_rule: str) -> str:
53
     def get_swagger_path(self, contextualised_rule: str) -> str:
52
         """
54
         """
53
         Return OpenAPI path with context path
55
         Return OpenAPI path with context path
56
+        TODO BS 20171228: Give example
54
         :param contextualised_rule: path of original context
57
         :param contextualised_rule: path of original context
55
         :return: OpenAPI path
58
         :return: OpenAPI path
56
         """
59
         """
57
         raise NotImplementedError()
60
         raise NotImplementedError()
58
 
61
 
62
+    # TODO BS 20171228: rename into "bypass"
59
     def by_pass_output_wrapping(self, response: typing.Any) -> bool:
63
     def by_pass_output_wrapping(self, response: typing.Any) -> bool:
60
         """
64
         """
61
-        Return True if the controller response is in final state: we do not
62
-        have to apply output wrapper on it.
65
+        Return True if the controller response is the final response object:
66
+        we do not have to apply any processing on it.
63
         :param response: the original response of controller
67
         :param response: the original response of controller
64
         :return:
68
         :return:
65
         """
69
         """

+ 5 - 0
hapic/decorator.py Näytä tiedosto

377
 
377
 
378
 
378
 
379
 class ExceptionHandlerControllerWrapper(ControllerWrapper):
379
 class ExceptionHandlerControllerWrapper(ControllerWrapper):
380
+    """
381
+    This wrapper is used to wrap a controller and catch given exception if
382
+    raised. An error will be generated in collaboration with context and
383
+    returned.
384
+    """
380
     def __init__(
385
     def __init__(
381
         self,
386
         self,
382
         handled_exception_class: typing.Type[Exception],
387
         handled_exception_class: typing.Type[Exception],

+ 10 - 0
hapic/doc.py Näytä tiedosto

111
         title: str='',
111
         title: str='',
112
         description: str='',
112
         description: str='',
113
     ) -> dict:
113
     ) -> dict:
114
+        """
115
+        Generate an OpenApi 2.0 documentation. Th given context will be used
116
+        to found controllers matching with given DecoratedController.
117
+        :param controllers: List of DecoratedController to match with context
118
+        controllers
119
+        :param context: a context instance
120
+        :param title: The generated doc title
121
+        :param description: The generated doc description
122
+        :return: a apispec documentation dict
123
+        """
114
         spec = APISpec(
124
         spec = APISpec(
115
             title=title,
125
             title=title,
116
             info=dict(description=description),
126
             info=dict(description=description),

+ 24 - 2
hapic/hapic.py Näytä tiedosto

87
         self._context = None
87
         self._context = None
88
 
88
 
89
     def with_api_doc(self, tags: typing.List['str']=None):
89
     def with_api_doc(self, tags: typing.List['str']=None):
90
+        """
91
+        Permit to generate doc about a controller. Use as a decorator:
92
+
93
+        ```
94
+        @hapic.with_api_doc()
95
+        def my_controller(self):
96
+            # ...
97
+        ```
98
+
99
+        What it do: Register this controller with all previous given
100
+        information like `@hapic.input_path(...)` etc.
101
+
102
+        :param tags: list of string tags (OpenApi)
103
+        :return: The decorator
104
+        """
90
         # FIXME BS 20171228: Documenter sur ce que ça fait vraiment (tester:
105
         # FIXME BS 20171228: Documenter sur ce que ça fait vraiment (tester:
91
         # on peut l'enlever si on veut pas generer la doc ?)
106
         # on peut l'enlever si on veut pas generer la doc ?)
92
         tags = tags or []  # FDV
107
         tags = tags or []  # FDV
350
             return decoration.get_wrapper(func)
365
             return decoration.get_wrapper(func)
351
         return decorator
366
         return decorator
352
 
367
 
353
-    def generate_doc(self, title: str='', description: str=''):
368
+    def generate_doc(self, title: str='', description: str='') -> dict:
369
+        """
370
+        See hapic.doc.DocGenerator#get_doc docstring
371
+        :param title: Title of generated doc
372
+        :param description: Description of generated doc
373
+        :return: dict containing apispec doc
374
+        """
354
         return self.doc_generator.get_doc(
375
         return self.doc_generator.get_doc(
355
             self._controllers,
376
             self._controllers,
356
             self.context,
377
             self.context,
357
             title=title,
378
             title=title,
358
-            description=description)
379
+            description=description,
380
+        )

+ 4 - 0
tests/func/test_doc.py Näytä tiedosto

10
 class TestDocGeneration(Base):
10
 class TestDocGeneration(Base):
11
     def test_func__input_files_doc__ok__one_file(self):
11
     def test_func__input_files_doc__ok__one_file(self):
12
         hapic = Hapic()
12
         hapic = Hapic()
13
+        # TODO BS 20171113: Make this test non-bottle
13
         app = bottle.Bottle()
14
         app = bottle.Bottle()
14
         hapic.set_context(MyContext(app=app))
15
         hapic.set_context(MyContext(app=app))
15
 
16
 
39
 
40
 
40
     def test_func__input_files_doc__ok__two_file(self):
41
     def test_func__input_files_doc__ok__two_file(self):
41
         hapic = Hapic()
42
         hapic = Hapic()
43
+        # TODO BS 20171113: Make this test non-bottle
42
         app = bottle.Bottle()
44
         app = bottle.Bottle()
43
         hapic.set_context(MyContext(app=app))
45
         hapic.set_context(MyContext(app=app))
44
 
46
 
75
 
77
 
76
     def test_func__output_file_doc__ok__nominal_case(self):
78
     def test_func__output_file_doc__ok__nominal_case(self):
77
         hapic = Hapic()
79
         hapic = Hapic()
80
+        # TODO BS 20171113: Make this test non-bottle
78
         app = bottle.Bottle()
81
         app = bottle.Bottle()
79
         hapic.set_context(MyContext(app=app))
82
         hapic.set_context(MyContext(app=app))
80
 
83
 
94
 
97
 
95
     def test_func__input_files_doc__ok__one_file_and_text(self):
98
     def test_func__input_files_doc__ok__one_file_and_text(self):
96
         hapic = Hapic()
99
         hapic = Hapic()
100
+        # TODO BS 20171113: Make this test non-bottle
97
         app = bottle.Bottle()
101
         app = bottle.Bottle()
98
         hapic.set_context(MyContext(app=app))
102
         hapic.set_context(MyContext(app=app))
99
 
103
 

+ 0 - 3
tests/func/test_marshmallow_decoration.py Näytä tiedosto

24
         class MySchema(marshmallow.Schema):
24
         class MySchema(marshmallow.Schema):
25
             file_abc = marshmallow.fields.Raw(required=True)
25
             file_abc = marshmallow.fields.Raw(required=True)
26
 
26
 
27
-        @hapic.with_api_doc()
28
         @hapic.input_files(MySchema())
27
         @hapic.input_files(MySchema())
29
         def my_controller(hapic_data=None):
28
         def my_controller(hapic_data=None):
30
             assert hapic_data
29
             assert hapic_data
46
         class MySchema(marshmallow.Schema):
45
         class MySchema(marshmallow.Schema):
47
             file_abc = marshmallow.fields.Raw(required=True)
46
             file_abc = marshmallow.fields.Raw(required=True)
48
 
47
 
49
-        @hapic.with_api_doc()
50
         @hapic.input_files(MySchema())
48
         @hapic.input_files(MySchema())
51
         def my_controller(hapic_data=None):
49
         def my_controller(hapic_data=None):
52
             assert hapic_data
50
             assert hapic_data
72
         class MySchema(marshmallow.Schema):
70
         class MySchema(marshmallow.Schema):
73
             file_abc = marshmallow.fields.Raw(required=True)
71
             file_abc = marshmallow.fields.Raw(required=True)
74
 
72
 
75
-        @hapic.with_api_doc()
76
         @hapic.input_files(MySchema())
73
         @hapic.input_files(MySchema())
77
         def my_controller(hapic_data=None):
74
         def my_controller(hapic_data=None):
78
             assert hapic_data
75
             assert hapic_data