示例#1
0
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
示例#2
0
from flask_restplus import Namespace, Resource

from service import BuildingRoomSvc
from service import BuildingSvc
from view.decorator import modal_body_with
from .model import BuildingModel
from .model import BuildingRoomModel

api = Namespace('building')
api.add_model('Building', BuildingModel)
api.add_model('BuildingRoom', BuildingRoomModel)

parser = api.parser()
parser.add_argument('room_id')
parser.add_argument('building_type_id')
parser.add_argument('production_type_id')
parser.add_argument('worker', action='append')


@api.route('')
class BuildingList(Resource):
    @api.doc('list all')
    @api.marshal_list_with(BuildingModel)
    def get(self):
        return BuildingSvc.read_all()


@api.route('/<int:id>')
@api.param('id', 'The building identifier')
@api.response(404, 'Building not found')
class Building(Resource):
示例#3
0
from flask_restplus import Resource
from flask_restplus import Namespace
from flask_restplus import abort
from flask import request

from utils.errors import BadRequest
from api.schema import URL_schema
from api.schema import Original_schema
from api.schema import Short_schema
from api.service import UrlDAO


ns = Namespace('', description='Simple URL shorted MS')
ns.add_model('URL', URL_schema)
ns.add_model('Short', Short_schema)
ns.add_model('Original', Original_schema)


DAO = UrlDAO()

@ns.route("/shorten")
class Short(Resource):
    @ns.doc(body=Original_schema)
    @ns.expect(Original_schema)
    @ns.marshal_with(URL_schema, skip_none=True, code=200)
    def put(self, **kwargs):
        url = DAO.put(ns.payload, request.host_url)
        if url == None:
            return abort(400, BadRequest)
        return url
示例#4
0
#  limitations under the License.
#
from flask_restplus import Namespace, Resource
from powderbooking.models import model_weather
from sqlalchemy import MetaData

from database import db
from database.query import Query

from utils.convert_models import convert_sqlalchemy_to_restplus_model

api = Namespace('weather', description='Weather reports of a overview')

weather = convert_sqlalchemy_to_restplus_model(table=model_weather(
    metadata=MetaData()))
api.add_model(name=weather.name, definition=weather)


@api.route('/<int:resort_id>')
@api.param('resort_id', 'The overview identifier')
@api.response(404, 'No weather report for given overview identifier found')
class Weather(Resource):
    @api.doc('get_weather_report')
    @api.marshal_with(weather)
    def get(self, resort_id: int):
        """Get the latest weather report for the given overview identifier"""
        result = db.execute_query(Query.select_weather_recent,
                                  resort_id=resort_id)

        if result.rowcount == 1:
            return result.fetchone()
@author: Jonas
"""
from flask_restplus import Resource, Namespace, Model, fields
from flask.globals import request
from son_editor.util.requestutil import get_json
from son_editor.impl import platformsimpl, platform_connector
from son_editor.util.constants import WORKSPACES, PLATFORMS, SERVICES
from son_editor.util.requestutil import prepare_response

namespace = Namespace(WORKSPACES + '/<int:ws_id>/' + PLATFORMS, description="Platform Resources")

serv_id = Model("Service ID", {
    'id': fields.Integer(required=True, description='The son-editor id of the service being published')
})

namespace.add_model(serv_id.name, serv_id)


@namespace.route("/")
@namespace.response(200, "OK")
class Platforms(Resource):
    """Platforms"""

    def get(self, ws_id):
        """List platforms

        Lists all service platforms in the given workspace"""
        return prepare_response(platformsimpl.get_platforms(ws_id))

    @namespace.doc("")
    def post(self, ws_id):
    })

payload = model_ns.model(
    'uPayload', {
        'payload':
        fields.Nested(
            model_output,
            as_list=True,
            required=True,
            description="Array of model predictions for each input."),
        'total':
        fields.Integer(required=False,
                       description="Total number of predictions.")
    })

model_ns.add_model('model_input', model_input)


@probe_ns.route('/liveness')
class Liveness(Resource):

    # noinspection PyMethodMayBeStatic
    def get(self):
        """Heartbeat."""
        return {'Status': "Running OK."}, HTTPStatus.OK


@probe_ns.route('/readiness')
class Readiness(Resource):

    # noinspection PyMethodMayBeStatic
serv_id = Model("Service ID", {
    'id': fields.Integer(required=True, description='The son-editor id of the service being published')
})

serv_response = serv.inherit("ServiceResponse", serv, {
    "descriptor": fields.Nested(model=serv, description="The Complete Service Descriptor"),
    "id": fields.Integer(description='The Project ID'),
    "project_id": fields.Integer(description='The parent workspace id'),
})

message_response = proj_namespace.model("Message", {
    'message': fields.String(required=True, description="The result message")
})

proj_namespace.add_model(serv_update.name, serv_update)
proj_namespace.add_model(serv.name, serv)
proj_namespace.add_model(serv_response.name, serv_response)


@proj_namespace.route('/')
@cata_namespace.route('/')
@plat_namespace.route('/')
@proj_namespace.param('ws_id', 'The Workspace identifier')
@cata_namespace.param('ws_id', 'The Workspace identifier')
@plat_namespace.param('ws_id', 'The Workspace identifier')
@proj_namespace.param('parent_id', 'The Project identifier')
@cata_namespace.param('parent_id', 'The Catalogue identifier')
@plat_namespace.param('parent_id', 'The Platform identifier')
@proj_namespace.response(200, "OK")
class Services(Resource):
示例#8
0
    })

fields11 = api.model(
    'MyModel', {
        'name': fields.String(description='The name', required=True),
        'type': fields.String(description='The object type', enum=['A', 'B']),
        'age': fields.Integer(min=0),
    })
name = 'job'
__type__ = String
items = {
    name: fields.String,
}
job = api.model(name, items)

api.add_model('123', fields11)

test_parser = api.parser()
test_parser.add_argument('data',
                         type=dict,
                         location='json',
                         help='使用json方式传递 与以下参数方式'
                         ' 相等 {"ge_id": 0, "eq_id": 0 }')


@api.expect(test_parser)
@api.route('/dict', doc={"description": "请求发送字典model样例"})
class DictView(Resource):
    @api.expect(job)
    # @api.expect(resource_fields)
    # @api.doc(model=fields)
示例#9
0
from flask_restplus import Namespace
from models.swagger import new_user_swgger

AuthenticationApi = Namespace('Authentication',
                              'All related with authentication')

UserApi = Namespace('User', 'User management')
UserApi.add_model('new_user', new_user_swgger)
示例#10
0
from flask_restplus import Namespace
from flask_restplus import abort
from flask import request

from api.schema import response_schema
from api.schema import request_schema
from api.schema import query_schema

from api.service import search

from metrics.prometheus import SEARCH_COUNTER
from metrics.prometheus import FLASK_REQUEST_LATENCY

ns = Namespace('', description='Simple word search engine')

ns.add_model('Word', response_schema)
ns.add_model('Query', query_schema)
ns.add_model('Search', request_schema)


@ns.route("/search")
class Search(Resource):
    @ns.doc(body=request_schema)
    @ns.expect(request_schema)
    @ns.marshal_with(response_schema, skip_none=True, code=200)
    @FLASK_REQUEST_LATENCY.time()
    def put(self, **kwargs):

        res = search(ns.payload)

        if res == None:
from son_editor.impl import platformsimpl, platform_connector
from son_editor.util.constants import WORKSPACES, PLATFORMS, SERVICES
from son_editor.util.requestutil import prepare_response

namespace = Namespace(WORKSPACES + '/<int:ws_id>/' + PLATFORMS,
                      description="Platform Resources")

serv_id = Model(
    "Service ID", {
        'id':
        fields.Integer(
            required=True,
            description='The son-editor id of the service being published')
    })

namespace.add_model(serv_id.name, serv_id)


@namespace.route("/")
@namespace.response(200, "OK")
class Platforms(Resource):
    """Platforms"""
    def get(self, ws_id):
        """List platforms

        Lists all service platforms in the given workspace"""
        return prepare_response(platformsimpl.get_platforms(ws_id))

    @namespace.doc("")
    def post(self, ws_id):
        """Create a new service platform
示例#12
0
from flask_restplus import Namespace, Resource

from db import ShapeMultiPolygonDao
from .model import ShapePointModel as ShapePointModel, ShapeRingModel as ShapeRingModel, \
    ShapePolygonModel as ShapePolygonModel, ShapeMultiPolygonModel as ShapeMultiPolygonModel

api = Namespace('shape')
api.add_model('ShapePoint', ShapePointModel)
api.add_model('ShapeRing', ShapeRingModel)
api.add_model('ShapePolygon', ShapePolygonModel)
api.add_model('ShapeMultiPolygon', ShapeMultiPolygonModel)


@api.route('')
class ShapeList(Resource):
    @api.doc('list all')
    @api.marshal_list_with(ShapeMultiPolygonModel)
    def get(self):
        return ShapeMultiPolygonDao.read_all()
示例#13
0
#  See the License for the specific language governing permissions and
#  limitations under the License.
#
from flask_restplus import Namespace, Resource
from powderbooking.models import model_resort
from sqlalchemy import MetaData

from database import db

from utils.convert_models import convert_sqlalchemy_to_restplus_model

api = Namespace('resort', description='Details of the resorts')

resort = convert_sqlalchemy_to_restplus_model(table=model_resort(
    metadata=MetaData()))
api.add_model(name=resort.name, definition=resort)


@api.route('/<int:id>')
@api.param('id', 'The overview identifier')
@api.response(404, 'Resort not found')
class Resort(Resource):
    @api.doc('get_resort')
    @api.marshal_with(resort)
    def get(self, id: int):
        """Get overview details given its identifier"""
        result = db.execute(
            db.get_table('resort').select().where(
                db.get_table_column('resort', 'id') == id))

        if result.rowcount == 1:
示例#14
0
__all__ = ['user_ns']
from flask_restplus import Namespace
from documentation.models import (login_model, registration_model, auth_model,
                                  message_model, gallery_item, metadata,
                                  friend_model, upload_img, user_model,
                                  comment_model, message_post, post_response,
                                  pending_frame_model, pending_model_update,
                                  add_role)

user_ns = Namespace('user',
                    path='/users/<string:username>',
                    description='User level operations')
for model in [
        login_model, registration_model, auth_model, metadata, message_model,
        friend_model, upload_img, user_model, gallery_item, comment_model,
        message_post, post_response, pending_frame_model, pending_model_update,
        add_role
]:
    user_ns.add_model(model.name, model)
示例#15
0
from sqlalchemy import MetaData

from utils.convert_models import filter_restplus_columns, convert_sqlalchemy_to_restplus_model
from database import db
from database.query import Query

from apis.resort import resort

api = Namespace('overview', description='Overview of all resorts with aggregate forecast data')

filtered_resort = filter_restplus_columns(model=resort, mask=['id', 'lat', 'lng', 'village'])
forecast_week = convert_sqlalchemy_to_restplus_model(table=model_forecast_week(metadata=MetaData()))
filtered_forecast_week = filter_restplus_columns(model=forecast_week, mask=['rain_week_mm', 'snow_week_mm'])

overview = Model('overview', {**filtered_resort, **filtered_forecast_week})  # pythonic way to union two dicts
api.add_model(name=overview.name, definition=overview)

max_overview = Model('max_overview', {
    'max': fields.Float(description='The maximum amount of snow or rain forecast of today', required=True)
})
api.add_model(name=max_overview.name, definition=max_overview)


