cancel
Showing results for 
Search instead for 
Did you mean: 

Add Upload button for OpenAPI 2.0 file as Octet-Stream

SOLVED
Highlighted
New Contributor

Add Upload button for OpenAPI 2.0 file as Octet-Stream

Context

  • I am using OpenAPI ver 2.0
  • I have API which consumes application/octet-stream (Java InputStream)

Issue

In OpenAPI ver 2.0 I can only set input type as multipart/form-data (link) to have upload button. When I have applied this solution for my swagger:
<code>
"consumes": [ "multipart/form-data" ],
"produces": [ "application/json" ],
"parameters": [ {
"in": "formData",
"name": "messageFile",
"description": "Description...",
"required": true,
"type": "file"
} ]

</code>

 

I am getting following error: Unsupported Media Type after sending a file - it is normal due to my API wants octet-stream.

 

Question

Is it possible to have upload button using OpenAPI ver 2.0 and application/octet-stream like:

mDVCb.png

 

If no, then what will be better solution / workaround for this? 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Moderator

Re: Add Upload button for OpenAPI 2.0 file as Octet-Stream

Not out of the box. You can try forking Swagger UI and implementing this non-standard functionality yourself. But the proper solution is to use OpenAPI 3.0. If you write the API definition manually (rather than generate it from code), there are OpenAPI 2.0-to-3.0 converters to help you with the migration.


Helen Kosova
SmartBear Documentation Team Lead
________________________
Learn SmartBear products in a fun and easy way and prove your knowledge!
>>Participate in the TechCorner Challenge today

View solution in original post

3 REPLIES 3
Highlighted
Moderator

Re: Add Upload button for OpenAPI 2.0 file as Octet-Stream

OpenAPI 2.0 does not support application/octet-stream in the request body, it only supports file upload via multipart/form-data.

 

To define application/octet-stream request bodies you need OpenAPI 3.0:

 

openapi: 3.0.0
...
paths:
  /something:
    post:
      requestBody:
        required: true
        content:
          application/octet-stream:
            schema:
              type: string
              format: binary

 

See also: File upload in OpenAPI 3.0


Helen Kosova
SmartBear Documentation Team Lead
________________________
Learn SmartBear products in a fun and easy way and prove your knowledge!
>>Participate in the TechCorner Challenge today
Highlighted
New Contributor

Re: Add Upload button for OpenAPI 2.0 file as Octet-Stream

And there is no solution which could cause that we will be able to upload files as octet-stream using OpenAPI 2.0 and some component to attach file🙂

Highlighted
Moderator

Re: Add Upload button for OpenAPI 2.0 file as Octet-Stream

Not out of the box. You can try forking Swagger UI and implementing this non-standard functionality yourself. But the proper solution is to use OpenAPI 3.0. If you write the API definition manually (rather than generate it from code), there are OpenAPI 2.0-to-3.0 converters to help you with the migration.


Helen Kosova
SmartBear Documentation Team Lead
________________________
Learn SmartBear products in a fun and easy way and prove your knowledge!
>>Participate in the TechCorner Challenge today

View solution in original post

New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors