Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

swagger-Unrecognized response type; displaying content as text

I built a swagger using swagger-ui-express module for my node js backend. I have an endpoint that returns files ( pdf-doc or xlsx). When i test my endpoint on swagger it rturns me 200 response with always this message on body 'Unrecognized response type; displaying content as text.' This is my swagger endpoint's code.

endpoint response image

 "/reports?typeDoc={typeDoc}&file={file}": {
            "get": {
                "tags": [
                    "Generate report"
                ],
                "description": "",
                "operationId": "",
                "parameters": [
                    {
                        "name": "typeDoc",
                        "in": "path",
                        "description": "type of document",
                        "required": true,
                        "type": "string"
                    },
                    {
                        "name": "file",
                        "in": "path",
                        "description": "name of the file",
                        "required": true,
                        "type": "string"
                    }
                ],
                "responses": {
                    "200":{
                    "description": "Report generated succefully. ",
                    "content":{
                        "application/octet-stream":{
                            "schema":{
                                "type": "string",
                                "format": "binary"}
                        }
                    }
                    },
                    "500": {
                        "description": "Error in zip file structure or typeDoc"
                    }
                }
            }   
    }



like image 350
Mat Avatar asked Jun 06 '19 14:06

Mat


People also ask

What is swagger produce?

To specify the response media types, use the produces keyword on the root level or operation level. The global list can be overridden on the operation level. produces: - application/json. # This operation returns JSON - as defined globally above.


1 Answers

Try add headers like

content-disposition: attachment; filename = test.xlsx
content-type: multipart / form-data

and swagger-ui will understand the response type and offer download the file.

enter image description here

like image 182
Victor Borovlev Avatar answered Nov 14 '22 23:11

Victor Borovlev