@api.route('/')
class OverviewList(Resource):
    @api.doc('list_overview')
    @api.marshal_list_with(overview)
    def get(self):
        """List all resorts with aggregate forecast data of today"""
        return db.execute_query(Query.select_overview).fetchall()
uid = Model("VNF_UID", {
    'id': fields.String(required=True, description='The VNF UID')
})

funct_response = funct.inherit("FunctionResponse", funct, {
    "descriptor": fields.Nested(model=funct, description="The Complete VNF Descriptor"),
    "id": fields.Integer(description='The Project ID'),
    "project_id": fields.Integer(description='The parent project id'),
})

message_response = namespace.model("Message", {
    'message': fields.String(required=True, description="The result message")
})

namespace.add_model(funct.name, funct)
namespace.add_model(funct_response.name, funct_response)


@namespace.route('/')
@namespace.param('ws_id', 'The Workspace identifier')
@namespace.param('project_id', 'The Project identifier')
class Functions(Resource):
    """Resource methods for all function descriptors of this directory"""

    @namespace.response(200, "OK", [funct_response])
    def get(self, ws_id, project_id):
        """List all functions

        Lists all available functions in the given project or catalogue."""
        functions = functionsimpl.get_functions(ws_id, project_id)
示例#17
0
from flask_restplus import Namespace, Resource

from db import ResourceDao
from .model import ResourceModel

api = Namespace('resource')
api.add_model('Resource', ResourceModel)


@api.route('')
class ResourceList(Resource):
    @api.doc('list all')
    @api.marshal_list_with(ResourceModel)
    def get(self):
        return ResourceDao.read_all()


@api.route('/<int:id>')
@api.param('id', 'The resource identifier')
@api.response(404, 'Resource not found')
class Resource(Resource):
    @api.doc('get by given id')
    @api.marshal_with(ResourceModel)
    def get(self, id):
        obj = ResourceDao.read(id)
        if obj is not None:
            return obj
        else:
            api.abort(404, 'Resource {} does not exist'.format(id))
示例#18
0
funct_response = funct.inherit(
    "FunctionResponse", funct, {
        "descriptor":
        fields.Nested(model=funct, description="The Complete VNF Descriptor"),
        "id":
        fields.Integer(description='The Project ID'),
        "project_id":
        fields.Integer(description='The parent project id'),
    })

message_response = proj_namespace.model("Message", {
    'message':
    fields.String(required=True, description="The result message")
})

proj_namespace.add_model(funct.name, funct)
proj_namespace.add_model(funct_response.name, funct_response)


@proj_namespace.route('/')
@cata_namespace.route('/')
@plat_namespace.route('/')
@proj_namespace.param('ws_id', 'The Workspace identifier')
@cata_namespace.param('ws_id', 'The Workspace identifier')
@plat_namespace.param('ws_id', 'The Workspace identifier')
@proj_namespace.param('parent_id', 'The Project identifier')
@cata_namespace.param('parent_id', 'The Catalogue identifier')
@plat_namespace.param('parent_id', 'The Platform identifier')
class Functions(Resource):
    """Resource methods for all function descriptors of this directory"""
    @proj_namespace.response(200, "OK", [funct_response])
示例#19
0
__all__ = ['base_ns']
from flask_restplus import Namespace
from documentation.models import (login_model, registration_model, auth_model, message_model, gallery_item, metadata,
                                  friend_model, upload_img, user_model)

base_ns = Namespace('base', path='/', description='Base level operations')
for model in [login_model, registration_model, auth_model, metadata, message_model,
              friend_model, upload_img, user_model, gallery_item]:
    base_ns.add_model(model.name, model)
示例#20
0
from flask_restplus import Namespace, Resource

from service import ProductionSvc
from view.decorator import modal_body_with
from .model import ProductionModel

api = Namespace('production')
api.add_model('Production', ProductionModel)

