0

I have the following OpenAPI definition hosted on SwaggerHub:
https://app.swaggerhub.com/apis/MyFirstAPI/1.0.1-oas3

openapi: 3.0.0
servers:
  - url: http://api.myfirstapi.com/
info:
  version: 1.0.1-oas3
  title: Equ API
paths:
  /query:
    get:
      tags:
        - developers
      parameters:
        - in: query
          name: searchString
          schema:
            type: string
      responses:
        '200':
          description: search results matching criteria
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/Equity'
        '400':
          description: There is 400
components:
  schemas:
    Equity:
      ...

When I test the GET /query request, it returns a 403 error:

content-length: 0 
date: Fri,10 Sep 2021 14:32:54 GMT 
server: nginx/1.18.0 + Phusion Passenger(R) 6.0.8 
status: 403 Forbidden 
via: 1.1 b5d86079363e9709b4c4051d3c94ac3d.cloudfront.net (CloudFront) 
x-amz-cf-id: pYbLwlrEHg5DXkGe5FkysAjSjbSDqUg7Rrhbv-Dt8Xwt8JuPRMAW3Q== 
x-amz-cf-pop: DEL54-C1 
x-cache: Error from cloudfront 
x-powered-by: Express,Phusion Passenger(R) 6.0.8

Why does this error happen and how to fix it?

  • Need more details. What tool do you use to test the request - Swagger UI, Postman, something else? If the API you're testing is public - please add the request URL and parameters in your question. 403 response indicates a permission error - did you include the proper authentication info in the request? – Helen Sep 10 '21 at 16:37

1 Answers1

0

This 403 error is somewhat misleading. The actual problem here is that the target server for requests - api.myfirstapi.com - does not actually exist. The servers list is supposed to specify your real server(s).

If you are designing a new API and don't have a live server yet, you can use SwaggerHub's mock server to similate responses and test API calls.

To add a mock to your API definition:

  1. Click the API name on the editor toolbar.
  2. Switch to the Integrations tab and click Add New Integrations. SwaggerHub: Adding a new API-level integration
  3. Select API Auto Mocking from the list and click Add.
  4. Enter any value for Name (e.g. mock), leave other options as is, and click Create and Execute.
  5. Close the remaining dialogs.

This creates a mock server for your API and adds it to the servers list in your API definition:

servers: 
  - description: SwaggerHub API Auto Mocking
    url: https://virtserver.swaggerhub.com/OWNER_NAME/API_NAME/VERSION

Make sure to select this server in the API docs before you test API calls.

SwaggerHub mock server in the Servers list in interactive API docs

Helen
  • 87,344
  • 17
  • 243
  • 314