Parcourir la source

add tags parameter on with_api_doc

Bastien Sevajol il y a 6 ans
Parent
révision
5ece55f0cc
4 fichiers modifiés avec 30 ajouts et 1 suppressions
  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 Voir le fichier

63
         output_file: OutputFileDescription=None,
63
         output_file: OutputFileDescription=None,
64
         output_headers: OutputHeadersDescription=None,
64
         output_headers: OutputHeadersDescription=None,
65
         errors: typing.List[ErrorDescription]=None,
65
         errors: typing.List[ErrorDescription]=None,
66
+        tags: typing.List[str]=None
66
     ):
67
     ):
67
         self.input_path = input_path
68
         self.input_path = input_path
68
         self.input_query = input_query
69
         self.input_query = input_query
74
         self.output_file = output_file
75
         self.output_file = output_file
75
         self.output_headers = output_headers
76
         self.output_headers = output_headers
76
         self.errors = errors or []
77
         self.errors = errors or []
78
+        self.tags = tags or []

+ 3 - 0
hapic/doc.py Voir le fichier

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

+ 6 - 1
hapic/hapic.py Voir le fichier

86
     def reset_context(self) -> None:
86
     def reset_context(self) -> None:
87
         self._context = None
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
         def decorator(func):
94
         def decorator(func):
91
             @functools.wraps(func)
95
             @functools.wraps(func)
92
             def wrapper(*args, **kwargs):
96
             def wrapper(*args, **kwargs):
97
             setattr(func, DECORATION_ATTRIBUTE_NAME, token)
101
             setattr(func, DECORATION_ATTRIBUTE_NAME, token)
98
 
102
 
99
             description = self._buffer.get_description()
103
             description = self._buffer.get_description()
104
+            description.tags = tags
100
 
105
 
101
             reference = ControllerReference(
106
             reference = ControllerReference(
102
                 wrapper=wrapper,
107
                 wrapper=wrapper,

+ 19 - 0
tests/func/test_doc.py Voir le fichier

147
         assert 'post' in doc['paths']['/upload']
147
         assert 'post' in doc['paths']['/upload']
148
         assert 'description' in doc['paths']['/upload']['post']
148
         assert 'description' in doc['paths']['/upload']['post']
149
         assert 'Hello doc' == doc['paths']['/upload']['post']['description']
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']