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

How to use swagger with a old flask project. #808

Open
engFelipeMonteiro opened this issue Jul 2, 2021 · 1 comment
Open

How to use swagger with a old flask project. #808

engFelipeMonteiro opened this issue Jul 2, 2021 · 1 comment

Comments

@engFelipeMonteiro
Copy link

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!".
Screen Shot 2021-07-02 at 6 35 50 PM

And the rest_plus page I get the documentation normal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
@engFelipeMonteiro and others