Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swagger 'GET' request always returns as text/html Accept type on response and NOT application/json

I have a swagger tag document using the Swagger UI that always returns text/html but it should return application/json. The POST requests and every other type returns application/json but this particular GET request does not. The service end point code is correct. And if I change the request to POST it does return as application/json. So it is just type GET within swagger which does not return the correct type. Any thoughts how to correct the call within the UI to use the application/json?

This is swagger version 2.1.4 that was downloaded recently from the swagger site.

"/bankName": {
    "get": {
        "summary": "Bank Name Search",
        "description": "Bank Name Search, input routing number to return bank name",                
        "consumes": [    
            "application/json"
        ],    
        "produces": [
            "application/json"
        ],                                 
        "parameters": [
            {
                "in": "query",                          
                "name": "routingNumber",
                "description": "Input Bank Routing Number",
                "required": true,   
                "type": "string",                           
            }
        ],
        "responses": {
            "200": {
                "description": "An array",
                "schema": {
                    "type": "object",
                    "properties": {
                        "errorInfo": { 
                            "$ref": "#/definitions/ErrorInfo"                   
                        },
                        "bankName": {
                            "type": "string",                                   
                        }
                    }
               }                        
            },
            "400": {
                "description": "Invalid Request Input supplied"                         
            },                  
            "500": {
                "description": "General Unexpected Error"
            }                       
        }
    }
}  

Accept:application/json

Accept-Encoding:gzip, deflate, sdch

Accept-Language:en-US,en;q=0.8

Cache-Control:no-cache

Connection:keep-alive

Host:localhost:9086

Origin:http://localhost:9086

Pragma:no-cache

Referer:http://localhost:9086/swagger/index.html

Here is the Java code Spring Restful definition:

@RequestMapping(value="bankName",
    method=RequestMethod.GET,
    produces=MediaType.APPLICATION_JSON_VALUE)
like image 577
Berlin Brown Avatar asked Apr 06 '16 13:04

Berlin Brown


People also ask

Which functionality of Swagger should be used to display in the documentation?

The major Swagger tools include: Swagger Editor – browser-based editor where you can write OpenAPI definitions. Swagger UI – renders OpenAPI definitions as interactive documentation. Swagger Codegen – generates server stubs and client libraries from an OpenAPI definition.


1 Answers

Have you tried this?

"/bankName": {
    "get": {
        "summary": "Bank Name Search",
        "description": "Bank Name Search, input routing number to return bank name",                
        "consumes": [    
            "application/json"
        ],    
        "produces": [
            "application/json"
        ],                                 
        "parameters": [
            {
                "in": "query",                          
                "name": "routingNumber",
                "description": "Input Bank Routing Number",
                "required": true,   
                "type": "string",                           
            }
        ],
        "responses": {
            "200": {
                "description": "An array",
                "content": {
                    "application/json": {
                        "schema": {
                            "type": "object",
                            "properties": {
                                "errorInfo": { 
                                    "$ref": "#/definitions/ErrorInfo"                   
                                },
                                "bankName": {
                                    "type": "string",                                   
                                }
                            }
                        }
                    }
                }
            },
            "400": {
                "description": "Invalid Request Input supplied"                         
            },                  
            "500": {
                "description": "General Unexpected Error"
            }                       
        }
    }
}  
like image 101
klmdbase Avatar answered Sep 18 '22 22:09

klmdbase