Browse Source

Fix NoContent with NoContentSchema and replace pagination Nested schema

Guénaël Muller 6 years ago
parent
commit
d407269905

+ 3 - 8
example/fake_api/bottle_api.py View File

@@ -85,19 +85,14 @@ class BottleController(object):
85 85
         }
86 86
 
87 87
     @hapic.with_api_doc()
88
-    @hapic.handle_exception(NoContentException, http_code=HTTPStatus.NO_CONTENT)
88
+    @hapic.output_body(NoContentSchema(),
89
+                       default_http_code=204)
89 90
     @hapic.input_path(UserPathSchema())
90 91
     def del_user(self, id, hapic_data: HapicData):
91 92
         """
92 93
         delete user
93 94
         """
94
-
95
-        # TODO - G.M - 2017-12-05 - Add better
96
-        #  way to doc response of this function, using response object ?
97
-        # return bottle.Response(
98
-        #     status=204,
99
-        # )
100
-        raise NoContentException
95
+        return NoContentSchema()
101 96
 
102 97
     def bind(self, app:bottle.Bottle):
103 98
         app.route('/about', callback=self.about)

+ 3 - 8
example/fake_api/flask_api.py View File

@@ -86,19 +86,14 @@ class FlaskController(object):
86 86
         }
87 87
 
88 88
     @hapic.with_api_doc()
89
-    @hapic.handle_exception(NoContentException, http_code=HTTPStatus.NO_CONTENT)
89
+    @hapic.output_body(NoContentSchema(),
90
+                       default_http_code=204)
90 91
     @hapic.input_path(UserPathSchema())
91 92
     def del_user(self, id, hapic_data: HapicData):
92 93
         """
93 94
         delete user
94 95
         """
95
-
96
-        # TODO - G.M - 2017-12-05 - Add better
97
-        #  way to doc response of this function, using response object ?
98
-        # return flask.Response(
99
-        #     status=204,
100
-        # )
101
-        raise NoContentException
96
+        return NoContentSchema()
102 97
 
103 98
     def bind(self, app: flask.Flask):
104 99
         app.add_url_rule('/about',

+ 3 - 8
example/fake_api/pyramid_api.py View File

@@ -87,19 +87,14 @@ class PyramidController(object):
87 87
         }
88 88
 
89 89
     @hapic.with_api_doc()
90
-    @hapic.handle_exception(NoContentException, http_code=HTTPStatus.NO_CONTENT)
90
+    @hapic.output_body(NoContentSchema(),
91
+                       default_http_code=204)
91 92
     @hapic.input_path(UserPathSchema())
92 93
     def del_user(self, context, request, hapic_data: HapicData):
93 94
         """
94 95
         delete user
95 96
         """
96
-
97
-        # TODO - G.M - 2017-12-05 - Add better
98
-        #  way to doc response of this function, using response object ?
99
-        # return Response(
100
-        #     status_code=204,
101
-        # )
102
-        raise NoContentException
97
+        return NoContentSchema()
103 98
 
104 99
     def bind(self, configurator: Configurator):
105 100
         configurator.add_route('about', '/about', request_method='GET')

+ 5 - 5
example/fake_api/schema.py View File

@@ -1,6 +1,8 @@
1 1
 # -*- coding: utf-8 -*-
2 2
 import marshmallow
3 3
 
4
+class NoContentSchema(marshmallow.Schema):
5
+    pass
4 6
 
5 7
 class AboutResponseSchema(marshmallow.Schema):
6 8
     version = marshmallow.fields.String(required=True,)
@@ -47,8 +49,6 @@ class ListsUserSchema(marshmallow.Schema):
47 49
     # Can't add doc for nested Schema properly
48 50
     # When schema item isn't added through their own method
49 51
     # Ex : Pagination Schema doesn't work here but UserSchema is ok.
50
-    pagination = {
51
-        'first_id': marshmallow.fields.Int(required=True),
52
-        'last_id': marshmallow.fields.Int(required=True),
53
-        'current_id': marshmallow.fields.Int(required=True),
54
-    }
52
+    pagination = marshmallow.fields.Nested(
53
+        PaginationSchema
54
+    )