Interactive API Docs 'Try it out!' 502 Bad Gateway
SOLVED- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Interactive API Docs 'Try it out!' 502 Bad Gateway
Hi,
I have an API that I'm describing on "swaggerhub.com."
When I send post request with parameters in json body using 'Try it out!' operation, it returns:
Response Body
<h1>Bad Gateway</h1>
Response Code
502
Response Headers
{
"cache-control": "no-cache, no-store, must-revalidate",
"content-type": "text/html; charset=UTF-8",
"date": "Wed, 04 May 2016 07:04:10 +0000",
"server": "nginx/1.8.0 + Phusion Passenger 5.0.22",
"status": "502 Bad Gateway",
"content-length": "20",
"connection": "keep-alive"
}
Here is the specification of this request:
/login: post: summary: "Some summary" description: "Some description" operationId: login parameters: - name: "Accept" in: header type: string default: "application/json" - name: "Content-Type" in: header type: string default: "application/json; charset=utf-8" - name: body in: body required: true schema: $ref: '#/definitions/login' responses: '200': description: "OK" schema: $ref: '#/definitions/apiVersion' '400': description: "Bad request." schema: $ref: '#/definitions/commonError' '403': description: "Forbidden."
Here is definitions:
definitions: login: type: object required: - key - secret properties: key: type: string secret: type: string apiVersion: type: object properties: name: type: string version: type: string
sessionId:
type: string
When I use curl it returns exactly what I need.
When I send incorrect parameters it returns error responses that I expect.
I cant find where is the problem.
Is there something I am doing wrong? Thanks in advance for your assistance.
Nikita.
Solved! Go to Solution.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Nikita,
Not sure... your spec seems fine, and I can't reproduce. But that just means, something else is not right 🙂
I'll ask our spec, expert.
In the meantime, have you set up the 'host', 'schemes' and if necessary 'basePath' properties? They help with determining the URL and protocol to use.
We'll get back to you here....
Thanks for the query,
Josh
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
So our spec-expert has come back...
And it turns out we'll get a 502 Bad Gateway, if the host cannot be reached from our servers.
Take a look at the 'host' property here... https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#swagger-object and hopefully that'll help.
Otherwise, just let us know if it persists.
A quick example...
swagger: '2.0' host: 'www.example.com' schemes: - http - https basePath: '/v1'
Will produce... 'http://www.example.com/v1/...;
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have set up "schemes", "host" and "basePath". URL and protocol are correct.
My spec looks like this:
swagger: '2.0' schemes: - https host: demo.example.co basePath: /myappexample/api/v1
502 Returns to me only when my parameters in body are correct and I expect to recieve 200 OK. When my parameters are incorrect (empty or missing) I receive expected responses with my web app's errors in response body.
Besides some other simple GET requests works fine. And when I paste proposed curl to my command line it works fine too.
When I use curl response looks like this:
HTTP/1.1 200 OK Server: nginx/1.6.2 Date: Wed, 04 May 2016 12:27:34 GMT Content-Type: application/json;charset=UTF-8 Transfer-Encoding: chunked Connection: keep-alive X-XSS-Protection: 1; mode=block X-Frame-Options: DENY Content-Security-Policy: default-src 'self' 'unsafe-inline' 'unsafe-eval' https://setronica.atlassian.net https://gdata.youtube.com www.google-analytics.com https://www.googleapis.com https://www.youtube.com http://www.youtube.com; img-src 'self' data: https://www.gravatar.com https://setronica.atlassian.net https://www.paypalobjects.com www.google-analytics.com; object-src 'self' https://www.googleapis.com https://www.youtube.com www.google-analytics.com; Pragma: no-cache Expires: Thu, 01 Jan 1970 00:00:00 GMT Cache-Control: no-cache Cache-Control: no-store Set-Cookie: JSESSIONID=6963E2C98E063E751820DA8A33EB1197; Path=/myappexample/; HttpOnly { "name" : "MyApp API", "version" : "1.0" }
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
My spec looks like your example.
Some of my simple GET requests works fine, for other requests I get 403 (as expected), that's why I think that my URL and protocol are correct.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Is your API public? If so, can we get a link to its SwaggerHub definition?
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others.↓↓↓↓↓
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for the details. We're investigating and will get back to you.
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others.↓↓↓↓↓
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Still haven't found the issue, but will be spending more time on this soon.
Josh
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hey Nikita,
After some digging, we found the issue.
Our proxy was forwarding the "Transfer-Encoding" header, which clashed with the "Content-Length" header in our proxied response.
We've added a fix, and it will be released soon, with our next roll-out.
Thanks for hanging in there!
Josh
