How To Accept None For String Type Field When Using Flask-restplus
I am just starting develop with flask-restplus and I am not a native speaker, but I will try to describe my question as clear as I can. I know there is a fields module in flask th
Solution 1:
Yes, you can create a child class and use it instead of default ones, which will accept None as well
class NullableString(fields.String):
__schema_type__ = ['string', 'null']
__schema_example__ = 'nullable string'
So your code will look like
{ "property": NullableString(attribute=value)}
Additionally you can visit the issue github.com/noirbizarre/flask-restplus/issues/179
Solution 2:
if some of your fields are optional then make required=False
add_group = api.model(
"add_group",
{"team_groups": fields.List(fields.Nested(api.model("team_groups", {
"name": fields.String(example="chicago bulls", description="name of add group"),
"display_name": fields.String(example="bulls", description="display name of add group", required=False)})))})
Post a Comment for "How To Accept None For String Type Field When Using Flask-restplus"