Browse Source

doc generation: adapt for error_builder

Bastien Sevajol 6 years ago
parent
commit
f06a14c4f6
2 changed files with 27 additions and 2 deletions
  1. 2 2
      hapic/doc.py
  2. 25 0
      tests/func/test_doc.py

+ 2 - 2
hapic/doc.py View File

@@ -50,7 +50,7 @@ def bottle_generate_operations(
50 50
 
51 51
     if description.errors:
52 52
         for error in description.errors:
53
-            schema_class = type(error.wrapper.schema)
53
+            schema_class = type(error.wrapper.error_builder)
54 54
             method_operations.setdefault('responses', {})\
55 55
                 [int(error.wrapper.http_code)] = {
56 56
                     'description': int(error.wrapper.http_code),
@@ -153,7 +153,7 @@ class DocGenerator(object):
153 153
 
154 154
             if description.errors:
155 155
                 for error in description.errors:
156
-                    schemas.append(type(error.wrapper.schema))
156
+                    schemas.append(type(error.wrapper.error_builder))
157 157
 
158 158
         for schema in set(schemas):
159 159
             spec.definition(schema.__name__, schema=schema)

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

@@ -170,3 +170,28 @@ class TestDocGeneration(Base):
170 170
         assert 'post' in doc['paths']['/upload']
171 171
         assert 'tags' in doc['paths']['/upload']['post']
172 172
         assert ['foo', 'bar'] == doc['paths']['/upload']['post']['tags']
173
+
174
+    def test_func__errors__nominal_case(self):
175
+        hapic = Hapic()
176
+        app = bottle.Bottle()
177
+        hapic.set_context(MyContext(app=app))
178
+
179
+        @hapic.with_api_doc()
180
+        @hapic.handle_exception()
181
+        def my_controller(hapic_data=None):
182
+            assert hapic_data
183
+
184
+        app.route('/upload', method='POST', callback=my_controller)
185
+        doc = hapic.generate_doc()
186
+
187
+        assert doc.get('paths')
188
+        assert '/upload' in doc['paths']
189
+        assert 'post' in doc['paths']['/upload']
190
+        assert 'responses' in doc['paths']['/upload']['post']
191
+        assert 500 in doc['paths']['/upload']['post']['responses']
192
+        assert {
193
+            'description': 500,
194
+            'schema': {
195
+                '$ref': '#/definitions/DefaultErrorBuilder'
196
+            }
197
+        } == doc['paths']['/upload']['post']['responses'][500]