I am new to Flask and still learning how to properly set up and configure it, and i m struggle with documentation.
I’m working on a Flask application that uses blueprints to organize my routes, and I’m documenting the API with flask_openapi3. However, when I access Swagger via http://127.0.0.1:5000/openapi/swagger, I only see the title of my API and no routes are documented.
/my_project
/app
__init__.py
/main
routes.py
/hello
routes.py
run.py
run.py
from app import create_app
app = create_app()
if __name__ == '__main__':
app.run(debug=True)
app/init.py
from .main.routes import main_bp
from .hello.routes import hello_bp
from flask_openapi3 import OpenAPI, Info
def create_app():
app = OpenAPI(__name__, info=Info(title="API PROJECT Data", version="1.0.0"))
app.register_blueprint(main_bp, url_prefix='/main')
app.register_blueprint(hello_bp, url_prefix='/hello')
return app
example app/hello/routes.py:
from flask import Blueprint
hello_bp = Blueprint('hello', __name__)
@hello_bp.get('/hello')
def hello():
"""
Hello Route
---
description: Returns a hello message.
responses:
200:
description: Successful response
"""
return 'Hello'
routes map :
Map([<Rule '/static/<filename>' (HEAD, OPTIONS, GET) -> static>,
<Rule '/openapi/static/<filename>' (HEAD, OPTIONS, GET) -> openapi.static>,
<Rule '/openapi/openapi.json' (HEAD, OPTIONS, GET) -> openapi.api_doc>,
<Rule '/openapi/swagger' (HEAD, OPTIONS, GET) -> openapi.swagger>,
<Rule '/openapi/redoc' (HEAD, OPTIONS, GET) -> openapi.redoc>,
<Rule '/openapi/rapidoc' (HEAD, OPTIONS, GET) -> openapi.rapidoc>,
<Rule '/openapi/' (HEAD, OPTIONS, GET) -> openapi.openapi>,
<Rule '/main/data' (HEAD, OPTIONS, GET) -> main.get_data>,
<Rule '/main/modality' (HEAD, OPTIONS, GET) -> main.get_columns>,
<Rule '/main/filter' (HEAD, OPTIONS, GET) -> main.filter_data>,
<Rule '/hello/hello' (HEAD, OPTIONS, GET) -> hello.index>,
<Rule '/hello/hello2' (HEAD, OPTIONS, GET) -> hello.index2>])
All routes works well , the problem is only that i have no docs. no information with http://127.0.0.1:5000/openapi/ !
I saw that in http://127.0.0.1:5000/openapi/openapi.json
in paths , I have nothing ….
Thanks for your help !