flask-restplus
flask-restplus copied to clipboard
How to use swagger with a old flask project.
I have system that is build with two API one is mine and another is third-part maintaned. How can I add swagger without modify the source of the third-part software.
I build a POC in the source below: PoC
simple_page.py
# Pure flask page
from flask import Blueprint, render_template, abort
from jinja2 import TemplateNotFound
simple_page = Blueprint('simple_page', __name__,
template_folder='templates')
@simple_page.route('/', defaults={'page': 'index'})
@simple_page.route('/<page>')
def show(page):
try:
return render_template('%s.html' % page)
except TemplateNotFound:
abort(418)
other_page.py
#restplus based artecture
from flask import Blueprint, render_template, abort, Flask
from jinja2 import TemplateNotFound
app = Flask(__name__)
other_page = Blueprint('other_page', __name__)
from flask_restplus import Api, Resource, fields
api = Api(other_page, version='1.0', title='Todo API',
description='A simple TODO API', doc='/doc/', template_folder='templates',
)
@api.route('/')
class TodoSimple(Resource):
def get(self):
try:
return render_template('other_page.html')
except TemplateNotFound:
abort(418)
simple.py
from flask import Flask
from simple_page import simple_page
from other_page import other_page
from flask_restplus import Api
app = Flask(__name__)
api = Api(simple_page, doc='/doc/')
app.register_blueprint(simple_page)
#app.register_blueprint(simple_page, url_prefix='/simple_page')
app.register_blueprint(other_page, url_prefix='/other_page')
app.run()
with this I get the doc page but a message "No operations defined in spec!".
And the rest_plus page I get the documentation normal.