Skip to content

Commit

Permalink
Merge pull request #72 from vkropotko/master
Browse files Browse the repository at this point in the history
Fix an issue with wrong methods in generated UI. Issue #68
  • Loading branch information
cr0hn authored Jul 25, 2019
2 parents 298d513 + 531846d commit 383ca21
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion aiohttp_swagger/helpers/builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def _build_doc_from_func_doc(route):
end_point_doc = route.handler.__doc__.splitlines()
except AttributeError:
return {}
out.update(_extract_swagger_docs(end_point_doc))
out.update(_extract_swagger_docs(end_point_doc, method=str(route.method).lower()))
return out

def generate_doc_from_each_end_point(
Expand Down
18 changes: 18 additions & 0 deletions tests/test_swagger.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,24 @@ def test_undocumented_fn(test_client, loop):
result = json.loads(text)
assert not result['paths']


@asyncio.coroutine
def test_wrong_method(test_client, loop):
app = web.Application(loop=loop)
app.router.add_route('POST', "/post_ping", ping)
setup_swagger(app)
client = yield from test_client(app)
# GET
swagger_resp1 = yield from client.get('/api/doc/swagger.json')
assert swagger_resp1.status == 200
text = yield from swagger_resp1.text()
result = json.loads(text)
assert "/post_ping" in result['paths']
assert "post" in result['paths']["/post_ping"]
resp = yield from client.get('/post_ping')
assert resp.status == 405


@asyncio.coroutine
def test_class_view(test_client, loop):
app = web.Application(loop=loop)
Expand Down

0 comments on commit 383ca21

Please sign in to comment.