Skip to content

SwaggerODataSample throws Exception when accessing V1, V2 and V3 #729

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
andenkondor opened this issue Feb 12, 2021 · 3 comments
Closed

Comments

@andenkondor
Copy link

Hi,

I'm currently on v5.0.0 and can't access the swagger docs for every version greater than 0.9.
Here is what the log is telling me:

Swashbuckle.AspNetCore.SwaggerGen.SwaggerGeneratorException: Failed to generate Operation for action - Microsoft.Examples.V1.OrdersController.Post (SwaggerODataSample). See inner exception ---> Swashbuckle.AspNetCore.SwaggerGen.SwaggerGeneratorException: Failed to generate schema for type - Microsoft.Examples.Models.Order. See inner exception ---> System.InvalidOperationException: Can't use schemaId "$Order" for type "$Microsoft.Examples.Models.Order". The same schemaId is already used for type "$Microsoft.Examples.Models.Order" at Swashbuckle.AspNetCore.SwaggerGen.SchemaRepository.RegisterType(Type type, String schemaId)

@Janus88
Copy link

Janus88 commented Feb 15, 2021

Hi,

I encountered the same problem. As a workaround, downgrading Swashbuckle.AspNetCore Nuget package to 5.6.3 helped.

@necipsunmaz
Copy link

necipsunmaz commented Mar 20, 2021

I found the solution but couldn't find the cause.

services.AddSwaggerGen(opt =>
{
   ...
   opt.CustomSchemaIds(type => type.ToString() + type.GetHashCode()); // This helped me
   ...
});

@commonsensesoftware
Copy link
Collaborator

I've discovered that this specific issue is a bug in Swashbuckle. Updating to the latest release should fix this. You might, however, run into other issues related to route template generation (not model generation). Peek at the updated sample in this branch. That may address them until the next patch is released.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants