Marshmallow: Adding location like header in Schema body

Created on 16 Mar 2020  路  2Comments  路  Source: marshmallow-code/marshmallow

So i need to add the authorization bearer model in the header part of a json request
can i validate it with the marshmallow schema?

question

Most helpful comment

If the headers structure inherits from the Mapping interface, marshmallow will consume it. If it doesn't, you will need to cast it to a dict first. You will probably need to set unknown=IGNORE unknown=EXCLUDE on the schema, since you probably don't want to declare the entire HTTP headers spec.

flask/werkzeug's Headers data structure does not inherit from Mapping, but casting it to a dict works fine.

All 2 comments

If the headers structure inherits from the Mapping interface, marshmallow will consume it. If it doesn't, you will need to cast it to a dict first. You will probably need to set unknown=IGNORE unknown=EXCLUDE on the schema, since you probably don't want to declare the entire HTTP headers spec.

flask/werkzeug's Headers data structure does not inherit from Mapping, but casting it to a dict works fine.

s/IGNORE/EXCLUDE

Was this page helpful?
0 / 5 - 0 ratings