How to use the flasgger.fields 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 / marshmallow_apispec.py View on Github external
from flask import Flask, jsonify, request

from flasgger import Schema, Swagger, SwaggerView, fields

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
    #     }
    # ]
github flasgger / flasgger / examples / apispec_example.py View on Github external
title='Flasger Petstore',
    version='1.0.10',
    openapi_version='2.0',
    plugins=[
        FlaskPlugin(),
        MarshmallowPlugin(),
    ],
)

app = Flask(__name__)


# Optional marshmallow support
class CategorySchema(Schema):
    id = fields.Int()
    name = fields.Str(required=True)


class PetSchema(Schema):
    category = fields.Nested(CategorySchema, many=True)
    name = fields.Str()


@app.route('/random')
def random_pet():
    """
    A cute furry animal endpoint.
    Get a random pet
    ---
    description: Get a random pet
    responses:
        200:
github flasgger / flasgger / examples / colors_with_schema.py View on Github external
"""
Example using Marshmallow Schema and fields as definitions
"""
# 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"
github flasgger / flasgger / examples / apispec_example_uiversion3.py View on Github external
title='Flasger Petstore',
    version='1.0.10',
    openapi_version='2.0',
    plugins=[
        FlaskPlugin(),
        MarshmallowPlugin(),
    ],
)

app = Flask(__name__)


# Optional marshmallow support
class CategorySchema(Schema):
    id = fields.Int()
    name = fields.Str(required=True)


class PetSchema(Schema):
    category = fields.Nested(CategorySchema, many=True)
    name = fields.Str()


@app.route('/random')
def random_pet():
    """
    A cute furry animal endpoint.
    Get a random pet
    ---
    description: Get a random pet
    responses:
        200:
github flasgger / flasgger / examples / apispec_example_uiversion3.py View on Github external
MarshmallowPlugin(),
    ],
)

app = Flask(__name__)


# Optional marshmallow support
class CategorySchema(Schema):
    id = fields.Int()
    name = fields.Str(required=True)


class PetSchema(Schema):
    category = fields.Nested(CategorySchema, many=True)
    name = fields.Str()


@app.route('/random')
def random_pet():
    """
    A cute furry animal endpoint.
    Get a random pet
    ---
    description: Get a random pet
    responses:
        200:
            description: A pet to be returned
            schema:
                $ref: '#/definitions/Pet'
    """
    pet = {'category': [{'id': 1, 'name': 'rodent'}], 'name': 'Mickey'}
github flasgger / flasgger / examples / apispec_example.py View on Github external
MarshmallowPlugin(),
    ],
)

app = Flask(__name__)


# Optional marshmallow support
class CategorySchema(Schema):
    id = fields.Int()
    name = fields.Str(required=True)


class PetSchema(Schema):
    category = fields.Nested(CategorySchema, many=True)
    name = fields.Str()


@app.route('/random')
def random_pet():
    """
    A cute furry animal endpoint.
    Get a random pet
    ---
    description: Get a random pet
    responses:
        200:
            description: A pet to be returned
            schema:
                $ref: '#/definitions/Pet'
    """
    pet = {'category': [{'id': 1, 'name': 'rodent'}], 'name': 'Mickey'}