17
17
<a href =" https://www.python.org/downloads/ " ><img src =" https://img.shields.io/badge/python-3.7-blue.svg " alt =" Python 3.7 " ></a >
18
18
</p >
19
19
20
-
21
- ![ img] ( https://user-images.githubusercontent.com/10708076/40740929-bd141942-6452-11e8-911c-d9032f8d625f.png )
22
-
23
20
<p >
24
21
25
22
``` aiohttp-apispec ``` key features:
@@ -52,7 +49,6 @@ pip install aiohttp-apispec
52
49
from aiohttp_apispec import (
53
50
docs,
54
51
request_schema,
55
- response_schema,
56
52
setup_aiohttp_apispec,
57
53
)
58
54
from aiohttp import web
@@ -63,19 +59,12 @@ class RequestSchema(Schema):
63
59
id = fields.Int()
64
60
name = fields.Str(description = " name" )
65
61
66
-
67
- class ResponseSchema (Schema ):
68
- msg = fields.Str()
69
- data = fields.Dict()
70
-
71
-
72
62
@docs (
73
63
tags = [" mytag" ],
74
64
summary = " Test method summary" ,
75
65
description = " Test method description" ,
76
66
)
77
67
@request_schema (RequestSchema(strict = True ))
78
- @response_schema (ResponseSchema(), 200 )
79
68
async def index (request ):
80
69
return web.json_response({" msg" : " done" , " data" : {}})
81
70
@@ -84,9 +73,16 @@ app = web.Application()
84
73
app.router.add_post(" /v1/test" , index)
85
74
86
75
# init docs with all parameters, usual for ApiSpec
87
- setup_aiohttp_apispec(app = app, title = " My Documentation" , version = " v1" )
76
+ setup_aiohttp_apispec(
77
+ app = app,
78
+ title = " My Documentation" ,
79
+ version = " v1" ,
80
+ url = " /api/docs/swagger.json" ,
81
+ swagger_path = " /api/docs" ,
82
+ )
88
83
89
- # now we can find it on 'http://localhost:8080/api/docs/api-docs'
84
+ # Now we can find spec on 'http://localhost:8080/api/docs/swagger.json'
85
+ # and docs on 'http://localhost:8080/api/docs'
90
86
web.run_app(app)
91
87
```
92
88
Class based views are also supported:
@@ -118,7 +114,7 @@ And it allows you not to use schemas for responses documentation:
118
114
description = " Test method description" ,
119
115
responses = {
120
116
200 : {
121
- " schema" : ResponseSchema() ,
117
+ " schema" : ResponseSchema,
122
118
" description" : " Success response" ,
123
119
}, # regular response
124
120
404 : {" description" : " Not found" }, # responses without schema
@@ -165,9 +161,6 @@ You can change ``Request``'s ``'data'`` param to another with ``request_data_nam
165
161
setup_aiohttp_apispec(
166
162
app = app,
167
163
request_data_name = " validated_data" ,
168
- title = " My Documentation" ,
169
- version = " v1" ,
170
- url = " /api/docs/api-docs" ,
171
164
)
172
165
173
166
...
@@ -200,8 +193,25 @@ app.middlewares.extend(
200
193
```
201
194
202
195
## Build swagger web client
196
+
197
+ #### 3.X SwaggerUI version
198
+
199
+ Just add ` swagger_path ` parameter to ` setup_aiohttp_apispec ` function.
200
+
201
+ For example:
202
+
203
+ ``` python
204
+ setup_aiohttp_apispec(app, swagger_path = " /docs" )
205
+ ```
206
+
207
+ Then go to ` /docs ` and see awesome SwaggerUI
208
+
209
+ #### 2.X SwaggerUI version
210
+
211
+ If you prefer older version you can use
212
+ [ aiohttp_swagger] ( https://github.com/cr0hn/aiohttp-swagger ) library.
203
213
` aiohttp-apispec ` adds ` swagger_dict ` parameter to aiohttp web application after initialization (with ` setup_aiohttp_apispec ` function).
204
- So you can use it easily with [ aiohttp_swagger ] ( https://github.com/cr0hn/aiohttp-swagger ) library :
214
+ So you can use it easily like :
205
215
206
216
``` Python
207
217
from aiohttp_apispec import setup_aiohttp_apispec
0 commit comments