How to use the flasgger.SwaggerView 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 flasgger / flasgger / examples / validation.py View on Github external
In this case it will use the same provided filename
    and will extract the schema from `in: body` definition
    and the data will default to `request.json`

    or you can specify:
    @swag_from('file.yml',
               validation=True,
               definition='User',
               data=lambda: request.json,  # any callable
               )
    """
    data = request.json
    return jsonify(data)


class BPUserPostView(SwaggerView):
    tags = ['users']
    parameters = User
    responses = {
        200: {
            'description': 'A single user item',
            'schema': User
        }
    }
    validation = True

    def post(self):
        """
        Example using marshmallow Schema
        validation=True forces validation of parameters in body
        ---
        # This value overwrites the attributes above
github gita / BhagavadGita / app / api / v1 / verse.py View on Github external
FROM %s vt
                    JOIN verses v
                    ON
                    vt.chapter_number = v.chapter_number
                    AND vt.verse_number = v.verse_number
                    WHERE v.chapter_number = %s
                    ORDER BY v.verse_order
                """ % (verses_table, chapter_number)

            verses = db.session.execute(sql)

        result = verses_schema.dump(verses)
        return jsonify(result.data)


class VerseByChapter(SwaggerView):

    decorators = [csrf.exempt, oauth.require_oauth('verse')]
    definitions = {'VerseSchema': VerseSchema}

    def get(self, chapter_number, verse_number):
        """
        Get a particular verse from a chapter.
        Get a specific verse from a specific chapter.
        ---
        tags:
        - verse
        parameters:
        - name: access_token
          in: query
          required: True
          type: 'string'
github gita / BhagavadGita / app / api / v1 / verse.py View on Github external
from flasgger import SwaggerView
from flask import jsonify, request

from app.models.chapter import ChapterModel

from ... import csrf, db, oauth
from ...models.verse import VerseModel
from ...schemas.verse import VerseSchema

verse_schema = VerseSchema()
verses_schema = VerseSchema(many=True)

LANGUAGES = {'en': 'English', 'hi': 'हिंदी'}


class VerseList(SwaggerView):

    decorators = [csrf.exempt, oauth.require_oauth('verse')]
    definitions = {'VerseSchema': VerseSchema}

    def get(self):
        """
        Get all the Verses.
        Get a list of all Verses.
        ---
        tags:
        - verse
        parameters:
        - name: access_token
          in: query
          required: True
          type: 'string'
github gita / BhagavadGita / app / api / v1 / chapter.py View on Github external
JOIN
                chapters c
                ON
                c.chapter_number = ct.chapter_number
                WHERE c.chapter_number = %s
                ORDER BY c.chapter_number
            """ % (chapter_table, chapter_number)
            chapter = db.session.execute(sql).first()

        if chapter:
            result = chapter_schema.dump(chapter)
            return jsonify(result.data)
        return (jsonify({'message': 'Chapter not found.'}), 404)


class ChapterList(SwaggerView):

    decorators = [csrf.exempt, oauth.require_oauth('chapter')]
    definitions = {'ChapterSchema': ChapterSchema}

    def get(self):
        """
        Get all the 18 Chapters of the Bhagavad Gita.
        Get a list of all the 18 Chapters of the Bhagavad Gita.
        ---
        tags:
        - chapter
        parameters:
        - name: access_token
          in: query
          required: True
          type: 'string'
github flasgger / flasgger / examples / validation.py View on Github external
definition='User',
               data=lambda: request.json,  # any callable
               )
    """
    data = request.json
    return jsonify(data)


class User(Schema):
    username = fields.Str(required=True, default="Sirius Black")
    # wrong default "180" to force validation error
    age = fields.Int(required=True, min=18, default="180")
    tags = fields.List(fields.Str(), default=["wizard", "hogwarts", "dead"])


class UserPostView(SwaggerView):
    tags = ['users']
    parameters = User
    responses = {
        200: {
            'description': 'A single user item',
            'schema': User
        }
    }
    validation = True

    def post(self):
        """
        Example using marshmallow Schema
        validation=True forces validation of parameters in body
        ---
        # This value overwrites the attributes above
github flasgger / flasgger / examples / colors_with_schema.py View on Github external
# coding: utf-8
from flask import Flask, jsonify

from flasgger import Schema, Swagger, SwaggerView, fields


class Color(Schema):
    name = fields.Str()


class Palette(Schema):
    pallete_name = fields.Str()
    colors = fields.Nested(Color, many=True)


class PaletteView(SwaggerView):
    parameters = [
        {
            "name": "palette",
            "in": "path",
            "type": "string",
            "enum": ["all", "rgb", "cmyk"],
            "required": True,
            "default": "all"
        }
    ]
    # definitions = {'Palette': Palette, 'Color': Color}
    responses = {
        200: {
            "description": "A list of colors (may be filtered by palette)",
            "schema": Palette
        }
github gita / BhagavadGita / app / api / v1 / verse.py View on Github external
SELECT vt.meaning, vt.word_meanings, v.text, v.transliteration, v.chapter_number, v.verse_number, v.verse_order
                    FROM %s vt
                    JOIN verses v
                    ON
                    vt.chapter_number = v.chapter_number
                    AND vt.verse_number = v.verse_number
                    ORDER BY v.verse_order
                """ % (verses_table)

            verses = db.session.execute(sql)

        result = verses_schema.dump(verses)
        return jsonify(result.data)


class VerseListByChapter(SwaggerView):

    decorators = [csrf.exempt, oauth.require_oauth('verse')]
    definitions = {'VerseSchema': VerseSchema}

    def get(self, chapter_number):
        """
        Get all the Verses from a Chapter.
        Get a list of all Verses from a particular Chapter.
        ---
        tags:
        - verse
        parameters:
        - name: access_token
          in: query
          required: True
          type: 'string'
github gita / BhagavadGita / app / api / v1 / chapter.py View on Github external
# -*- coding: utf-8 -*-

from flasgger import SwaggerView
from flask import jsonify, request

from ... import csrf, db, oauth
from ...models.chapter import ChapterModel
from ...schemas.chapter import ChapterSchema

chapter_schema = ChapterSchema()
chapters_schema = ChapterSchema(many=True)

LANGUAGES = {'en': 'English', 'hi': 'हिंदी'}


class Chapter(SwaggerView):

    decorators = [csrf.exempt, oauth.require_oauth('chapter')]
    definitions = {'ChapterSchema': ChapterSchema}

    def get(self, chapter_number):
        """
        Get a specific chapter from the Bhagavad Gita.
        Get information about a specific chapter from the Bhagavad Gita.
        ---
        tags:
        - chapter
        parameters:
        - name: access_token
          in: query
          required: True
          type: 'string'
github flasgger / flasgger / examples / marshmallow_apispec.py View on Github external
app = Flask(__name__)
app.config['SWAGGER'] = {
    "title": "API using Marshmallow",
    "uiversion": 2
}

swag = Swagger(app)


class User(Schema):
    username = fields.Str(required=True)
    age = fields.Int(required=True, min=18)
    tags = fields.List(fields.Str())


class UserPostView(SwaggerView):

    parameters = User

    # parameters = [
    #     {
    #         'name': 'body',
    #         'in': 'body',
    #         'schema': User
    #     }
    # ]

    responses = {
        200: {
            'description': 'A single user',
            'schema': User
        }