Hi,
I've upgraded from 6.9.1 to 7.1.0.
The new option added to SwaggerGen in startup causes a duplicate key error:
options.OperationFilter<SwaggerOperationFilter>();
System.ArgumentException: An item with the same key has already been added. Key: x-schema
at System.Collections.Generic.Dictionary2.TryInsert(TKey key, TValue value, InsertionBehavior behavior) at System.Collections.Generic.Dictionary2.Add(TKey key, TValue value)
at Uno.Framework.Web.Swagger.SwaggerOperationFilter.Apply(Operation operation, OperationFilterContext context) in C:\Uno\Git\uno-ins\framework\src\Uno.Framework.Web.Core\Swagger\SwaggerOperationFilter.cs:line 32
at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.CreateOperation(ApiDescription apiDescription, ISchemaRegistry schemaRegistry)...
Removed the new option all works fine. What is the purpose of this new code?
This is my full configuration for swagger:
services.AddSwaggerGen(options =>
{
options.SwaggerDoc("v1", new Info { Title = "Framework API", Version = "v1" });
options.DocInclusionPredicate((docName, description) => true);
options.UseReferencedDefinitionsForEnums();
options.ParameterFilter<SwaggerEnumParameterFilter>();
options.SchemaFilter<SwaggerEnumSchemaFilter>();
options.OperationFilter<SwaggerOperationIdFilter>();
//SOFTWAREUNO - Questo filtro causa un errore di duplicazione di chiave
//options.OperationFilter<SwaggerOperationFilter>();
options.CustomDefaultSchemaIdSelector();
//Note: This is just for showing Authorize button on the UI.
//Authorize button's behaviour is handled in wwwroot/swagger/ui/index.html
options.AddSecurityDefinition("Bearer", new BasicAuthScheme());
//SOFTWAREUNO
options.OrderActionsBy(o => o.RelativePath);
options.CustomSchemaIds(o => o.FullName);
foreach (var file in Directory.GetFiles(_hostingEnvironment.ContentRootPath, "*.docs.xml", SearchOption.AllDirectories))
{
options.IncludeXmlComments(file);
}
options.DescribeAllEnumsAsStrings();
});
Thank you Ivano
5 Answer(s)
-
0
May be related to this https://github.com/aspnetzero/aspnet-zero-core/issues/2458
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
No, the code is the same and the problem happens in SwaggerOperationFilter.cs file.
Removed the new option all works fine. What is the purpose of this new code?
Thanks
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
Hi @ivanosw1
It simplyfies Enum definitions and allows Angular client app to use more meaningful Enum names. The line
options.CustomSchemaIds(o => o.FullName);can cause the problem in your case as well.Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
I'm not an expert of Swagger and the default values works well for me until last update.
I must use
options.CustomSchemaIds(o => o.FullName)because we have some duplicate schemaIds in our dtos otherwise I have the Conflicting schemaIds error.If you want to see for enums the text instead of the values, I use
options.DescribeAllEnumsAsStrings();and all enum are showed as text:Uno.Foundation.Core.ImageSizeTypestring $ref: #/definitions/Uno.Foundation.Core.ImageSizeType Enum: [ Big, Medium, Small ] <--- 1,2,3
Also swagger show a dropdown with literal values when you try some rest api. Maybe it is a duplicate functionality?
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
We had several issue when using CustomSchemaIds similar to https://github.com/aspnetzero/aspnet-zero-core/issues/2205
Here is the full list https://github.com/aspnetzero/aspnet-zero-core/issues?q=is:issue+CustomSchemaIds+is:closed
If your solution works for you, you can keep it that way.
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image)
