question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

type: file is not allowed in body parameter

See original GitHub issue

The 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:closed
  • Created 6 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
jemeraldcommented, Jul 21, 2017

Found a temporary workaround from https://github.com/OAI/OpenAPI-Specification/issues/326

schema:
  type: string
  format: binary

However, the code generation would produce byte[] instead of nicer Stream class.

1reaction
darrelmillercommented, Jul 21, 2017

Moving forward, I would suggest that tooling use stream for this description and where a maxLength is provided byte[] could be used instead.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found