Skip to content

Wrong input type in multi-file upload #5656

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
eduherminio opened this issue Oct 10, 2019 · 5 comments
Closed

Wrong input type in multi-file upload #5656

eduherminio opened this issue Oct 10, 2019 · 5 comments

Comments

@eduherminio
Copy link

Q&A

  • Browser: chrome, mozilla
  • Swagger-UI version: Swashbuckle.AspNetCore.SwaggerUI v4.0.1
  • Swagger/OpenAPI version: OpenAPI 3.0

Content & configuration

        [HttpPost]
        public string UploadFiles(ICollection<IFormFile> files)
        {
            return "";
        }

Example Swagger/OpenAPI definition:

    "/api/File": {
      "post": {
        "tags": [
          "File"
        ],
        "operationId": "UploadFiles",
        "consumes": [
          "multipart/form-data"
        ],
        "produces": [
          "text/plain",
          "application/json",
          "text/json"
        ],
        "parameters": [
          {
            "name": "files",
            "in": "formData",
            "required": false,
            "type": "array",
            "items": {
            },
            "collectionFormat": "multi",
            "uniqueItems": false
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "schema": {
              "type": "string"
            }
          }
        }
      }
    },

Swagger-UI configuration options:

From Swashbuckle.AspNetCore.SwaggerUI

app.UseSwaggerUI(c => c.SwaggerEndpoint($"/swagger/{SwaggerDocumentVersion}/swagger.json", $"{SwaggerDocumentVersion} docs"));

Describe the bug you're encountering

Input type is text rather than file when a method receives muliple files (either IEnumerable<IFormFile> or IFormFileCollection) as argument.

Current behavior

real

Expected behavior

expected

@eduherminio
Copy link
Author

Related: OAI/OpenAPI-Specification#254

@webron
Copy link
Contributor

webron commented Oct 17, 2019

@eduherminio Please provide a full definition and not a snippet to help test the issue.

@eduherminio
Copy link
Author

        [HttpPost("{userId}/{id}")]
        public async Task<string> UploadFiles(int userId, string id, ICollection<IFormFile> files)
        {
            // ...
        }

        [HttpPost("test")]
        public async Task<string> UploadFile(IFormFile file)
        {
            // ....
        }
{
	"swagger": "2.0",
	"info": {
		"version": "4.0.1.0",
		"title": "Test_Poc API",
		"description": "Test_Poc API",
		"termsOfService": "Test Limited, registered in England and Wales, Company no. XXXXXXXX",
		"contact": {
			"name": "Test"
		},
		"license": {
			"name": "All rights restricted"
		}
	},
	"paths": {
		"/api/File/{userId}/{id}": {
			"post": {
				"tags": [
					"File"
				],
				"summary": "Uploads multiple files -> buggy",
				"operationId": "UploadFiles",
				"consumes": [
					"multipart/form-data"
				],
				"produces": [
					"text/plain",
					"application/json",
					"text/json"
				],
				"parameters": [
					{
						"name": "userId",
						"in": "path",
						"description": "",
						"required": true,
						"type": "integer",
						"format": "int32"
					},
					{
						"name": "id",
						"in": "path",
						"description": "File group identifier",
						"required": true,
						"type": "string"
					},
					{
						"name": "files",
						"in": "formData",
						"description": "",
						"required": false,
						"type": "array",
						"items": {},
						"collectionFormat": "multi",
						"uniqueItems": false
					}
				],
				"responses": {
					"200": {
						"description": "Success",
						"schema": {
							"type": "string"
						}
					}
				}
			}
		},
		"/api/File/test": {
			"post": {
				"tags": [
					"File"
				],
				"summary": "Single file upload",
				"operationId": "UploadFile",
				"consumes": [
					"multipart/form-data"
				],
				"produces": [
					"text/plain",
					"application/json",
					"text/json"
				],
				"parameters": [
					{
						"name": "file",
						"in": "formData",
						"description": "",
						"required": false,
						"type": "file"
					}
				],
				"responses": {
					"200": {
						"description": "Success",
						"schema": {
							"type": "string"
						}
					}
				}
			}
		}
	}
}

@webron
Copy link
Contributor

webron commented Oct 18, 2019

@eduherminio - that's OpenAPI (Swagger) 2.0, not OpenAPI 3.0. The 2.0 version does not support multi file uploads.

@eduherminio
Copy link
Author

Oops, totally right @webron, I'll close this and create a new one if I experience issues once I configure the project to use 3.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants