When I was load the swagger UI it shows error.
Unhandled exception at line 1490, column 3 in http://localhost:51082/swagger/ui/swagger-ui-js
0x800a139e - JavaScript runtime error: 500 : {"$id":"1","message":"An error has occurred.","exceptionMessage":"Conflicting schemaIds: Duplicate schemaIds detected for types PersonName and Global.PersonName. See the config setting - \"UseFullTypeNameInSchemaIds\" for a potential workaround","exceptionType":"System.InvalidOperationException","stackTrace":" at Swashbuckle.Swagger.SchemaRegistry.CreateRefSchema(Type type)\r\n at
If there is a handler for this exception, the program may be safely continued.
It represent two class in same name. But two class will be present in different directory model. I want to use same class name with out change. can you pls help regarding this.
Every class in the swagger JSON must have a unique schemaId.
Swashbuckler tries to just use the class name as a simple schemaId, however if you have two classes in different namespaces with the same name (as you do) this will not work.
As the error suggests, you can use the config setting "UseFullTypeNameInSchemaIds" for a potential workaround.
HI MarickOWA
Thank you so much for your clarification now it's working fine.
How to use "UseFullTypeNameInSchemaIds" in .NetCore middleware?
@udaykiranp looks like there is no UseFullTypeNameInSchemaIds in .NET Core, but you can achieve the same behavior via options.CustomSchemaIds(x => x.FullName). Here is an example:
services.ConfigureSwaggerGen(options =>
{
//your custom configuration goes here
...
// UseFullTypeNameInSchemaIds replacement for .NET Core
options.CustomSchemaIds(x => x.FullName);
});
I found the solution here http://wegotcode.com/microsoft/swagger-fix-for-dotnetcore/
Btw. nowadays .NET Core offers you CustomSchemaIds option in the error message as well. In my case the message looks like:
An unhandled exception has occurred while executing the request
System.InvalidOperationException: Conflicting schemaIds: Identical schemaIds detected for types.Features.Contracts.RegisterContractRequest+ParticipantDTO and .Features.Contracts.SnapshotResponse+ParticipantDTO. See config settings - "UseFullTypeNameInSchemaIds" or "CustomSchemaIds" for a workaround
options.CustomSchemaIds(x => x.FullName);
It will give error when you try generate clientC# => invalid character when parameter type is generic
In ASP.NET Core 2.1
public void ConfigureServices(IServiceCollection services)
{
...
// Register the Swagger generator, defining 1 or more Swagger documents
services.AddSwaggerGen(c =>
{
...
c.CustomSchemaIds(r => r.FullName);
});
...
}
Most helpful comment
@udaykiranp looks like there is no UseFullTypeNameInSchemaIds in .NET Core, but you can achieve the same behavior via options.CustomSchemaIds(x => x.FullName). Here is an example:
I found the solution here http://wegotcode.com/microsoft/swagger-fix-for-dotnetcore/
Btw. nowadays .NET Core offers you CustomSchemaIds option in the error message as well. In my case the message looks like: