From 41eae22576a95a7bebb1c7f6d83ab0702c6fcc54 Mon Sep 17 00:00:00 2001 From: kgrvamsi Date: Fri, 29 Nov 2019 12:58:45 -0600 Subject: [PATCH 1/3] Adding Swagger Documentation Support --- README.md | 5 +++++ assembly/scaffold/init/config.py | 12 ++++++++++++ assembly/scaffold/init/main/__init__.py | 25 +++++++++++++++++++++++++ assembly/scaffold/init/requirements.txt | 1 + 4 files changed, 43 insertions(+) diff --git a/README.md b/README.md index 3923b7f..5bf618d 100644 --- a/README.md +++ b/README.md @@ -169,6 +169,8 @@ class Api(Assembly): - Inbuilt development server +- Swagger Documentation + --- @@ -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 --- diff --git a/assembly/scaffold/init/config.py b/assembly/scaffold/init/config.py index a593db9..dce7b1d 100644 --- a/assembly/scaffold/init/config.py +++ b/assembly/scaffold/init/config.py @@ -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 --------------------------- """ diff --git a/assembly/scaffold/init/main/__init__.py b/assembly/scaffold/init/main/__init__.py index 3b6775d..3c2aca9 100644 --- a/assembly/scaffold/init/main/__init__.py +++ b/assembly/scaffold/init/main/__init__.py @@ -69,11 +69,36 @@ def items(self): class Index(Assembly): def index(self): + print("we are here in index route") return @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" diff --git a/assembly/scaffold/init/requirements.txt b/assembly/scaffold/init/requirements.txt index 0dd89ce..bed19c0 100644 --- a/assembly/scaffold/init/requirements.txt +++ b/assembly/scaffold/init/requirements.txt @@ -1,3 +1,4 @@ # Assembly # --------------------------- assembly +flasgger From 215455ca9309a971547784f7be981902e990d287 Mon Sep 17 00:00:00 2001 From: kgrvamsi Date: Fri, 29 Nov 2019 13:01:52 -0600 Subject: [PATCH 2/3] Revert "Adding Swagger Documentation Support" This reverts commit 41eae22576a95a7bebb1c7f6d83ab0702c6fcc54. --- README.md | 5 ----- assembly/scaffold/init/config.py | 12 ------------ assembly/scaffold/init/main/__init__.py | 25 ------------------------- assembly/scaffold/init/requirements.txt | 1 - 4 files changed, 43 deletions(-) diff --git a/README.md b/README.md index 5bf618d..3923b7f 100644 --- a/README.md +++ b/README.md @@ -169,8 +169,6 @@ class Api(Assembly): - Inbuilt development server -- Swagger Documentation - --- @@ -317,9 +315,6 @@ 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 --- diff --git a/assembly/scaffold/init/config.py b/assembly/scaffold/init/config.py index dce7b1d..a593db9 100644 --- a/assembly/scaffold/init/config.py +++ b/assembly/scaffold/init/config.py @@ -292,18 +292,6 @@ 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 --------------------------- """ diff --git a/assembly/scaffold/init/main/__init__.py b/assembly/scaffold/init/main/__init__.py index 3c2aca9..3b6775d 100644 --- a/assembly/scaffold/init/main/__init__.py +++ b/assembly/scaffold/init/main/__init__.py @@ -69,36 +69,11 @@ def items(self): class Index(Assembly): def index(self): - print("we are here in index route") return @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" diff --git a/assembly/scaffold/init/requirements.txt b/assembly/scaffold/init/requirements.txt index bed19c0..0dd89ce 100644 --- a/assembly/scaffold/init/requirements.txt +++ b/assembly/scaffold/init/requirements.txt @@ -1,4 +1,3 @@ # Assembly # --------------------------- assembly -flasgger From f2a86307d5915689c8d9ee1b9845794c6292e30e Mon Sep 17 00:00:00 2001 From: kgrvamsi Date: Fri, 29 Nov 2019 13:10:09 -0600 Subject: [PATCH 3/3] Adding Swagger Documentation Support --- README.md | 5 +++++ assembly/cli.py | 1 + assembly/scaffold/init/config.py | 12 ++++++++++++ assembly/scaffold/init/main/__init__.py | 24 ++++++++++++++++++++++++ assembly/scaffold/init/requirements.txt | 1 + assembly/scaffold/init/wsgi.py | 15 +++++++++++++++ 6 files changed, 58 insertions(+) diff --git a/README.md b/README.md index 3923b7f..5bf618d 100644 --- a/README.md +++ b/README.md @@ -169,6 +169,8 @@ class Api(Assembly): - Inbuilt development server +- Swagger Documentation + --- @@ -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 --- diff --git a/assembly/cli.py b/assembly/cli.py index aa2e117..7d39ea9 100644 --- a/assembly/cli.py +++ b/assembly/cli.py @@ -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 ]") diff --git a/assembly/scaffold/init/config.py b/assembly/scaffold/init/config.py index a593db9..dce7b1d 100644 --- a/assembly/scaffold/init/config.py +++ b/assembly/scaffold/init/config.py @@ -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 --------------------------- """ diff --git a/assembly/scaffold/init/main/__init__.py b/assembly/scaffold/init/main/__init__.py index 3b6775d..20bf2a2 100644 --- a/assembly/scaffold/init/main/__init__.py +++ b/assembly/scaffold/init/main/__init__.py @@ -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" diff --git a/assembly/scaffold/init/requirements.txt b/assembly/scaffold/init/requirements.txt index 0dd89ce..bed19c0 100644 --- a/assembly/scaffold/init/requirements.txt +++ b/assembly/scaffold/init/requirements.txt @@ -1,3 +1,4 @@ # Assembly # --------------------------- assembly +flasgger diff --git a/assembly/scaffold/init/wsgi.py b/assembly/scaffold/init/wsgi.py index 160deeb..665a3c6 100644 --- a/assembly/scaffold/init/wsgi.py +++ b/assembly/scaffold/init/wsgi.py @@ -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 """ @@ -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)