-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Open
Description
Summary
Integrate ASP.NET Core OData v8 into the Web API project of dotnet-starter-kit and expose OData endpoints through Swagger/OpenAPI. This gives clients rich, standardized query capabilities ($filter, $select, $expand, $orderby, $top, $skip, $count) while keeping our API surface minimal and discoverable via Swagger UI. Implementation follows Microsoft's OData guidance and Swashbuckle setup for ASP.NET Core.
Why this belongs in dotnet-starter-kit
- Powerful querying with fewer endpoints: Built-in OData query options reduce the need for custom endpoints and fit admin/back-office/reporting scenarios.
- Modern, supported stack: ASP.NET Core OData v8 is actively maintained; OData .NET 8 modernizes internals on recent .NET versions.
- Discoverability via Swagger/OpenAPI: Swashbuckle provides interactive docs; newer ASP.NET Core templates require explicit OpenAPI/Swagger configuration.
References
- OData Fundamentals (ASP.NET Core OData 8): https://learn.microsoft.com/en-us/odata/webapi-8/fundamentals/overview
- Getting Started with OData 8: https://learn.microsoft.com/en-us/odata/webapi-8/getting-started
- OData Query Options: https://learn.microsoft.com/en-us/odata/webapi-8/fundamentals/query-options
- OData .NET 8 Announcement: https://devblogs.microsoft.com/odata/announcing-odata-net-8-official-release/
- Swashbuckle with ASP.NET Core: https://learn.microsoft.com/en-us/aspnet/core/tutorials/getting-started-with-swashbuckle
Scope (for this repository)
Projects/paths
Assume the Web API entry point issrc/apps/webapi/Program.cs. We’ll update docs if paths differ.
-
Add OData package
- Add
Microsoft.AspNetCore.ODatato the Web API project.
- Add
-
Register OData services & EDM
- Build an EDM model (
ODataConventionModelBuilder) and register route components under/odata. - Enable query options:
.Select().Filter().OrderBy().Expand().Count().SetMaxTop(null).
- Build an EDM model (
-
Create sample controller(s)
- Inherit from
ODataControllerand annotate GET actions with[EnableQuery].
- Inherit from
-
Wire up Swagger/OpenAPI
- Add Swashbuckle packages, then
AddSwaggerGen(),UseSwagger(),UseSwaggerUI()inProgram.cs. - Confirm OData endpoints operate and Swagger loads without formatter conflicts (workarounds exist if needed).
- Add Swashbuckle packages, then
-
Documentation
- Update kit docs (e.g.,
/docsor README) with examples & screenshots:GET /odata/Products?$filter=Price gt 20GET /odata/Products?$select=Id,Name&$orderby=NameGET /odata/Products?$expand=Category&$count=true
- Update kit docs (e.g.,
Proposed Implementation (starter-kit aligned)
src/apps/webapi/Program.cs(illustrative—adapt to actual path/namespaces)
using Microsoft.AspNetCore.OData;
using Microsoft.OData.ModelBuilder;
var builder = WebApplication.CreateBuilder(args);
// Swagger / OpenAPI
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
// OData EDM
var odataModelBuilder = new ODataConventionModelBuilder();
// Replace with a real entity from the kit (e.g., Products, Tenants, Users)
odataModelBuilder.EntitySet<Product>("Products");
builder.Services
.AddControllers()
.AddOData(opt => opt
.Select().Filter().OrderBy().Expand().Count().SetMaxTop(null)
.AddRouteComponents("odata", odataModelBuilder.GetEdmModel()));
var app = builder.Build();
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
// Optional: app.UseODataRouteDebug(); // exposes ~/$odata routing page
}
app.UseRouting();
// keep existing auth/tenant middleware as-is
app.MapControllers();Metadata
Metadata
Assignees
Labels
No labels