Skip to content

Issue when displaying the Swagger definition for V1, V2 and V3 in the SwaggerODataSample project #737

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
jmoralesv opened this issue Mar 28, 2021 · 3 comments

Comments

@jmoralesv
Copy link

jmoralesv commented Mar 28, 2021

Hi all,
I'm writing this issue because I was running the projects under the samples folder and found an error when running the SwaggerODataSample.csproj project, located at https://github.com/microsoft/aspnet-api-versioning/tree/master/samples/aspnetcore/SwaggerODataSample. When selecting a Swagger definition in the Swagger UI page, either for V1, V2 or V3, this error appears in the output console:

Microsoft.AspNetCore.Server.IIS.Core.IISHttpServer: Error: Connection ID "18302628887244308571", Request ID "8000005e-0000-fe00-b63f-84710c7967bb": An unhandled exception was thrown by the application.

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)
   at Swashbuckle.AspNetCore.SwaggerGen.SchemaGenerator.GenerateReferencedSchema(DataContract dataContract, SchemaRepository schemaRepository, Func`1 definitionFactory)
   at Swashbuckle.AspNetCore.SwaggerGen.SchemaGenerator.GenerateConcreteSchema(DataContract dataContract, SchemaRepository schemaRepository)
   at Swashbuckle.AspNetCore.SwaggerGen.SchemaGenerator.GenerateSchemaForParameter(ParameterInfo parameterInfo, SchemaRepository schemaRepository)
   at Swashbuckle.AspNetCore.SwaggerGen.SchemaGenerator.GenerateSchema(Type type, SchemaRepository schemaRepository, MemberInfo memberInfo, ParameterInfo parameterInfo)
   at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GenerateSchema(Type type, SchemaRepository schemaRepository, PropertyInfo propertyInfo, ParameterInfo parameterInfo)
   --- End of inner exception stack trace ---
   at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GenerateSchema(Type type, SchemaRepository schemaRepository, PropertyInfo propertyInfo, ParameterInfo parameterInfo)
   at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GenerateRequestBodyFromBodyParameter(ApiDescription apiDescription, SchemaRepository schemaRepository, ApiParameterDescription bodyParameter)
   at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GenerateRequestBody(ApiDescription apiDescription, SchemaRepository schemaRepository)
   at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GenerateOperation(ApiDescription apiDescription, SchemaRepository schemaRepository)
   --- End of inner exception stack trace ---
   at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GenerateOperation(ApiDescription apiDescription, SchemaRepository schemaRepository)
   at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GenerateOperations(IEnumerable`1 apiDescriptions, SchemaRepository schemaRepository)
   at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GeneratePaths(IEnumerable`1 apiDescriptions, SchemaRepository schemaRepository)
   at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GetSwagger(String documentName, String host, String basePath)
   at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)
   at Microsoft.AspNetCore.Server.IIS.Core.IISHttpContextOfT`1.ProcessRequestAsync()

In the Swagger UI page, this is how it looks like:
image

Do you know how to solve it please? I'm learning on how to display OData parameters ($filter, $skip, $count) for a OData endpoint in Swagger (either by using Swashbuckle or NSwag) and this example looks very promising.

Thanks for your help on this.

Regards,
Jorge

@commonsensesoftware
Copy link
Collaborator

This appears to be duplicate of #729. I'll investigate.

@jmoralesv
Copy link
Author

Hi @commonsensesoftware
Yes, it seems the same issue, I think there is a workaround in one of the last comments in that issue, something about using a unique SchemaId.
I'm looking forward to having a solution for this. Thanks!

@commonsensesoftware
Copy link
Collaborator

As mentioned in the other issue, this specific problem was in Swashbuckle and has been fixed. You shouldn't see any more issues related to duplicate models, but you might run into other bugs in API Versioning that haven't been released yet. You can peek at this branch on how you might be able to fix things while you're waiting for the patch.

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

2 participants