Those principle are the basic on how it should generate different requests under an operation. It is much more meaningful for OpenAPI3 where contentType => body type In swagger as it is multiple content types mapping to a single body types there is a few special cases. With that in mind those are the additional rules for Swagger 2.0:
type: string, format: binary
, type: string, format: file
, ) then there will be a single request that takes in binary data and what content type the data is regardless of the content types. (See Scenario 1)text/plain
always assume the body is string
See Scenario 3, Scenario 4 and Scenario 5application/json
produces an request taking in the schema defined for the body Scenario 2, Scenario 3 and Scenario 4binary
Scenario 3, Scenario 4As explained in the principles above Swagger 2.0 intrepretation is a little more complex. Here are a few scenarios and how they are treated.
Swagger:
consumes:
- "application/json"
- "application/octet-stream"
- "image/png"
- "text/plain"
parameters:
- in: body
name: body
schema:
type: string
format: binary
Modelerfour:
- schema: binary
contentTypes:
- "application/json"
- "application/octet-stream"
- "image/png"
- "text/plain"
Generated operations:
function myOp(body: Stream, contentType: "application/json" | "application/octet-stream" | "image/png" | "text/plain");
application/json
object in bodySwagger:
consumes:
- "application/json"
parameters:
- in: body
name: body
schema:
type: object
properties: { $ref: MySchema }
Modelerfour:
schema: MySchema
contentTypes:
- "application/json"
Generated operations:
function myOp(body: MySchema); // Sent as application/json
Swagger:
consumes:
- "application/json"
- "application/octet-stream"
- "image/png"
- "text/plain"
parameters:
- in: body
name: body
schema:
type: object
properties: { $ref: MySchema }
Equivalent OpenAPI3:
requestBody:
application/json:
type: object
properties: { $ref: MySchema }
application/octet-stream:
type: object
properties:
type: string
format: binary
image/png:
type: object
properties:
type: string
format: binary
text/plain:
type: object
properties:
type: string
Modelerfour:
requests:
- schema: MySchema
contentTypes:
- "application/json"
- schema: binary
contentTypes:
- "application/octet-stream"
- "image/png"
- schema: string
contentTypes:
- "text/plain"
Generated operations:
function myOp(body: MySchema); // Sent as application/json
function myOp(body: stream, contentType: "application/octet-stream" | "image/png" | string);
function myOp(body: string); // Sent as text/plain
Swagger:
consumes:
- "application/json"
- "application/octet-stream"
- "image/png"
- "text/plain"
parameters:
- in: body
name: body
schema:
type: string
Modelerfour:
- schema: string
contentTypes:
- "application/json"
- "text/plain"
- schema: binary
contentTypes:
- "application/octet-stream"
- "image/png"
Generated operations:
function myOp(body: string, contentType: "application/json" | "text/plain" | string);
function myOp(body: stream, contentType: "application/octet-stream" | "image/png" | string);
text/plain
content typeconsumes:
- "text/plain"
parameter:
body:
type: string
Modelerfour:
- schema: string
contentTypes:
- "text/plain"
Generated operations:
function myOp(body: string); // Sent as text/plain
consumes:
- "multipart/form-data"
parameter:
- in: formData
type: string
format: binary
name: file
- in: formData
name: filename
type: string
requests:
- parameters:
- schema: binary
name: file
- schema: string
name: filename
contentTypes:
- "multipart/form-data"
Generated operations:
function myOp(file: Stream, filename: string); // Sent as multipart/form-data
application/octet-stream
single file paramconsumes:
- "multipart/form-data"
- "text/plain"
- "application/octet-stream"
parameter:
- in: formData
type: string
format: binary
name: file
requests:
- parameters:
- schema: binary
name: file
contentTypes:
- "multipart/form-data"
- "application/octet-stream"
- parameters:
- schema: string
name: body
contentTypes:
- "text/plain"
Generated operations:
function myOp(file: Stream, contentType: "multipart/form-data" | "application/octet-stream" | string);
function myOp(file: string); // sent as text/plain
application/octet-stream
multi file paramNOT SUPPORTED