• swagger error: Conflicting schemaIds: Duplicate schemaIds detected for types A and B


    使用Web API并使用swashbuckle生成swagger文档,我在两个不同的命名空间中定义了两个具有相同名称的不同类。当我在浏览器中打开swagger页面时,它说

    1 Conflicting schemaIds: Duplicate schemaIds detected for types A and B. See the config setting - "UseFullTypeNameInSchemaIds" for a potential workaround

    完整消息:

     1 {
     2     "message": "An error has occurred.",
     3     "exceptionMessage": "Conflicting schemaIds: Duplicate schemaIds detected for types Amo.Common.AjaxResult`1[[System.Collections.Generic.List`1[[Amo.UsdtCoin.UsMerchantClient+oListTransactionResult, Amo.UsdtCoin, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]] and Amo.Common.AjaxResult`1[[System.Collections.Generic.List`1[[Amo.BtcCoin.MerchantClient+oListTransactionResult, Amo.BitCoin, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]. See the config setting - "UseFullTypeNameInSchemaIds" for a potential workaround",
     4     "exceptionType": "System.InvalidOperationException",
     5     "stackTrace": " 在 Swashbuckle.Swagger.SchemaRegistry.CreateRefSchema(Type type)
    
     6      在 Swashbuckle.Swagger.SchemaRegistry.CreateInlineSchema(Type type)
     
     7      在 Swashbuckle.Swagger.SchemaRegistry.GetOrRegister(Type type)
     
     8      在 Swashbuckle.Swagger.SwaggerGenerator.CreateOperation(ApiDescription apiDesc, SchemaRegistry schemaRegistry)
     
     9      在 Swashbuckle.Swagger.SwaggerGenerator.CreatePathItem(IEnumerable`1 apiDescriptions, SchemaRegistry schemaRegistry)
     
    10      在 Swashbuckle.Swagger.SwaggerGenerator.<>c__DisplayClass7.<GetSwagger>b__4(IGrouping`2 group)
     
    11      在 System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer)
     
    12      在 Swashbuckle.Swagger.SwaggerGenerator.GetSwagger(String rootUrl, String apiVersion)
     
    13      在 Amo.Client.CachingSwaggerProvider.GetSwagger(String rootUrl, String apiVersion) 位置 E:\codes\USDTSolution\Amo.Client\App_Start\SwaggerConfig.cs:行号 301
     
    14      在 Swashbuckle.Application.SwaggerDocsHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
     
    15      在 System.Net.Http.HttpMessageInvoker.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
     
    16      在 System.Web.Http.Dispatcher.HttpRoutingDispatcher.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
     
    17      在 System.Net.Http.DelegatingHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
     在 System.Web.Http.HttpServer.<SendAsync>d__24.MoveNext()"
    18 }

    我不想改变类的名字。我该如何解决?

    解决方法1:

    1  services.ConfigureSwaggerGen(options =>
    2    {
    3        //your custom configuration goes here
    4 
    5 ...
    6 
    7   // UseFullTypeNameInSchemaIds replacement for .NET Core
    8        options.CustomSchemaIds(x => x.FullName);
    9    });

    解决方法2:

     1 GlobalConfiguration.Configuration 
     2     .EnableSwagger(c =>
     3     {
     4         // your configs...
     5 
     6         c.SchemaId(x => x.FullName);
     7 
     8         // other configs...
     9     })
    10     .EnableSwaggerUi(c =>
    11         // ....
    12     });

    解决方法3:

    1 c.UseFullTypeNameInSchemaIds();
  • 相关阅读:
    符瑞艺 160809228_C语言程序设计实验2 选择结构程序设计
    页面布局class常见命名规范
    CSS学习笔记
    HTML学习笔记
    虚拟机Centos7设置ip地址,并ping真机ip
    vue单页面开发和多页面开发的概念,及优缺点?
    传统的DOM渲染方式?
    面试题
    通过电脑chrome调试手机真机打开的微信H5页面,调试电脑微信H5页面(转载自 乐乐熊小妹)
    常见前端面试题及答案
  • 原文地址:https://www.cnblogs.com/yanglang/p/9475539.html
Copyright © 2020-2023  润新知