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

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

That worked perfectly. Though now I'm having trouble with the get. I only get the first item I searched for
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 for an example.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.