flasgger/flasgger

Use python 3.7 new dataclass to specify Schema

Open

#204 aberto em 28 de jun. de 2018

Ver no GitHub
 (2 comments) (13 reactions) (0 assignees)Python (3.435 stars) (500 forks)batch import
enhancementhacktoberfesthelp wanted

Description

With the new python 3.7 dataclass (https://www.python.org/dev/peps/pep-0557/)

It would be nice to automatically infer the response schema from it , instead of:

from marshmallow import Schema, fields, post_load
from flasgger import Swagger, SwaggerView

class FooSchema(Schema):
    url = fields.Str(required=True)

class FooView(SwaggerView):
    responses = {
        200: {
            'description': 'Foo Example',
            'schema': FooSchema
        }
    }
    . . . . 

do

from flasgger import Swagger, SwaggerView

@dataclass
class Foo:
    url: str

class FooView(SwaggerView):
    responses = {
        200: {
            'description': 'Foo Example',
            'schema': Foo
        }
    }
    . . . . 

Guia do colaborador