Skip to content
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

Exception When Exploring OData Routes with Both Key Styles #891

Closed
1 task done
commonsensesoftware opened this issue Oct 6, 2022 · 1 comment · Fixed by #901
Closed
1 task done

Exception When Exploring OData Routes with Both Key Styles #891

commonsensesoftware opened this issue Oct 6, 2022 · 1 comment · Fixed by #901

Comments

@commonsensesoftware
Copy link
Collaborator

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

When:

options.RouteOptions.EnableKeyInParenthesis = false;
options.RouteOptions.EnableKeyAsSegment = true;

or

options.RouteOptions.EnableKeyInParenthesis = true;
options.RouteOptions.EnableKeyAsSegment = false;

Is configured, then OData routes are documented as expected. However, if:

options.RouteOptions.EnableKeyInParenthesis = true;
options.RouteOptions.EnableKeyAsSegment = true;

is configured or there is no configuration at all (the default), then an exception is encountered.

Expected Behavior

No exception should occur. If both key styles are enabled, then both routes should be discovered and documented.

Steps To Reproduce

  • Define entity with composite keys
  • Configure both entity key types (or omit the configuration, which is the default)
  • Enable the API Explorer extensions for OData
  • Run the application

Exceptions (if any)

NullReferenceException

at Asp.Versioning.ApiExplorer.ODataApiDescriptionProvider.TryMatchModelVersion(ApiDescription description, IReadOnlyList`1 items, IODataRoutingMetadata& metadata)
   at Asp.Versioning.ApiExplorer.ODataApiDescriptionProvider.OnProvidersExecuted(ApiDescriptionProviderContext context)
   at Microsoft.AspNetCore.Mvc.ApiExplorer.ApiDescriptionGroupCollectionProvider.GetCollection(ActionDescriptorCollection actionDescriptors)
   at Microsoft.AspNetCore.Mvc.ApiExplorer.ApiDescriptionGroupCollectionProvider.get_ApiDescriptionGroups()
   at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GetSwaggerDocumentWithoutFilters(String documentName, String host, String basePath)
   at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.<GetSwaggerAsync>d__6.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.<Invoke>d__4.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult()

.NET Version

No response

Anything else?

Related to #889

@commonsensesoftware
Copy link
Collaborator Author

There are actually two conditions that can cause this:

  1. A logic bug where ApiVersionMetadata is not applied to all SelectorModel instances created by OData
  2. A developer incorrectly calls AddRouteComponents via the default OData method instead of the API Versioning variant

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

Successfully merging a pull request may close this issue.

1 participant