Sobes.tech
Middle

What request and response body formats does OpenAPI support?

sobes.tech AI

Answer from AI

OpenAPI does not restrict the formats of request and response bodies, but by default supports any formats that can be described through MIME types (Content-Type and Accept). The most commonly used are:

  • application/json — the most common format for REST APIs
  • application/xml — for XML data
  • application/x-www-form-urlencoded — for form data in requests
  • multipart/form-data — for file uploads

In the OpenAPI specification, supported formats can be explicitly specified in the content section for each endpoint, for example:

requestBody:
  content:
    application/json:
      schema:
        $ref: '#/components/schemas/Example'
responses:
  '200':
    content:
      application/json:
        schema:
          $ref: '#/components/schemas/ExampleResponse'

Thus, OpenAPI flexibly supports any formats if they are correctly described through MIME types and data schemas.

What request and response body formats does OpenAPI… - sobes.tech