Skip to content

FileUpload changes in generated curl request when adding a header using requestInterceptor #6082

@mike2184

Description

@mike2184

Q&A (please complete the following information)

  • OS: macOS
  • Browser: chrome
  • Version: 81.0.4044.138 (Official Build) (64-bit)
  • Method of installation: dist assets
  • Swagger-UI version: 3.10.0 (I've tried several versions and it happens with them all)
  • Swagger/OpenAPI version: Swagger 2.0 (Happens with both Swagger 2.0 and OpenAPI 3.0)

Content & configuration

I created an example project on github to demonstrate the issue. https://github.com/mike2184/swagger-ui-test
Swagger UI hosted on GItHub pages here: https://mike2184.github.io/swagger-ui-test/#/pet/uploadFile

Example Swagger/OpenAPI definition:
I'm using https://petstore.swagger.io/v2/swagger.json in the example I created to show this issue.

Swagger-UI configuration options:

const ui = SwaggerUIBundle({
				url : "./swagger.yaml",
				dom_id : '#swagger-ui',
				deepLinking : true,
				presets : [ SwaggerUIBundle.presets.apis,
						SwaggerUIStandalonePreset ],
				plugins : [ SwaggerUIBundle.plugins.DownloadUrl ],
				layout : "StandaloneLayout",
				requestInterceptor : function(req) {
					// Having the following line of code that adds a header causes the generated curl request to change from
					// -F "file=@cake.jpg;type=image/jpeg" to -d {"file":{}}
					req.headers['x-test-header'] = 'test value'; 
					return req;
				}
			})

Describe the bug you're encountering

If I make any changes to the headers using the requestInterceptor it changes the file upload in the generated curl request from -F "file=@cake.jpg;type=image/jpeg" to -d {"file":{}}

To reproduce...

Steps to reproduce the behavior:

  1. Go to https://mike2184.github.io/swagger-ui-test/#/pet/uploadFile
  2. Click Try it out for /pet/{petId}/uploadImage API
  3. Set petId to 1
  4. Click choose file and select any image file
  5. Click execute
  6. Notice: generated curl request has -d {"file":{}} instead of -F "file=@cake.jpg;type=image/jpeg"

Expected behavior

Generated curl request should be -F "file=@cake.jpg;type=image/jpeg"

Screenshots

Screen Shot 2020-06-04 at 8 50 24 AM

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions