简体   繁体   English

Swagger 被具有不同 URL 的第二个 HttpPost 端点混淆

[英]Swagger confused by second HttpPost endpoint with different URL

I have the following API endpoint.我有以下 API 端点。

[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.但我需要添加一个返回额外数据的版本,但我想在不破坏现有 API 的情况下进行。

So I added a second one with an "ex" segment in the URL.所以我在 URL 中添加了第二个带有“ex”段的。

[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.然而,swagger 似乎对此感到困惑。

在此处输入图像描述

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.如果我尝试直接导航到https://localhost:44360/swagger/v1/swagger.json ,则会出现错误。

在此处输入图像描述

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.将该方法(不是端点)设为私有解决了这个问题。

instead of Post then Route, try而不是发布然后路由,尝试

HttpPost("{companyCode}") HttpPost("{companyCode}")

and

HttpPost("ex/{companyCode}") HttpPost("ex/{companyCode}")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM