Search code examples
swaggerapi-designswaggerhub

Error testing API with Swagger response header 405


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


Solution

  • 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.