The most comprehensive OpenAPI (Swagger) documentation generator for ASP.NET Core OData APIs.
Provides full support for OData query options ($filter, $select, $expand, etc.), real endpoint-based path generation, and seamless Swashbuckle integration.
If animation is not shown in your Markdown viewer, open Images/swagger-ui-demo.webp directly.
Tip
Start with DOCUMENTATION.md for the canonical reference and RELEASE_NOTES.md for change history and breaking changes.
AddEnhancedSwaggerGenOData* is the default API path. AddSwaggerGenOData remains only as an obsolete compatibility shim.
- π Full OData Query Support - Automatic documentation of
$filter,$select,$expand,$orderby,$top,$skip,$count,$format(and$searchwhen enabled) - π‘ Real Endpoint-Based Generation - Uses actual ASP.NET Core endpoint routing for accurate API documentation
- π― Complete OData Path Coverage - Entity sets, singletons, functions, actions, property access,
$value,$ref - π HTTP Method Accuracy - Correctly captures GET, POST, PUT, PATCH, DELETE with proper request/response schemas
- π§ Swashbuckle Integration - Native integration with Swashbuckle.AspNetCore for UI and code generation
- π Method Overloads - Supports multiple actions with same name, different parameters
- π¨ Customizable - Configure query option examples, max page sizes, and more
dotnet add package Swashbuckle.AspNetCore.Community.ODatapublic void ConfigureServices(IServiceCollection services)
{
// Add OData with query features
services.AddControllers()
.AddOData(o => o
.AddRouteComponents("odata", GetEdmModel())
.EnableQueryFeatures(100)
);
// Add enhanced OData Swagger with query options
services.AddEnhancedSwaggerGenODataWithQueryOptions(
odataSetupAction: opt =>
{
opt.SwaggerDoc(
"v1",
"odata",
new OpenApiInfo
{
Title = "My OData API",
Version = "v1",
Description = "Full OData query support with $filter, $select, $expand!"
}
);
},
queryOptionsSettings: new ODataQueryOptionsSettings
{
EnableFilter = true,
EnableSelect = true,
EnableExpand = true,
MaxTop = 100,
FilterExample = "Name eq 'John' and Age gt 18"
}
);
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseRouting();
app.UseAuthorization();
// Enable Swagger
app.UseSwagger();
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "My OData API v1");
});
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}
private static IEdmModel GetEdmModel()
{
var builder = new ODataConventionModelBuilder();
builder.EntitySet<Product>("Products");
return builder.GetEdmModel();
}var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllers()
.AddOData(o => o
.AddRouteComponents("odata", GetEdmModel())
.EnableQueryFeatures(100));
builder.Services.AddEnhancedSwaggerGenODataWithQueryOptions(
odataSetupAction: opt =>
{
opt.SwaggerDoc("v1", "odata", new OpenApiInfo
{
Title = "My OData API",
Version = "v1"
});
});
var app = builder.Build();
app.UseSwagger();
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "My OData API v1"));
app.MapControllers();
app.Run();- Endpoint-Based Path Generation: Uses actual ASP.NET Core endpoint routing instead of just EDM inference
- Full Query Options Documentation: Every GET collection endpoint includes
$filter,$select,$expand, etc. - Complete Path Coverage: Property access (
/Products(1)/Name),$value,$refpaths - Method Overload Support: Multiple actions with same name are correctly documented
- Better HTTP Semantics: Accurate methods, status codes, request/response schemas
These features shipped in the v2.0 line (starting with v2.0.0). Track version-by-version status in RELEASE_NOTES.md. See ENHANCED_FEATURES.md for detailed feature documentation.
| Feature | Basic EDM | OData's Sample | Enhanced Swashbuckle |
|---|---|---|---|
| OData Query Options | β | β | β Full support |
| Real Endpoint Paths | β | β | β + Enhanced |
| Property Access Paths | β | β | β Added |
| $value/$ref Paths | β | β | β Added |
| Method Overloads | β | β Full | |
| Swashbuckle Integration | β | β | β Native |
paths:
/Products:
get:
summary: Get entities from Products
parameters:
- name: $filter
in: query
description: Filter using OData expressions
example: "Name eq 'John' and Price gt 100"
- name: $select
in: query
description: Select specific properties
example: "Name,Price,Category"
- name: $expand
in: query
description: Expand related entities
example: "Category,Orders"
- name: $top
in: query
schema:
type: integer
maximum: 100
post:
summary: Create a new Product
/Products({key}):
get:
summary: Get Product by key
put:
summary: Update Product (full)
patch:
summary: Update Product (partial with Delta)
delete:
summary: Delete Product
/Products({key})/Category/$ref:
get:
summary: Get Category reference
put:
summary: Update Category reference
delete:
summary: Remove Category referenceservices.AddEnhancedSwaggerGenODataWithQueryOptions(
odataSetupAction: opt =>
{
opt.SwaggerDoc("v1", "odata", new OpenApiInfo { Title = "Public API", Version = "v1" });
opt.SwaggerDoc("internal", "internal", new OpenApiInfo { Title = "Internal API", Version = "v1" });
},
queryOptionsSettings: new ODataQueryOptionsSettings
{
MaxTop = 1000,
EnableSearch = true,
FilterExample = "CreatedDate gt 2023-01-01"
}
);services.AddEnhancedSwaggerGenOData(opt =>
{
opt.SwaggerDoc("odata", "odata", new OpenApiInfo { Title = "OData API", Version = "v1" });
});
services.AddSwaggerGen(options =>
{
options.SwaggerDoc("rest", new OpenApiInfo { Title = "REST API", Version = "v1" });
options.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme { ... });
});- API Documentation: Interactive Swagger UI with full OData query support
- Code Generation: Client SDK generation from accurate OpenAPI specs
- Testing: Discover all endpoints including navigation properties
- Standards Compliance: OData-OpenAPI mapping specification compliance
- DOCUMENTATION.md - Canonical reference and configuration guide
- ENHANCED_FEATURES.md - Feature-focused deep dive
- RELEASE_NOTES.md - Release and breaking-change history
- DEVGUIDE.md - Maintainer release/build workflow
- MAINTAINERS.md - Maintainer list
- Examples/SimpleOdataApi - Lightweight sample implementation
- Examples/ValidationHarness - Validation-focused sample with richer OData surface area
- OData to OpenAPI Mapping - Official OData OpenAPI specification
git clone https://github.com/Tiberriver256/Swashbuckle.AspNetCore.Community.OData.git
cd Swashbuckle.AspNetCore.Community.OData
dotnet restore
dotnet build
dotnet testContributions are welcome. Please read our Contributing Guidelines.
For behavior-affecting changes, contributions are expected to include:
- unit/integration test updates
- relevant documentation updates (
README.mdand/orDOCUMENTATION.md) - release note entries in
RELEASE_NOTES.mdwhen appropriate
This project is licensed under the MIT License - see the LICENSE.md file for details.
- Built on Microsoft.OpenApi.OData for EDM-to-OpenAPI conversion
- Integrated with Swashbuckle.AspNetCore for Swagger UI
- Inspired by ASP.NET Core OData routing samples
