Description
- connexion
3.1.0
- Flask
3.1.1
- Python
3.13.3
Background
I am using response validation.
I have an application endpoint that streams a file to the client. The application runs successfully using pre-v3 connexion but only works in v3 when I disable response validation.
I can appreciate that my existing spec may be incorrect or incomplete, but it has worked for several years and many application iterations. After taking the plunge and migrating to connexion v3 I am unable to get past response validation, having tried many things and now have to resort to disabling response validation to get a working application.
Code example
Here's an excerpt from my API definition (minimal content for clarity): -
/project/{project_id}/file:
get:
responses:
"200":
description: >
The file
When I call this endpoint the app attempts to return a file with flask: -
# ...and just use flask to construct a response to return the file
response = flask.send_from_directory(
file_directory,
project_file,
as_attachment=True,
download_name=project_file,
)
But, in v3, I get the following error: -
exceptions.problem_handler():79 ERROR # NonConformingResponseHeaders(status_code=500, detail="Invalid Response Content-type (application/octet-stream), expected ['application/json', 'application/json']")
Attempting to fix with response content schema
In my naive attempt to fix the error, in one attempt to avoid the error I have tried to define the response using this refined endpoint definition (again, minimal content for clarity): -
/project/{project_id}/file:
get:
responses:
"200":
description: >
The file
content:
application/octet-stream:
schema:
type: string
format: binary
But this leads to a different error: -
Multiple response content types are defined in the operation spec, but the handler response did not specify which one to return.
Question
I am not sure what "multiple" means in my case. I am only defining one content type so I can only assume connexion is adding its own (built-in/default) values to the one I define? If so telling me "multiple content types are defined" seems, to me, to be misleading - surely only one content type defined? i.e. if I define one, please don't infer anythign else.
Regardless...
If I want to return an octet stream using the flask.send_from_directory()
method illustrated above, how do I avoid response validation errors?
Basically, what am I not doing properly to satisfy v3 response validation?