Home > Enterprise >  Swagger confused by second HttpPost endpoint with different URL
Swagger confused by second HttpPost endpoint with different URL

Time:01-26

I have the following API endpoint.

[Authorize]
[HttpPost]
[Route("{companyCode}")]
public async Task<IActionResult> GetSearchResultsAsync(TripSearchDto tripSearch, string companyCode, int? page = null) =>
    await SearchResultsCommonAsync(tripSearch, companyCode, false, page);

This works fine. But I needed to add a version that returns additional data, but I'd like to do it without breaking the existing APIs.

So I added a second one with an "ex" segment in the URL.

[Authorize]
[HttpPost]
[Route("ex/{companyCode}")]
public async Task<IActionResult> GetSearchResultsExAsync(TripSearchDto tripSearch, string companyCode, int? page = null);

This also seems to work fine.

However, swagger appears to be confused by this.

enter image description here

Does anyone see the problem here, or how I can resolve it?

Here's the error if I try navigating to https://localhost:44360/swagger/v1/swagger.json directly.

enter image description here

CodePudding user response:

instead of Post then Route, try

HttpPost("{companyCode}")

and

HttpPost("ex/{companyCode}")

CodePudding user response:

Both methods relied on a common method, which I had inadvertently made public.

Making that method--which was not an endpoint--private solved the issue.

  • Related