From bad7f7a0978e1be3b0e1d7c6d8cee40b9fe1a5a6 Mon Sep 17 00:00:00 2001 From: Askarpour Date: Wed, 12 Feb 2020 19:15:00 +0100 Subject: [PATCH] swagger setting --- main.py | 13 ++++++ requirements.txt | 1 + static/swagger.json | 96 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 110 insertions(+) create mode 100644 static/swagger.json diff --git a/main.py b/main.py index c6544d5..bf335ad 100644 --- a/main.py +++ b/main.py @@ -1,5 +1,6 @@ from flask import Flask, request import shutil +from flask_swagger_ui import get_swaggerui_blueprint import requests, os import blueprint2json from gevent.pywsgi import WSGIServer @@ -8,6 +9,18 @@ import json app = Flask(__name__) +SWAGGER_URL = '/docs' +API_URL = '/static/swagger.json' +SWAGGERUI_BLUEPRINT = get_swaggerui_blueprint( + SWAGGER_URL, + API_URL, + config={ + 'app_name': "SODALITE iac-blueprint-builder" + } +) +app.register_blueprint(SWAGGERUI_BLUEPRINT, url_prefix=SWAGGER_URL) + + XOPERA_API = 'http://154.48.185.206:5000/manage' @app.route('/parse', methods = ['POST']) diff --git a/requirements.txt b/requirements.txt index f917164..a641a30 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ Flask==1.1.1 gevent==1.4.0 requests +flask_swagger_ui diff --git a/static/swagger.json b/static/swagger.json new file mode 100644 index 0000000..4b21947 --- /dev/null +++ b/static/swagger.json @@ -0,0 +1,96 @@ +{ + "openapi": "3.0.0", + "info": { + "description": "SODALITE iac-blueprint-builder component", + "version": "1.0.0", + "title": "iac-blueprint-builder", + "contact": { + "email": "mehrnoosh.askarpour@gmail.com" + } + }, + "servers": [ + { + "url": "/" + } + ], + "tags": [ + { + "name": "iac-blueprint-builder", + "description": "SODALITE JSON parser" + } + ], + "paths": { + "/parse": { + "post": { + "tags": [ + "parse" + ], + "summary": "Parse JSON file and save blueprint to xOpera", + "requestBody": { + "description": "parse", + "required": true, + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/parseBody" + } + } + } + }, + "produces": [ + "application/json" + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/components/schemas/parseResponse" + } + } + } + } + } + }, + "components": { + "schemas": { + "parseBody": { + "type": "object", + "properties": { + "name": { + "type": "string", + "format": "string" + }, + "data": { + "type": "SODALITE JSON", + "format": "SODALITE JSON" + } + } + }, + "parseResponse": { + "type": "object", + "properties": { + "blueprint_token": { + "type": "string", + "format": "string" + }, + "id": { + "type": "string", + "format": "string" + }, + "message": { + "type": "string", + "format": "string" + }, + "timestamp": { + "type": "string", + "format": "string" + }, + "version_id": { + "type": "number", + "format": "number" + } + } + } + } + } + }