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.

 "/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"
                    }
                }
            }   
    }
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.
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.

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With