flask_accepts
flask_accepts copied to clipboard
Add Swagger for supported marshmallow validators
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.
I was able to achieve this behavior using the api.model from Restplus
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.
There is also some semi-relevant discussion in #16
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.
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
+1 for this feature
Are there any workarounds for this to work?
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.
+1 for this feature