How to use the flasgger.utils.swag_from function in flasgger

To help you get started, we’ve selected a few flasgger examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github IKNL / vantage / vantage6_server / vantage6 / server / resource / node.py View on Github external
    @swag_from(str(Path(r"swagger/get_node_with_id.yaml")), 
        endpoint='node_with_id')
    @swag_from(str(Path(r"swagger/get_node_without_id.yaml")), 
        endpoint='node_without_id')
    def get(self, id=None):
        nodes = db.Node.get(id)
        user_or_node = g.user or g.node

        is_root = False
        if g.user:
            is_root = g.user.roles == 'root'

        if id:
            if not nodes:
                return {"msg": "node with id={} not found".format(id)}, \
                    HTTPStatus.NOT_FOUND  # 404
            if (not is_root) \
github flasgger / flasgger / examples / example_app.py View on Github external
@swag_from('username_specs.yml')
def fromfile_decorated(username):
    return jsonify({'username': username})
github IKNL / vantage / vantage6_server / vantage6 / server / resource / node.py View on Github external
    @swag_from(str(Path(r"swagger/post_node_without_node_id.yaml")), endpoint='node_without_id')
    def post(self):

        parser = reqparse.RequestParser()
        parser.add_argument(
            "collaboration_id",
            type=int,
            required=True,
            help="This field cannot be left blank!"
        )
        data = parser.parse_args()

        collaboration = db.Collaboration.get(data["collaboration_id"])

        # check that the collaboration exists
        if not collaboration:
            return {"msg": "collaboration_id '{}' does not exist".format(
github IKNL / vantage / vantage6_server / vantage6 / server / resource / node.py View on Github external
    @swag_from(str(Path(r"swagger/patch_node_with_id.yaml")), endpoint='node_with_id')
    def patch(self, id):
        """update existing node"""
        node = db.Node.get(id)

        # do not create new nodes here
        if not node:
            return {"msg": "Use POST to create a new node"}, HTTPStatus.FORBIDDEN  # 403            

        data = request.get_json()
        if 'state' in data:
            data['state'] = json.dumps(data['state'])

        if g.node:
            if g.node.id == node.id:
                log.debug("Hey! It's me! I got this!")
                node.update(include=['status', 'state'], **data)
github flasgger / flasgger / examples / example_blueprint.py View on Github external
@swag_from('username_specs.yml', methods=['GET'])
@swag_from('username_specs.yml', methods=['POST'])
def usernames(username):
    return jsonify({'username': username})
github fossasia / pslab-webapp / backend / app / views.py View on Github external
@swag_from('validateLogin.yml')
def validateLogin():
    _username = request.form['inputEmail']
    _password = request.form['inputPassword']
    user = User.query.filter_by(email=_username).first() #retrieve the row based on e-mail
    if user is not None:
        if check_password_hash(user.pwHash,_password):
            session['user'] = [user.username,user.email]
            return json.dumps({'status':True})
        else:
            return json.dumps({'status':False,'message':'Wrong Email address or Password. hash mismatch'}),400
    else:
        return json.dumps({'status':False,'message':'Username not specified'})
github flasgger / flasgger / examples / example_app.py View on Github external
@swag_from('username_specs_no_descr.yml')
def fromfile_decorated_no_descr(username):
    return jsonify({'username': username})
github flasgger / flasgger / examples / colors_from_specdict.py View on Github external
@swag_from(colors_spec)
def colors(palette):
    """
    Example using a dictionary as specification
    This is the description
    You can also set 'summary' and 'description' in
    specs_dict
    ---
    # values here overrides the specs dict
    deprecated: true
    """
    all_colors = {
        'cmyk': ['cian', 'magenta', 'yellow', 'black'],
        'rgb': ['red', 'green', 'blue']
    }
    if palette == 'all':
        result = all_colors
github flasgger / flasgger / examples / example_app.py View on Github external
@swag_from('username_specs_utf32.yml')
def fromfile_decorated_utf32(username):
    return jsonify({'username': username})
github IKNL / vantage / vantage6_server / vantage6 / server / resource / node.py View on Github external
    @swag_from(str(Path(r"swagger/delete_node_with_id.yaml")), endpoint='node_with_id')
    def delete(self, id):
        """delete node account"""
        node = db.Node.get(id)

        if not node:
            return {"msg": "node with id={} not found".format(id)}, HTTPStatus.NOT_FOUND  # 404

        if node.organization_id != g.user.organization_id and g.user.roles != 'admin':
            return {"msg": "you are not allowed to delete this node"}, HTTPStatus.FORBIDDEN  # 403

        node.delete()

        return {"msg": "successfully deleted node id={}".format(id)}, HTTPStatus.OK  # 200