I am using the Flask-RestX to generate an automatic swagger 2.0 documentation. But I can not find how I could define the flag "host" by RestX.
I use this code to generate swagger.json automatic with RestX:
# app.py
from flask import Flask
from flask import Blueprint
from flask_restx import Api
def create_app() -> Flask:
"""Create Flask app."""
app = Flask(__name__)
# accepts both /endpoint and /endpoint/ as valid URLs
app.url_map.strict_slashes = False
app.register_blueprint(blueprint, url_prefix="/api/v1")
return app
blueprint = Blueprint("api", __name__)
api = Api(blueprint,
doc='/docs/',
title="Test API",
version="1.0",
description="Test API")
app = create_app()
if __name__ == "__main__": # Only in dev
app.run(host="0.0.0.0", port=8080, debug=True) # nosec
To get the swagger.json and save it on folder docs/specs
, I run this script:
"""Export Swagger documentation automatically."""
import json
import yaml
from app import create_app
def get_swagger_json():
"""Get swagger json generated automatic by RestX."""
with app.test_client() as client:
swagger_doc = client.get('/api/v1/swagger.json').get_json()
with open('docs/specs/swagger.json', 'w', encoding='utf-8') as file:
json.dump(swagger_doc, file, ensure_ascii=False, indent=4)
app = create_app()
get_swagger_json()
I want generate a swagger.json like this:
{
"swagger": "2.0",
"basePath": "/api/v1",
"host": "myserver-prod.com.br",
...
}
But I can generate this with RestX:
{
"swagger": "2.0",
"basePath": "/api/v1",
...
}
Anyone could help me in how I can do this?