Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"""
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"
}
]
# definitions = {'Palette': Palette, 'Color': Color}
responses = {
200: {
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:
description: A pet to be returned
schema:
$ref: '#/definitions/Pet'
"""
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:
description: A pet to be returned
schema:
$ref: '#/definitions/Pet'
"""