How does Connexion set the response content type?

Solution 1:

If you want your function to decide dynamically which content-type to return, you have to set the header explicitly as explained in the documentation.

One of the two methods is to return a tuple of the content, the return code and a dictionary of headers like this:

def post_order(platform, open_req=None): 
    """order

    """
    return 'do some magic!', 200, {'content-type': 'text/plain'}

The second method is to create a response object explicitly and return that:

from connexion.lifecycle import ConnexionResponse

def post_order(platform, open_req=None): 
    """order

    """
    return ConnexionResponse(
        status_code=200,
        content_type='text/plain',
        body='do some magic!'
    )

This gives you more control for other adjustments. But it is not necessary if the simple tuple solution works in your case.