Skip to content

Commit

Permalink
1. config url suport.
Browse files Browse the repository at this point in the history
2. Make the code more concise.
  • Loading branch information
duguiping committed Apr 10, 2019
1 parent 286b9c9 commit d981abd
Show file tree
Hide file tree
Showing 43 changed files with 487 additions and 331 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright [yyyy] [name of copyright owner]
Copyright 2019 PWZER

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
24 changes: 23 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,21 @@ Swagger UI for Python web framework, such Tornado, Flask, Quart, aiohttp and San

- Code

Using the local config file

```python
from swagger_ui import api_doc
api_doc(app, config_path='./config/test.yaml', url_prefix='/api/doc', title='API doc')
```

Using config url, but need to suport [CORS](https://en.wikipedia.org/wiki/Cross-origin_resource_sharing)

```python
api_doc(app, config_url='https://petstore.swagger.io/v2/swagger.json', url_prefix='/api/doc', title='API doc')
```

and keep the old way

```python
# for Tornado
from swagger_ui import tornado_api_doc
Expand Down Expand Up @@ -42,4 +57,11 @@ Swagger UI for Python web framework, such Tornado, Flask, Quart, aiohttp and San
`http://<host>:<port>/api/doc`, open the url in your browser.

## Swagger UI
Swagger UI version is `3.19.3`. see [https://github.com/swagger-api/swagger-ui](https://github.com/swagger-api/swagger-ui).
Swagger UI version is `3.22.0`. see [https://github.com/swagger-api/swagger-ui](https://github.com/swagger-api/swagger-ui).

You can update Swagger UI version with

```bash
cd swagger-ui-py/tools
python update_swagger_ui.py
```
7 changes: 4 additions & 3 deletions examples/aiohttp_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os

from aiohttp import web


Expand All @@ -14,6 +15,6 @@ async def hello(request):
working_dir = os.path.dirname(os.path.abspath(__file__))
config_path = os.path.join(working_dir, 'conf/test.yaml')

from swagger_ui import aiohttp_api_doc
aiohttp_api_doc(app, config_path=config_path)
web.run_app(app)
from swagger_ui import api_doc
api_doc(app, config_path=config_path)
web.run_app(app, port=8989)
6 changes: 4 additions & 2 deletions examples/flask_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os

from flask import Flask

app = Flask(__name__)
Expand All @@ -13,6 +14,7 @@ def hello():
working_dir = os.path.dirname(os.path.abspath(__file__))
config_path = os.path.join(working_dir, 'conf/test.yaml')

from swagger_ui import flask_api_doc
flask_api_doc(app, config_path=config_path)
from swagger_ui import api_doc
api_doc(app, config_path=config_path)

app.run(host='0.0.0.0', port=8989)
5 changes: 3 additions & 2 deletions examples/quart_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os

from quart import Quart

app = Quart(__name__)
Expand All @@ -13,7 +14,7 @@ async def index_handler():
working_dir = os.path.dirname(os.path.abspath(__file__))
config_path = os.path.join(working_dir, 'conf/test.yaml')

from swagger_ui import quart_api_doc
quart_api_doc(app, config_path=config_path)
from swagger_ui import api_doc
api_doc(app, config_path=config_path)

app.run(host='0.0.0.0', port=8989)
5 changes: 3 additions & 2 deletions examples/sanic_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os

from sanic import Sanic, response

app = Sanic(__name__)
Expand All @@ -13,7 +14,7 @@ async def index_handler(request):
working_dir = os.path.dirname(os.path.abspath(__file__))
config_path = os.path.join(working_dir, 'conf/test.yaml')

from swagger_ui import sanic_api_doc
sanic_api_doc(app, config_path=config_path)
from swagger_ui import api_doc
api_doc(app, config_path=config_path)

app.run(host='0.0.0.0', port=8989)
5 changes: 3 additions & 2 deletions examples/tornado_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os

import tornado.ioloop
import tornado.web

Expand All @@ -19,8 +20,8 @@ def make_app():
cur_dir = os.path.dirname(os.path.abspath(__file__))
config_path = os.path.join(cur_dir, 'conf/test.yaml')

from swagger_ui import tornado_api_doc
tornado_api_doc(app, config_path=config_path)
from swagger_ui import api_doc
api_doc(app, config_path=config_path)

app.listen(8989)
tornado.ioloop.IOLoop.current().start()
15 changes: 5 additions & 10 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import os
import sys
from setuptools import setup, find_packages

from setuptools import find_packages, setup


def load_package_data():
package_data = []
cur_dir = os.path.dirname(os.path.abspath(__file__))
for data_dir in ['static', 'templates']:
for file_name in os.listdir(os.path.join(cur_dir, 'src/swagger_ui', data_dir)):
for file_name in os.listdir(os.path.join(cur_dir, 'swagger_ui', data_dir)):
package_data.append(data_dir + '/' + file_name)
return {'swagger_ui': package_data}

Expand All @@ -18,20 +18,15 @@ def readme():


if __name__ == '__main__':
exclude_packages = []
if sys.version_info < (3, 0):
exclude_packages = ['*.py3']

setup(
name='swagger-ui-py',
version='0.1.5',
version='0.1.6',
description='Swagger UI for Python web framework, such Tornado, Flask, Quart and Sanic.',
long_description=readme(),
long_description_content_type='text/markdown',
license='Apache License 2.0',
package_dir={'': 'src'},
include_package_data=True,
packages=find_packages('src', exclude=exclude_packages),
packages=find_packages(),
package_data=load_package_data(),
install_requires=['Jinja2>=2.0', 'PyYAML>=2.0'],
url='https://github.com/PWZER/swagger-ui-py',
Expand Down
9 changes: 0 additions & 9 deletions src/swagger_ui/__init__.py

This file was deleted.

20 changes: 0 additions & 20 deletions src/swagger_ui/flask_swagger_ui.py

This file was deleted.

Empty file removed src/swagger_ui/py3/__init__.py
Empty file.
19 changes: 0 additions & 19 deletions src/swagger_ui/py3/aiohttp_swagger_ui.py

This file was deleted.

19 changes: 0 additions & 19 deletions src/swagger_ui/py3/quart_swagger_ui.py

This file was deleted.

20 changes: 0 additions & 20 deletions src/swagger_ui/py3/sanic_swagger_ui.py

This file was deleted.

Binary file removed src/swagger_ui/static/favicon-16x16.png
Binary file not shown.
Binary file removed src/swagger_ui/static/favicon-32x32.png
Binary file not shown.
93 changes: 0 additions & 93 deletions src/swagger_ui/static/swagger-ui-bundle.js

This file was deleted.

1 change: 0 additions & 1 deletion src/swagger_ui/static/swagger-ui-bundle.js.map

This file was deleted.

Loading

0 comments on commit d981abd

Please sign in to comment.