type: file is not allowed in body parameter
See original GitHub issueThe 2.0 spec says
An additional primitive data type “file” is used by the Parameter Object and the Response Object to set the parameter type or the response as being a file.
The JSON schema for OpenAPI 2.0 allows type: file
in the schema for a response body.
"schema": {
"oneOf": [
{
"$ref": "#/definitions/schema"
},
{
"$ref": "#/definitions/fileSchema"
}
]
but fileSchema
is not included in the schema for parameter with in: body
:
"bodyParameter": {
"type": "object",
"required": [
"name",
"in",
"schema"
],
"patternProperties": {
"^x-": {
"$ref": "#/definitions/vendorExtension"
}
},
"properties": {
"description": {
"type": "string",
"description": "A brief description of the parameter. This could contain examples of use. GitHub Flavored Markdown is allowed."
},
"name": {
"type": "string",
"description": "The name of the parameter."
},
"in": {
"type": "string",
"description": "Determines the location of the parameter.",
"enum": [
"body"
]
},
"required": {
"type": "boolean",
"description": "Determines whether or not this parameter is required or optional.",
"default": false
},
"schema": {
"$ref": "#/definitions/schema"
}
},
Thus, the following OpenAPI document does not pass schema validation.
swagger: "2.0"
info:
title: Issue 1226
description: 'type: file not allowed for body parameter '
version: "1"
basePath: /issue-1126
paths:
/issues:
post:
summary: Create a resource from the body
consumes:
- application/zip
produces:
- application/zip
parameters:
- name: content
in: body
required: true
description: A zip file of the contents.
schema:
type: file
responses:
201:
description: Created.
schema:
type: file
headers:
Location:
description: location of the new resource
type: string
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
parameter is not of type 'Blob' - javascript - Stack Overflow
The one that the error message is complaining about is that you are trying to select a file using a hard coded string....
Read more >Why can't one use a "schema" or "type=object" for formData ...
If it's not obvious, the reason is because we need to allow sending files in the request body so we can't just have...
Read more >File Upload - Swagger
The operation payload is defined using formData parameters (not body parameters). The file parameter must have type: file :.
Read more ><input type="file"> - HTML: HyperText Markup Language | MDN
When a file is chosen using an <input type="file"> , the real path to the source file is not shown in the input's...
Read more >HTTP/1.1: Header Field Definitions
Note: Use of the "q" parameter name to separate media type parameters from ... If the choice is not made available, then the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Found a temporary workaround from https://github.com/OAI/OpenAPI-Specification/issues/326
However, the code generation would produce
byte[]
instead of nicerStream
class.Moving forward, I would suggest that tooling use
stream
for this description and where amaxLength
is providedbyte[]
could be used instead.