pistacchio
pistacchio

Reputation: 58893

Flask RestPlus: Add expected headers AND model

I'm using @api.expect(MyModel, validate=True) in order to validate the input json of a post request again a custom model. I've created the model with MyModel = api.model('MyModel', {...}).

I also want to add a required (expected) header to be handled and validated by the request. I can do this:

parser = api.parser()
parser.add_argument('X-Authentication', location='headers')
[...]
@api.expect(parser)

But how can I expect and validate a model and a header since api.parser and add_argument lets me add headers but doesn't seem to handle a "add this model as body payload" while api.model doesn't let me add headers?

Upvotes: 1

Views: 1056

Answers (1)

amark
amark

Reputation: 79

I believe you should be able to do this using @ns.doc

@ns.doc(body=some_model, parser=some_parser)

Upvotes: 3

Related Questions