我在WebApi 2应用程序中集成了swagger.应用程序有单个控制器时,它工作正常.当我在应用程序中添加第二个控制器时.我收到以下错误:
发生错误.","ExceptionMessage":"Swagger 2.0不支持:路径'api/Credential'和方法'GET'的多个操作.请参阅配置设置 - \"ResolveConflictingActions \"以获取潜在的解决方法","ExceptionType":"System.NotSupportedException","StackTrace":"at Swashbuckle.Swagger.SwaggerGeneratorOptions.DefaultConflictingActionsResolver(IEnumerable
1 apiDescriptions)\r\n at Swashbuckle.Swagger.SwaggerGenerator.CreatePathItem(IEnumerable1 apiDescriptions,SchemaRegistry schemaRegistry)\ r \在Swashbuckle.Swagger.SwaggerGenerator.<> c__DisplayClass7.b__4(IGrouping2 group)\r\n at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable1 source,Func2 keySelector, Func2 elementSelector,IEqualityComparer1 comparer)\r\n at Swashbuckle.Swagger.SwaggerGenerator.GetSwagger(String rootUrl, String apiVersion)\r\n at Swashbuckle.Application.SwaggerDocsHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)\r\n at System.Net.Http.HttpMessageInvoker.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)\r\n at System.Web.Http.Dispatcher.HttpRoutingDispatcher.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)\r\n at System.Net.Http.DelegatingHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)\r\n at System.Web.Http.Cors.CorsMessageHandler.<SendAsync>d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.HttpServer.d__0.MoveNext()"} http:// …
c# asp.net-web-api swagger asp.net-web-api-routing swashbuckle
使用 openapi-generator 使用 openapi v3.0 规范生成 C# API 客户端。有没有办法自定义API的methodNames?我希望能够通过使用 operationId 字段来指定它们?
现在,他们正在将路径变量与 HTTP VERB 和静态路径组件合并在一起。它会起作用,但我希望名称有点不同。
GetEncountersResponse ClientidEncountersDateGet (string clientid, string date, string startToken = null);
Run Code Online (Sandbox Code Playgroud)
另一个选择是只添加新方法,因为该类被定义为部分类?
当为现有的 500 多个控制器和相应的方法创建 Angular API 服务代理时,我们试图覆盖 Swashbuckle/Swagger IO CodeGen 命名约定。
目前正在将 Net Core 3 API 与 Angular Typescript 链接起来。
以下答案有效:
[HttpGet("{id:int}", Name = nameof(GetProductById))]
public IActionResult GetProductById(int id) // operationId = "GetProductById"'
[HttpGet("{id:int}", Name = "GetProductById")]
public IActionResult GetProductById(int id) // operationId = "GetProductById"'
Run Code Online (Sandbox Code Playgroud)
有没有办法在启动时循环遍历所有控制器和方法?名称应与控制器中操作方法的名称相同。
这也许是可能的解决方案,但是,我需要行动价值。
return services.AddSwaggerGen(c =>
{
c.CustomOperationIds(e => $"{e.ActionDescriptor.RouteValues["controller"]}_{e.HttpMethod}");
Run Code Online (Sandbox Code Playgroud)
我正在尝试在 Visual Studio 2019..Net 5.0 中生成 OpenApi 服务引用。
右键单击项目>添加>连接服务>+服务引用
我正在使用 NetDocs api“https://api.vault.netvoyage.com/v2/swagger/docs/v2”。
结果:我生成了 c# 客户端代码,但它复制了类型,并出现以下错误。
Severity Code Description Project File Line Suppression State
Error CS0102 The type 'v2Client' already contains a definition for '_settings' OpenAPITest C:\Users\dryfus\source\repos\OpenAPITest\obj\v2Client.cs 4941 Active
Error CS0579 Duplicate 'System.CodeDom.Compiler.GeneratedCode' attribute OpenAPITest C:\Users\dryfus\source\repos\OpenAPITest\obj\v2Client.cs 4936 Active
Error CS0102 The type 'v2Client' already contains a definition for '_baseUrl' OpenAPITest C:\Users\dryfus\source\repos\OpenAPITest\obj\v2Client.cs 4939 Active
Error CS0102 The type 'v2Client' already contains a definition for '_httpClient' OpenAPITest C:\Users\dryfus\source\repos\OpenAPITest\obj\v2Client.cs 4940 Active
Run Code Online (Sandbox Code Playgroud)
有没有一种方法可以让它与连接器方式一起工作而无需重复?甚至是 cli?关于为什么创建重复项有什么建议吗?
在我的 web api 中,我有 2 种获取方法,一种获取所有客户端,一种通过 ID 获取客户端
[HttpGet]
public async Task<IHttpActionResult> GetClients()
{
var telemetry = new TelemetryClient();
try
{
var roles = await CosmosStoreHolder.Instance.CosmosStoreClient.Query().ToListAsync();
return Ok(roles);
}
catch (System.Exception ex)
{
string guid = Guid.NewGuid().ToString();
var dt = new Dictionary<string, string>
{
{ "Error Lulo: ", guid }
};
telemetry.TrackException(ex, dt);
return BadRequest("Error Lulo: " + guid);
}
}
[HttpGet]
public async Task<IHttpActionResult> GetClient(string clientId)
{
var telemetry = new TelemetryClient();
try
{
var clientStore = CosmosStoreHolder.Instance.CosmosStoreClient;
var …Run Code Online (Sandbox Code Playgroud) 如何operationId在Asp.Net Core 2.1项目中设置swagger 属性?根据这篇文章,我应该使用,SwaggerOperationAttribute但在Swashbuckle.AspNetCore库中找不到它。也有一个IOperationFilter
public interface IOperationFilter
{
void Apply(Operation operation, OperationFilterContext context);
}
Run Code Online (Sandbox Code Playgroud)
而且我找不到为实现摇摇欲坠目的的任何实现。