cancel
Showing results for 
Search instead for 
Did you mean: 

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

rsaw
Occasional Visitor

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 1
HKosova
Moderator

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

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.


Helen Kosova
SmartBear Documentation Team Lead
________________________
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
New Here?
Join us and watch the welcome video: