Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Swagger Documentation #3

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ class Api(Assembly):

- Inbuilt development server

- Swagger Documentation


---

Expand Down Expand Up @@ -315,6 +317,9 @@ Two endpoints will be available:
- `http://127.0.0.1:5000/` which will show an HTML
- `http://127.0.0.1:5000/api/` which will a json response

For Swagger Documentation:

- `http://127.0.0.1:5000/apidocs` which will show you the Swagger UI

---

Expand Down
1 change: 1 addition & 0 deletions assembly/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ def init():
print("%s is setup successfully!" % about.__title__)
print("")
print("> To do:")
print("- Run Pip Install to install other dependencies")
print("- Edit application's config [ ./config.py ] ")
print("- Create your Models/Database tables, then run [ asm-admin sync-models ]")
print("- Create your commands in [ cli.py ] and run your setup command [ asm setup ]")
Expand Down
12 changes: 12 additions & 0 deletions assembly/scaffold/init/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,18 @@ class BaseConfig(object):
#: Directory to store cache if CACHE_TYPE is filesystem, it will
CACHE_DIR = ""

#--------- SWAGGER ----------
#: Flassger is used to render Swagger Docs

#: SWAGGER_TITLE
#: Name of the Application
SWAGGER_TITLE = "Assembly"

#: SWAGGER_UI_VERSION
#: The type of Swagger UI to render
#: 2 or 3 default: 3
SWAGGER_UI_VERSION = "3"


# -------------------------- ENVIRONMENT BASED CONFIG ---------------------------
"""
Expand Down
24 changes: 24 additions & 0 deletions assembly/scaffold/init/main/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,30 @@ def index(self):
@request.cors
@response.json
def api(self):
"""API Endpoint with CORS and JSON response
This is using docstrings for specifications.
---
definitions:
Endpoint:
type: object
properties:
date:
type: date
description:
type: string
items:
$ref: '#/definitions/Endpoint'
responses:
200:
description: API Endpoint with CORS and JSON response
schema:
$ref: '#/definitions/Endpoint'
examples:
response: {
"date": "2019-11-29T18:28:07.125075+00:00",
"description": "API Endpoint with CORS and JSON response"
}
"""
return {
"date": date.utcnow(),
"description": "API Endpoint with CORS and JSON response"
Expand Down
1 change: 1 addition & 0 deletions assembly/scaffold/init/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Assembly
# ---------------------------
assembly
flasgger
15 changes: 15 additions & 0 deletions assembly/scaffold/init/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
"""
from assembly import Assembly

"""
Importing Swagger Supporting Library
"""
from flasgger import Swagger

"""
If you want to use your views CLI, you can import them below
"""
Expand All @@ -58,3 +63,13 @@
the 'app' variable is required
"""
app = Assembly.init(__name__, APPS)

"""
Initialize the Swagger Docs
"""
app.config["SWAGGER"] = {
"title": app.config.get("SWAGGER_TITLE"),
"uiversion": app.config.get("SWAGGER_UI_VERSION"),
}

Swagger(app)