Open mathew-tolj opened 5 hours ago
This might be a gap in the implementation. I can tell by what you've shared that you are in the Partial OData camp. You're not really using OData the protocol. You're just taking advantage of the query options. There's nothing wrong with that per se and why reinvent a HTTP-based query language.
This path, however, does come with some quirks and limitations. First and foremost, the API Explorer extensions for OData are based on an EDM. EF and OData both use EDM, but not the same EDM model or instance. The EDM for EF is about mapping your model to a database. The OData EDM is for mapping your model over the wire (e.g. HTTP). You don't have an OData EDM (that I see). That is to be expected in this scenario. Since the API Explorer extensions only know how to operate on an OData EDM, it generates one on the fly.
It appears you've encountered a sharp edge where:
I'm almost certain it's #2
. You need to tell the OData side that the Addresses
is either contained or a complex type. This configuration can be achieved by using IModelConfiguration
, which will be picked up by DI or you can explicitly configure it through ODataApiExplorerOptions.AdHocModelBuilder
. This is the ODataModelBuilder
that is used to build the ad hoc EDM used for this scenario.
The reason you haven't seen this before is that you aren't actually using OData in your controller. That requires applying [ODataRouting]
, which is typically applied by inheriting from ODataController
.
I think with a little bit of configuration help on your side, you'll achieve the result you're looking for.
Is there an existing issue for this?
Describe the bug
I recently configured JSON columns in a service using Microsoft.EntityFrameworkCore.SqlServer 8.0.10 and this caused Swashbuckle.AspNetCore 6.8.1 to fail. Investigating further it looks like this might be caused by the EDM model created by Asp.Versioning.OData.ApiExplorer 8.1.0 failing validation. It seems like the EDM model is expecting the owned entities from the JSON to have a key but in my case they are more like value objects. The exception only causes Swashbuckle to fail. I can still call the endpoint and get a response using methods other than the Swagger endpoint.
Expected Behavior
No response
Steps To Reproduce
Create an entity that owns a list of other entities:
Configure a
DbContext
that persists the list in database as JSON:Create a controller for the entity:
Wire it all up in Program.cs:
Exceptions (if any)
.NET Version
8.0.403
Anything else?
No response