ApiVersionAuto 1.0.0
dotnet add package ApiVersionAuto --version 1.0.0
NuGet\Install-Package ApiVersionAuto -Version 1.0.0
<PackageReference Include="ApiVersionAuto" Version="1.0.0" />
<PackageVersion Include="ApiVersionAuto" Version="1.0.0" />
<PackageReference Include="ApiVersionAuto" />
paket add ApiVersionAuto --version 1.0.0
#r "nuget: ApiVersionAuto, 1.0.0"
#:package ApiVersionAuto@1.0.0
#addin nuget:?package=ApiVersionAuto&version=1.0.0
#tool nuget:?package=ApiVersionAuto&version=1.0.0
ApiVersionAuto
๐ Automate API versioning in .NET projects by detecting breaking changes and generating new API versions using Roslyn analyzers.
๐ Overview
ApiVersionAuto is a powerful .NET library that automatically detects breaking changes in your API code and suggests appropriate version increments. It uses Roslyn analyzers to scan your codebase and identify potential breaking changes, helping you maintain API versioning best practices.
โจ Key Features
- ๐ Auto-detects breaking changes in API contracts using Roslyn
- ๐ Generates new API versions automatically based on semantic versioning
- ๐๏ธ Attribute-based overrides for manual control and exclusions
- ๐ง Integrates with ASP.NET Core routing and middleware
- ๐ Changelog and diff generation for better documentation
- ๐ก๏ธ Prevents accidental breaking changes from reaching production
- ๐ Comprehensive reporting with severity levels and migration guides
๐ Quick Start
Installation
dotnet add package ApiVersionAuto
Basic Usage
using ApiVersionAuto;
using ApiVersionAuto.Analyzers;
using ApiVersionAuto.Generators;
// Configure the analyzer engine
var engine = new AnalyzerEngine()
.RegisterAnalyzer(new RoslynApiAnalyzer())
.RegisterVersionGenerator(new SemanticVersionGenerator());
// Analyze your API project
var (breakingChanges, newVersion) = await engine.AnalyzeAndVersionAsync("./path/to/your/project");
Console.WriteLine($"Suggested version: {newVersion}");
Console.WriteLine($"Breaking changes found: {breakingChanges.Count}");
ASP.NET Core Integration
// Program.cs
var builder = WebApplication.CreateBuilder(args);
// Add ApiVersionAuto services
builder.Services.AddApiVersionAuto();
var app = builder.Build();
// Map ApiVersionAuto endpoints
app.MapApiVersionAuto();
app.Run();
๐ฏ Usage Examples
1. Basic API Analysis
using ApiVersionAuto;
var analyzer = new AnalyzerEngine()
.RegisterAnalyzer(new RoslynApiAnalyzer())
.RegisterVersionGenerator(new SemanticVersionGenerator());
var (breakingChanges, suggestedVersion) = await analyzer.AnalyzeAndVersionAsync("./MyApi");
if (breakingChanges.Count > 0)
{
Console.WriteLine($"โ ๏ธ Breaking changes detected! Suggested version: {suggestedVersion}");
foreach (var change in breakingChanges)
{
Console.WriteLine($"- {change}");
}
}
2. Custom Analyzer Configuration
var engine = new AnalyzerEngine()
.RegisterAnalyzer(new RoslynApiAnalyzer())
.RegisterAnalyzer(new CustomApiAnalyzer()) // Your custom analyzer
.RegisterVersionGenerator(new SemanticVersionGenerator())
.RegisterVersionGenerator(new CustomVersionGenerator()); // Your custom generator
3. Attribute-Based Control
[ApiVersion("2.0")]
[ExcludeFromVersionAnalysis("Internal API")]
public class UsersController : ControllerBase
{
[NonBreakingChange("Adding optional parameter")]
public IActionResult GetUsers(string? filter = null)
{
// This change won't trigger a version bump
}
[IntentionalBreakingChange("Removing deprecated endpoint")]
public IActionResult GetUser(int id)
{
// This will be marked as an intentional breaking change
}
}
4. Changelog Generation
using ApiVersionAuto.Generators;
var generator = new ChangelogGenerator();
var versionInfo = new VersionInfo
{
CurrentVersion = "1.0.0",
SuggestedVersion = "2.0.0",
ChangeType = VersionChangeType.Major
};
var breakingChanges = new List<BreakingChange>
{
new BreakingChange
{
Type = BreakingChangeType.MethodSignatureChanged,
Severity = BreakingChangeSeverity.High,
Description = "GetUser method signature changed",
AffectedApi = "GET /api/users/{id}"
}
};
var changelog = generator.GenerateMarkdownChangelog(versionInfo, breakingChanges);
Console.WriteLine(changelog);
๐ง Configuration
ASP.NET Core Integration
// Add services with custom configuration
builder.Services.AddApiVersionAuto(engine =>
{
engine.RegisterAnalyzer(new RoslynApiAnalyzer());
engine.RegisterVersionGenerator(new SemanticVersionGenerator());
});
// Map endpoints with custom path
app.MapApiVersionAuto("/api/versioning");
Available Endpoints
GET /api/version/analyze?projectPath={path}
- Analyze API versionPOST /api/version/changelog
- Generate changelogGET /api/version/summary?projectPath={path}
- Get breaking changes summary
๐๏ธ Attributes
ApiVersionAttribute
Manually specify API version for controllers or actions.
[ApiVersion("2.0")]
public class UsersController : ControllerBase
{
// This controller is explicitly versioned
}
ExcludeFromVersionAnalysisAttribute
Exclude controllers or actions from version analysis.
[ExcludeFromVersionAnalysis("Internal API")]
public class InternalController : ControllerBase
{
// This controller won't be analyzed
}
NonBreakingChangeAttribute
Mark changes as non-breaking.
[NonBreakingChange("Adding optional parameter")]
public IActionResult GetUsers(string? filter = null)
{
// This change won't trigger a version bump
}
ForceVersionChangeAttribute
Force a specific version change type.
[ForceVersionChange(VersionChangeType.Major, "Major refactoring")]
public class RefactoredController : ControllerBase
{
// This will force a major version change
}
IntentionalBreakingChangeAttribute
Mark breaking changes as intentional.
[IntentionalBreakingChange("Removing deprecated endpoint")]
public IActionResult GetUser(int id)
{
// This will be marked as an intentional breaking change
}
๐ Breaking Change Detection
ApiVersionAuto detects the following types of breaking changes:
Method Signature Changes
- Parameter type changes
- Parameter order changes
- Return type changes
- Method removal
Route Changes
- Route pattern changes
- HTTP method changes
- Route parameter changes
Model Changes
- Property type changes
- Property removal
- Model structure changes
Security Changes
- Authentication requirements
- Authorization requirements
- Security header changes
๐ Severity Levels
- Critical: Will definitely break existing clients
- High: Likely to break existing clients
- Medium: May break some clients
- Low: Unlikely to break clients
๐ Changelog Generation
ApiVersionAuto generates comprehensive changelogs including:
- Breaking changes with severity levels
- Migration guides for each change
- Affected API endpoints
- File locations and line numbers
- Detailed explanations
๐ ๏ธ Customization
Custom Analyzers
public class CustomApiAnalyzer : IApiAnalyzer
{
public string Name => "CustomAnalyzer";
public async Task<IList<string>> AnalyzeAsync(string projectPath)
{
// Your custom analysis logic
return new List<string>();
}
}
Custom Version Generators
public class CustomVersionGenerator : IVersionGenerator
{
public string Name => "CustomGenerator";
public async Task<string> GenerateVersionAsync(string projectPath, IList<string> breakingChanges)
{
// Your custom version generation logic
return "2.0.0";
}
}
๐งช Testing
[Test]
public async Task TestApiVersionAnalysis()
{
var engine = new AnalyzerEngine()
.RegisterAnalyzer(new RoslynApiAnalyzer())
.RegisterVersionGenerator(new SemanticVersionGenerator());
var (breakingChanges, newVersion) = await engine.AnalyzeAndVersionAsync("./test-project");
Assert.IsNotNull(newVersion);
Assert.IsNotNull(breakingChanges);
}
๐ Performance
- Fast Analysis: Roslyn-based analysis for quick results
- Incremental: Only analyzes changed files
- Caching: Caches analysis results for better performance
- Parallel Processing: Analyzes multiple files concurrently
๐ค Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ Support
- ๐ง Email: support@apiversionauto.com
- ๐ Issues: GitHub Issues
- ๐ Documentation: Wiki
๐ Roadmap
- Visual Studio Extension
- CI/CD Integration
- Custom Rule Engine
- Performance Benchmarking
- Memory Usage Analysis
- Async/Await Analysis
- OpenAPI/Swagger Integration
- Git Integration for Change Tracking
Made with โค๏ธ for the .NET community
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- Microsoft.AspNetCore.Http.Abstractions (>= 2.2.0)
- Microsoft.AspNetCore.Mvc.Core (>= 2.2.5)
- Microsoft.AspNetCore.Routing.Abstractions (>= 2.2.0)
- Microsoft.CodeAnalysis.Analyzers (>= 3.3.4)
- Microsoft.CodeAnalysis.CSharp (>= 4.8.0)
- System.Text.Json (>= 8.0.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last Updated |
---|---|---|
1.0.0 | 163 | 8/4/2025 |