Forum Discussion

ngolubchuk's avatar
ngolubchuk
Occasional Contributor
9 years ago

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.

  • Hi Nikita,

     

    Just a note: we've deployed to production with several fixes, including the try-it-out fixes we've been going over with you.

     

    Thanks for pointing them out, it really helps!

     

    Have an awesome weekend,

    Josh

  • 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

    • ponelat's avatar
      ponelat
      Staff

      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/...;

      • ngolubchuk's avatar
        ngolubchuk
        Occasional Contributor

        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.

    • ngolubchuk's avatar
      ngolubchuk
      Occasional Contributor

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