简体   繁体   中英

Python Connexion: Automatically validate Accept header

I'm using the Connexion framework for my Python Flask project. In the API spec (using the yaml file format) I defined "consumes" and "produces" field like this:

produces:
   - application/json
consumes:
   - application/json

The Connexion documentanation says that Connexion automatically validates the request based on the API specification, so I thought that it would automatically verify that incoming "Accept" (or "Content-Type") headers would match "application/json" using the above data as example.

However, this doesn't seem to be the case. If I omit the Accept header and Content-Type header, or add them with random values, there are no warnings or errors or anything.

Have other Connexion users gotten Connexion to validate media types data? Or do you handle this explicitly in your code?

EDIT: Seems like this bug report addresses this issue.

I'm using the versions:

  • connexion == 1.5.3 swagger
  • spec-validator == 2.4.0

When I execute an operation in this scenario where I wait for "application/json" and send a different Content I get a 415 with the body:

{ "detail": "Invalid Content-type (application/javascript), expected JSON data", "status": 415, "title": "Unsupported Media Type", "type": "about:blank" }

In this case i sent a request with the Content "application/javascript"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM