flask_accepts icon indicating copy to clipboard operation
flask_accepts copied to clipboard

Add Swagger for supported marshmallow validators

Open BenC14 opened this issue 5 years ago • 8 comments
trafficstars

I am trying to add a string field to my Schema which uses the validate.OneOf() from marshmallow. I see the correct error response if I pass a bad option to this field but the Swagger UI does not have the helpful options in model description. Are there plans to add maps from the native marshmallow validators to the supported Flask-Restplus validators.

Screen Shot 2019-12-17 at 2 14 43 PM I was able to achieve this behavior using the api.model from Restplus

BenC14 avatar Dec 17 '19 19:12 BenC14

As a side thought one of the reasons this is so frustrating is the limitation that you cannot modify the fields generated by the for_swagger method if they come from a marshmallow schema. Obviously this is the main feature of the whole library so I can understand why it isn't a feature yet. However if there was a way to override or extend fields from the schema using the dict() parameters you would preserve the convenience of marshmallow schema's for the common case while allowing for slight modifications when you need to make a single field change. Just a thought.

BenC14 avatar Dec 17 '19 19:12 BenC14

There is also some semi-relevant discussion in #16

apryor6 avatar Dec 21 '19 12:12 apryor6

I am completely open to enabling this functionality. It was deprioritized previously due to being an outsized amount of work versus a smallish unlock, but if a increasing number of users have need for this then that priority goes up.

My bandwidth is nonexistent as of late, but if you’d like to take a stab I’m happy to comment/mentor/discuss through it.

apryor6 avatar Dec 21 '19 13:12 apryor6

My point of using swagger is that for internal/private app, I don't need to write docs alongside the app.

My web app had many fields with validate.OneOf() schema. They didn't show up in swagger. So the end-user can't know what are available options.

+1

azzamsa avatar Jun 05 '20 03:06 azzamsa

+1 for this feature

yujinyuz avatar Jun 12 '20 08:06 yujinyuz

Are there any workarounds for this to work?

yujinyuz avatar Jun 12 '20 08:06 yujinyuz

I don't see any way for a workaround without implementing the above mapping. If we mapped the validators in a similar fashion to how the fields are mapped from marshmallow to restx, then the docs should work. It will require a bit of dev work which I can't provide right now - but would be a great contribution opportunity.

apryor6 avatar Jun 12 '20 11:06 apryor6

+1 for this feature

eduardovra avatar Jul 18 '22 23:07 eduardovra