I have a service that creates a multipart file containing:
Is it possible to model this custom response in an OpenAPI (Swagger) definition, using YAML?
You start with the requestBody/content keyword. Then, you specify the media type of request data. File uploads typically use the multipart/form-data media type, and mixed-data requests usually use multipart/mixed . Below the media type, put the schema keyword to indicate that you start describing the request payload.
a multipart request is a REST request containing several packed REST requests inside its entity. a multipart response is a REST response containing several packed REST responses inside its entity.
Multipart responses can be described using OpenAPI 3.0, but not OpenAPI 2.0 (fka Swagger 2.0).
openapi: 3.0.0
...
paths:
/something:
get:
responses:
'200':
description: OK
content:
multipart/mixed: # <-- Content-Type of the response
schema:
type: object
properties:
# Part 1 - application/octet-stream
file: # <-- part name
type: string
format: binary
# Part 2 - application/json
metadata: # <-- part name
type: object
properties:
foo:
type: string
example: bar
required:
- foo
# Optional, see https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md#encoding-object
encoding:
file:
...
metadata:
...
The optional encoding
key can be used to override the Content-Type
for subparts or add headers for subparts (e.g. Content-Disposition
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With