Пример #1
0
def write_swagger():
    """
    Generate the Swagger documentation and store it in a file.
    """
    yaml.add_representer(collections.defaultdict, Representer.represent_dict)
    outfile = "openapi/swagger.yaml"
    with open(outfile, "w") as f:
        data = Flasgger.get_apispecs(swagger)
        yaml.dump(data, f, default_flow_style=False)
        print("Generated docs")
Пример #2
0
def create_app():
    app = Flask(__name__)
    app.logger.setLevel(logging.DEBUG)
    app.config.from_object(Config)
    db.init_app(app)

    jwt_manager.init_app(app)
    CORS(app, resources=r'/*')
    Flasgger(app)

    from .web import main as main_bludprint
    app.register_blueprint(main_bludprint)

    return app
Пример #3
0
def build_swag_doc():
    """
    Return a compilation of the Swagger docs of all the blueprints.
    """
    from openapi.app_info import app_info
    from openapi.definitions import definitions

    swag_doc = {}
    subs = parse_sphinx_substitutions()

    # add the Flask endpoints to the documentation
    with app.app_context():
        swagger = Swagger(app, template=app_info)
        swag_doc = Flasgger.get_apispecs(swagger)
    if "paths" not in swag_doc:
        swag_doc["paths"] = {}

    # add the schema definitions
    swag_doc["definitions"] = definitions

    # parse and add each blueprint's docstring
    for route in routes:

        docstring = route["view_func"].__doc__
        if not docstring:
            print("This endpoint is not documented: {}".format(
                route["view_func"].__name__))

        parsed_doc = Docstring.from_string(docstring)
        spec = translate_to_swag(parsed_doc.sections, subs)

        # overwrite parsed info with manually written 'swagger' field info
        # (e.g. a PUT and a POST point to the same function but one is for creation and the other for update -> overwritte summary)
        # (e.g. to add a dry_run tag)
        # note: parameters are added, not overwritten
        if route["swagger"]:
            new_params = route["swagger"].pop("parameters", [])
            spec["parameters"].extend(new_params)
            spec.update(route["swagger"])

        path = route["rule"]  # OR? '/v0/submission' + route['rule']

        # methods: GET, PUT, POST, DELETE
        for method in route["options"].get("methods", []):
            if path not in swag_doc["paths"]:
                swag_doc["paths"][path] = {}
            swag_doc["paths"][path][method.lower()] = spec

    return swag_doc
Пример #4
0
import torch
from torch.autograd import Variable

CATBOOST_MODEL = CatBoostClassifier().load_model(fname='catboost_model')
GRADIENT_BOOSTING_CLASSIFIER_MODEL = pickle.load(
    open("gradient_boosting_classifier_model.dat", "rb"))
PYTORCH_MODEL = Net()
MODEL_MAPPING = {
    "001": CATBOOST_MODEL,
    "002": GRADIENT_BOOSTING_CLASSIFIER_MODEL,
    "003": PYTORCH_MODEL
}

app = Flask(__name__)

swagger = Flasgger(app)


@app.route(rule='/', methods=['GET'])
def index():
    return jsonify(result='check42', status=200)


@app.route(rule='/api/predict/', methods=['POST'])
@swag_from('doc.yml')
@validate_json
def get_predict():
    data = request.get_json()
    return jsonify(result=predict(data)), 200

Пример #5
0
def configure(app):
    ''' Starts openapispec '''
    Flasgger(app)
Пример #6
0
def configure(app):
    """Starts openapispec"""
    Flasgger(app)
Пример #7
0
import logging
import os
from logging.handlers import RotatingFileHandler

from flask import Flask, render_template
from flask_bcrypt import Bcrypt
from flask_migrate import Migrate
from flask_sqlalchemy import SQLAlchemy
from flasgger import Flasgger

db = SQLAlchemy()
db_migration = Migrate()
bcrypt = Bcrypt()
flasgger = Flasgger()


def create_app():
    app = Flask(__name__)
    app.secret_key = b"\x91\xd7\x15\x96\xb9=\x8c\x03\xfe\xc0vX\xe9\x14h[\x95\xa8\xaf\xcf>\x1a\x0e\xfb\x0e3\x97/P\x9e\xef9"

    # Configure the Flask app
    config_type = os.getenv("CONFIG_TYPE", default="config.DevelopmentConfig")
    app.config.from_object(config_type)

    # Logging config
    _config_logging(app)
    app.logger.info("Starting the Pokerena App")

    # Initialize extensions
    init_extensions(app)