0

So I'm fairly new to creating API documentation and I'm having some difficulty creating a new entry via the swagger UI. I keep getting a 405 response. I have no idea what the issue is, I've become code blind. The link to the API is below. Any pointers would be greatly appreciated. https://swaggerhub.com/apis/Sharper-Web-Dev/test/1.0.0

Helen
  • 87,344
  • 17
  • 243
  • 314
Sharper
  • 327
  • 3
  • 17

1 Answers1

2

Your definition specifies SwaggerHub's mock server (virtserver.swaggerhub.com) as the target server. The mock server generates the responses based on the responses defined in your API definition. POST /charity defines just the 405 response, that's why the mock returns 405.

To get a "normal" response, you need to define a 200 OK or 201 Created response, and add the response schema (or response examples) describing the desired JSON structure.

paths:
  /charity:
    post:
      ...
      produces:
        - application/json
      parameters:
        ...
      responses:
        200:
          description: OK
          schema:
            $ref: "#/definitions/MyResponseSchema"
        405:
          description: "Invalid input"  

See How Response Mocking Works in SwaggerHub docs for further information.

Helen
  • 87,344
  • 17
  • 243
  • 314
  • That worked perfectly. Though now I'm having trouble with the get. I only get the first item I searched for – Sharper Jan 23 '18 at 14:35
  • Mock only returns what your API definition defines, it does not have any business logic. If you want to return multiple items, add a response example with multiple items. Check out [this answer](https://stackoverflow.com/a/46192564/113116) for an example. – Helen Jan 23 '18 at 14:58