Forum Discussion

rsaw's avatar
rsaw
Occasional Visitor
3 years ago

Does openapi 3 allow 200 response text/plain &&& 401 response application/json?

Given any version of the spec (I'm using 3.0.3, but would be happy to change that to whatever), and given a particular path & method, e.g., post to /auth, does the openapi spec have anything to say about whether it is allowed for a 200 response to be text/plain while other error responses are of type application/json?

 

I'm using a yaml definition with the Python Connexion framework . I've posted an issue on their github to see if anyone has ideas about whether it's a bug in the framework; however, I was hoping someone here might be able to say whether the spec has an opinion on this.

1 Reply

  • HKosova's avatar
    HKosova
    SmartBear Alumni (Retired)

    Yes, OpenAPI 3 supports this. Media type and schemas can vary per HTTP status code, and it's even possible to define multiple media types with different schemas for the same status code. For example, this is a valid OpenAPI 3 definition:

     

          responses:
            '200':
              description: Plain text or XML
              content:
                text/plain:
                  schema:
                    type: string
                application/xml:
                  schema:
                    ...
          responses:
            '401':
              description: Unauthorized
              content:
                application/json:
                  schema:
                    ...

     

    The issue you're seeing seems to be a bug or limitation of the Connexion framework. Please follow up with them to troubleshoot the issue.