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