Skip to content

Commit cb69657

Browse files
Readme refactoring
1 parent b967033 commit cb69657

File tree

1 file changed

+28
-18
lines changed

1 file changed

+28
-18
lines changed

README.md

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@
1717
<a href="https://www.python.org/downloads/"><img src="https://img.shields.io/badge/python-3.7-blue.svg" alt="Python 3.7"></a>
1818
</p>
1919

20-
21-
![img](https://user-images.githubusercontent.com/10708076/40740929-bd141942-6452-11e8-911c-d9032f8d625f.png)
22-
2320
<p>
2421

2522
```aiohttp-apispec``` key features:
@@ -52,7 +49,6 @@ pip install aiohttp-apispec
5249
from aiohttp_apispec import (
5350
docs,
5451
request_schema,
55-
response_schema,
5652
setup_aiohttp_apispec,
5753
)
5854
from aiohttp import web
@@ -63,19 +59,12 @@ class RequestSchema(Schema):
6359
id = fields.Int()
6460
name = fields.Str(description="name")
6561

66-
67-
class ResponseSchema(Schema):
68-
msg = fields.Str()
69-
data = fields.Dict()
70-
71-
7262
@docs(
7363
tags=["mytag"],
7464
summary="Test method summary",
7565
description="Test method description",
7666
)
7767
@request_schema(RequestSchema(strict=True))
78-
@response_schema(ResponseSchema(), 200)
7968
async def index(request):
8069
return web.json_response({"msg": "done", "data": {}})
8170

@@ -84,9 +73,16 @@ app = web.Application()
8473
app.router.add_post("/v1/test", index)
8574

8675
# 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+
)
8883

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'
9086
web.run_app(app)
9187
```
9288
Class based views are also supported:
@@ -118,7 +114,7 @@ And it allows you not to use schemas for responses documentation:
118114
description="Test method description",
119115
responses={
120116
200: {
121-
"schema": ResponseSchema(),
117+
"schema": ResponseSchema,
122118
"description": "Success response",
123119
}, # regular response
124120
404: {"description": "Not found"}, # responses without schema
@@ -165,9 +161,6 @@ You can change ``Request``'s ``'data'`` param to another with ``request_data_nam
165161
setup_aiohttp_apispec(
166162
app=app,
167163
request_data_name="validated_data",
168-
title="My Documentation",
169-
version="v1",
170-
url="/api/docs/api-docs",
171164
)
172165

173166
...
@@ -200,8 +193,25 @@ app.middlewares.extend(
200193
```
201194

202195
## 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.
203213
`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:
205215

206216
```Python
207217
from aiohttp_apispec import setup_aiohttp_apispec

0 commit comments

Comments
 (0)