jmcarp / flask-apispec

MIT License
655 stars 156 forks source link

use_kwargs(PetSchema) does not work (with test code) #217

Closed muffmolch closed 3 years ago

muffmolch commented 3 years ago

How do I get use_kwargs to work in this case:

class CatResource(MethodResource):

    @marshal_with(PetSchema)
    def get(self, pet_id):
        return Pet('calici', 'cat')

    @use_kwargs(PetSchema)   # <- HERE
    @marshal_with(PetSchema)
    def put(self, pet_id, **kwargs):
        return Pet('calici', 'cat')

Just replace the class in your example and test the put command within the swagger-ui

result:

TypeError: put() got an unexpected keyword argument 'type'

and in this case:

class CatResource(PetResource):
    @use_kwargs({'category': ma.fields.Int()})
    @marshal_with(PetSchema(), code=201)
    def get(self):
        return Pet('calici', 'cat'), 200

How do I access the kwargs? it seems **kwargs is missing in the parameter list. But:

class CatResource(PetResource):
    @use_kwargs({'category': ma.fields.Int()})
    @marshal_with(PetSchema(), code=201)
    def get(self,**kwargs):
        print( len(**kwargs) ) # --> 0 !!! even they have been snd
        return Pet('calici', 'cat'), 200

:-(

muffmolch commented 3 years ago

hmm... my fault.. I cpied the **kwargs at the wrong position :D