Browse Source

add tags parameter on with_api_doc

Bastien Sevajol 6 years ago
parent
commit
5ece55f0cc
4 changed files with 30 additions and 1 deletions
  1. 2 0
      hapic/description.py
  2. 3 0
      hapic/doc.py
  3. 6 1
      hapic/hapic.py
  4. 19 0
      tests/func/test_doc.py

+ 2 - 0
hapic/description.py View File

@@ -63,6 +63,7 @@ class ControllerDescription(object):
63 63
         output_file: OutputFileDescription=None,
64 64
         output_headers: OutputHeadersDescription=None,
65 65
         errors: typing.List[ErrorDescription]=None,
66
+        tags: typing.List[str]=None
66 67
     ):
67 68
         self.input_path = input_path
68 69
         self.input_query = input_query
@@ -74,3 +75,4 @@ class ControllerDescription(object):
74 75
         self.output_file = output_file
75 76
         self.output_headers = output_headers
76 77
         self.errors = errors or []
78
+        self.tags = tags or []

+ 3 - 0
hapic/doc.py View File

@@ -93,6 +93,9 @@ def bottle_generate_operations(
93 93
                 'type': 'file',
94 94
             })
95 95
 
96
+    if description.tags:
97
+        method_operations['tags'] = description.tags
98
+
96 99
     operations = {
97 100
         route.method.lower(): method_operations,
98 101
     }

+ 6 - 1
hapic/hapic.py View File

@@ -86,7 +86,11 @@ class Hapic(object):
86 86
     def reset_context(self) -> None:
87 87
         self._context = None
88 88
 
89
-    def with_api_doc(self):
89
+    def with_api_doc(self, tags: typing.List['str']=None):
90
+        # FIXME BS 20171228: Documenter sur ce que ça fait vraiment (tester:
91
+        # on peut l'enlever si on veut pas generer la doc ?)
92
+        tags = tags or []  # FDV
93
+
90 94
         def decorator(func):
91 95
             @functools.wraps(func)
92 96
             def wrapper(*args, **kwargs):
@@ -97,6 +101,7 @@ class Hapic(object):
97 101
             setattr(func, DECORATION_ATTRIBUTE_NAME, token)
98 102
 
99 103
             description = self._buffer.get_description()
104
+            description.tags = tags
100 105
 
101 106
             reference = ControllerReference(
102 107
                 wrapper=wrapper,

+ 19 - 0
tests/func/test_doc.py View File

@@ -147,3 +147,22 @@ class TestDocGeneration(Base):
147 147
         assert 'post' in doc['paths']['/upload']
148 148
         assert 'description' in doc['paths']['/upload']['post']
149 149
         assert 'Hello doc' == doc['paths']['/upload']['post']['description']
150
+
151
+    def test_func__tags__ok__nominal_case(self):
152
+        hapic = Hapic()
153
+        app = bottle.Bottle()
154
+        hapic.set_context(MyContext(app=app))
155
+
156
+        @hapic.with_api_doc(tags=['foo', 'bar'])
157
+        def my_controller(hapic_data=None):
158
+            assert hapic_data
159
+            assert hapic_data.files
160
+
161
+        app.route('/upload', method='POST', callback=my_controller)
162
+        doc = hapic.generate_doc()
163
+
164
+        assert doc.get('paths')
165
+        assert '/upload' in doc['paths']
166
+        assert 'post' in doc['paths']['/upload']
167
+        assert 'tags' in doc['paths']['/upload']['post']
168
+        assert ['foo', 'bar'] == doc['paths']['/upload']['post']['tags']