parser = api.parser()
parser.add_argument('type')
parser.add_argument('worker', action='append')
parser.add_argument('tool', action='append')
parser.add_argument('resource', action='append')


@api.route('')
class ProductionList(Resource):
    @api.doc('list all')
    @api.marshal_list_with(ProductionModel)
    def get(self):
        return ProductionSvc.read_all()

    @api.doc('create')
    @modal_body_with(ProductionModel)
    def post(self):
        args = parser.parse_args()
        type = args.get('type')
        workers = args.get('worker') if args.get('worker') is not None else []
        tools = args.get('tool') if args.get('tool') is not None else []
        resources = args.get('resource') if args.get(
uid = Model("VNF_UID", {
    'id': fields.String(required=True, description='The VNF UID')
})

funct_response = funct.inherit("FunctionResponse", funct, {
    "descriptor": fields.Nested(model=funct, description="The Complete VNF Descriptor"),
    "id": fields.Integer(description='The Project ID'),
    "project_id": fields.Integer(description='The parent project id'),
})

message_response = proj_namespace.model("Message", {
    'message': fields.String(required=True, description="The result message")
})

proj_namespace.add_model(funct.name, funct)
proj_namespace.add_model(funct_response.name, funct_response)


@proj_namespace.route('/')
@cata_namespace.route('/')
@plat_namespace.route('/')
@proj_namespace.param('ws_id', 'The Workspace identifier')
@cata_namespace.param('ws_id', 'The Workspace identifier')
@plat_namespace.param('ws_id', 'The Workspace identifier')
@proj_namespace.param('parent_id', 'The Project identifier')
@cata_namespace.param('parent_id', 'The Catalogue identifier')
@plat_namespace.param('parent_id', 'The Platform identifier')
class Functions(Resource):
    """Resource methods for all function descriptors of this directory"""
示例#22
0
from documentation.models import message_model
from flask_restplus import Namespace

functions_ns = Namespace('function',
                         path='/function',
                         description='Function operations')

for model in [message_model]:
    functions_ns.add_model(model.name, model)
    "ServiceResponse", serv, {
        "descriptor":
        fields.Nested(model=serv,
                      description="The Complete Service Descriptor"),
        "id":
        fields.Integer(description='The Project ID'),
        "project_id":
        fields.Integer(description='The parent workspace id'),
    })

message_response = namespace.model("Message", {
    'message':
    fields.String(required=True, description="The result message")
})

namespace.add_model(serv_update.name, serv_update)
namespace.add_model(serv.name, serv)
namespace.add_model(serv_response.name, serv_response)


@namespace.route('/')
@namespace.param('ws_id', 'The Workspace identifier')
@namespace.param('project_id', 'The Project identifier')
@namespace.response(200, "OK")
class Services(Resource):
    """
    Api Methods for all services in this resource
    """
    @namespace.doc("Gets a list of services")
    @namespace.response(200, "OK", [serv_response])
    def get(self, ws_id, project_id):
示例#24
0
#  limitations under the License.
#
from flask_restplus import Namespace, Resource
from powderbooking.models import model_forecast
from sqlalchemy import MetaData

from database import db
from database.query import Query

from utils.convert_models import convert_sqlalchemy_to_restplus_model

api = Namespace('forecast', description='Weather reports of a overview')

forecast = convert_sqlalchemy_to_restplus_model(table=model_forecast(
    metadata=MetaData()))
api.add_model(name=forecast.name, definition=forecast)


@api.route('/current/<int:resort_id>')
@api.param('resort_id', 'The overview identifier')
@api.response(404,
              'No current forecast report for given overview identifier found')
class ForecastCurrent(Resource):
    @api.doc('get_current_forecast_report')
    @api.marshal_list_with(fields=forecast)
    def get(self, resort_id: int):
        """Get the current forecast report from today for the given overview identifier"""
        result = db.execute_query(Query.select_forecast_current,
                                  resort_id=resort_id)

        if result.rowcount > 0: