Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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 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
"""
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 = {