punkouter
punkouter

Reputation: 5366

Adding a WEB API method ruins my SWAGGER UI

This first method is fine. But when I add the second method the body of the SWAGGER UI is a bunch of html gibberish. And I creating the route the wrong way?

enter image description here

// GET api/checklist/1288
        [HttpGet("{id}")]
        public async Task<IActionResult> Get(int id)
        {
            var model = _checkListService.Get(id);
            return Ok(model);
        }

    // http://localhost:64783/api/checklist/GetDelinquentItems?id=1288
    [Route("GetDelinquentItems")]
    public async Task<IActionResult> GetDelinquentItems(int id)
    {
        var model = _checkListService.GetDelinquentItems(id);
        return Ok(model);
    }

Upvotes: 0

Views: 252

Answers (1)

jps
jps

Reputation: 22575

That 'html gibberish' (indeed not the most elegant way to show an error) still contains some useful information. The first line says:

500 internal server error

and in the last three lines you can read:

Ambiguos HTTP method for action...CheckListController.GetDelinquentItems... Actions require explicit HttpMethod binding for Swagger

therefore another

[HttpGet("{id}")]

before the GetDelinquentItems() method should solve the problem.

Upvotes: 2

Related Questions