def register_schema(api: Namespace) -> Namespace: all_models = [ getattr(schema, attr) for attr in dir(schema) if isinstance(getattr(schema, attr), Model) ] # TODO: only a subset of all models should be registered. for model in all_models: api.add_model(model.name, model) return api
BlackboxResponseApi, BlackboxTrainResponseApi, BlackboxResponseErrorApi, BlackboxResponseTaskApi, ) from .validation import validate_data # ML Namespace ml_ns = Namespace( name="Blackbox Anomaly Detection", path="/api/v1/bb", description="Anomaly Detection with Machine Learning and Mathematicals models", ) # Register models of namespace ml_ns.add_model("BlackboxModel", BlackboxModelApi) ml_ns.add_model("BlackboxModelPatch", BlackboxModelPatchApi) ml_ns.add_model("BlackboxData", BlackboxDataApi) ml_ns.add_model("BlackboxTrain", BlackboxTrainApi) ml_ns.add_model("BlackboxPCAMahalanobis", BlackboxPCAMahalanobisApi) ml_ns.add_model("BlackboxAutoencoder", BlackboxAutoencoderApi) ml_ns.add_model("BlackboxKMeans", BlackboxKMeansApi) ml_ns.add_model("BlackboxOneClassSVM", BlackboxOneClassSVMApi) ml_ns.add_model( "BlackboxGaussianDistribution", BlackboxGaussianDistributionApi, ) ml_ns.add_model("BlackboxIsolationForest", BlackboxIsolationForestApi) ml_ns.add_model("BlackboxKNN", BlackboxKNNApi) ml_ns.add_model("BlackboxLOF", BlackboxLOFApi) ml_ns.add_model("BlackboxResponse", BlackboxResponseApi) ml_ns.add_model("BlackboxTrainResponse", BlackboxTrainResponseApi)
from flask import jsonify from flask_restx import Namespace, Resource, fields import json from random import randint from .models import todo_model ns = Namespace('todos', description='Todos operations') # Add models ns.add_model("todo", todo_model) # Init Array todos = [ {'id': '123', 'task': 'Clean the bedroom'}, {'id': '563', 'task': 'Go to shop milk'} ] @ns.route("/") class TodoList(Resource): @ns.doc('list_todos') @ns.marshal_list_with(todo_model) def get(self): """ Returns a list of todos """ return todos @ns.doc('create_todo') @ns.expect(todo_model) @ns.marshal_with(todo_model, code=201)
def register_example_response_models(api: Namespace): api.add_model("example_response_model", example_response_model)