Skip to content

Commit

Permalink
Expose /v1/__api__ endpoint with the OAS spec.
Browse files Browse the repository at this point in the history
Fixes #20
  • Loading branch information
Rémy HUBSCHER committed Aug 7, 2017
1 parent b343b85 commit 1a76a77
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 2 deletions.
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
include *.rst LICENSE Makefile tox.ini
include dev-requirements.txt
include pollbot/api.yaml
File renamed without changes.
3 changes: 2 additions & 1 deletion pollbot/app.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from aiohttp import web
from .views import home, release
from .views import home, release, utilities


def get_app(loop=None):
app = web.Application(loop=loop)
app.router.add_get('/', home.redirect)
app.router.add_get('/v1/', home.index)
app.router.add_get('/v1/__api__', utilities.oas_spec)
app.router.add_get('/v1/firefox/{version}', release.info)
return app
12 changes: 12 additions & 0 deletions pollbot/views/utilities.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import os.path

from aiohttp import web
import ruamel.yaml as yaml

HERE = os.path.dirname(__file__)


async def oas_spec(request):
with open(os.path.join(HERE, "..", "api.yaml")) as stream:
oas_spec = yaml.load(stream)
return web.json_response(oas_spec)
2 changes: 1 addition & 1 deletion tests/test_oas.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


def test_oas_spec():
with open(os.path.join(HERE, "..", "api.yaml"), 'r') as stream:
with open(os.path.join(HERE, "..", "pollbot", "api.yaml"), 'r') as stream:
oas_spec = yaml.load(stream)
# example for swagger spec v2.0
validate_spec(oas_spec)
12 changes: 12 additions & 0 deletions tests/test_views.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import os.path
import pytest
import ruamel.yaml as yaml

from pollbot import __version__ as pollbot_version, HTTP_API_VERSION
from pollbot.app import get_app

HERE = os.path.dirname(__file__)


@pytest.fixture
def cli(loop, test_client):
Expand All @@ -13,6 +18,13 @@ async def test_home_redirects_to_v1(cli):
assert resp.status == 302


async def test_oas_spec(cli):
with open(os.path.join(HERE, "..", "pollbot", "api.yaml"), 'r') as stream:
oas_spec = yaml.load(stream)
resp = await cli.get("/v1/__api__")
assert await resp.json() == oas_spec


async def test_home_body(cli):
resp = await cli.get("/v1/")
assert resp.status == 200
Expand Down

0 comments on commit 1a76a77

Please sign in to comment.