Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write a response for an MP3 file in OpenAPI YAML?

Tags:

openapi

I am writing an API YAML that returns an MP3 file. I am not familiar with multimedia responses. While going through Google I found that I can use the audio/mp3 content type. But I couldn't find any example showing how to do it. How should I address this audio content type?

like image 358
Shibin Avatar asked Oct 30 '25 21:10

Shibin


1 Answers

OpenAPI 3.1

A binary file response is defined with just the media type and no schema:

openapi: 3.1.0
...

paths:
  /something:
    get:
      responses:
        '200':
          description: An audio file
          content:
            audio/mp3: {}

OpenAPI 3.0

Files are defined as binary strings (type: string + format: binary):

openapi: 3.0.3
...

paths:
  /something:
    get:
      responses:
        '200':
          description: An audio file
          content:
            audio/mp3:
              schema:
                type: string
                format: binary

OpenAPI 2.0

Binary file responses are defined with a type: file schema. Make sure to also specify the media type in the operation's produces list:

swagger: '2.0'
...

paths:
  /something:
    get:
      produces:
        - audio/mp3
      responses:
        200:
          description: An audio file
          schema:
            type: file
like image 170
Helen Avatar answered Nov 01 '25 12:11

Helen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!