-
-
Save stormwild/244c0dec94bb0bca6a514897159b5fa9 to your computer and use it in GitHub Desktop.
Showing deprecated endpoint versions in Swagger
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var bld = WebApplication.CreateBuilder(); | |
bld.Services | |
.AddFastEndpoints() | |
.SwaggerDocument(o => | |
{ | |
o.DocumentSettings = s => | |
{ | |
s.DocumentName = "Initial Release"; | |
s.Version = "v0"; | |
}; | |
}) | |
.SwaggerDocument(o => | |
{ | |
o.MaxEndpointVersion = 1; | |
o.ShowDeprecatedOps = true; // specify to show deprecated versions | |
o.DocumentSettings = s => | |
{ | |
s.DocumentName = "Release 1"; | |
s.Version = "v1"; | |
}; | |
}) | |
.SwaggerDocument(o => | |
{ | |
o.MaxEndpointVersion = 2; | |
o.ShowDeprecatedOps = true; // specify to show deprecated versions | |
o.DocumentSettings = s => | |
{ | |
s.DocumentName = "Release 2"; | |
s.Version = "v2"; | |
}; | |
}); | |
var app = bld.Build(); | |
app | |
.UseFastEndpoints() | |
.UseSwaggerGen(); | |
app.Run(); | |
class MyEndpoint : EndpointWithoutRequest | |
{ | |
public override void Configure() | |
{ | |
Get("say-hello"); | |
AllowAnonymous(); | |
Version(0, deprecateAt: 1); // specify when to deprecate | |
} | |
public override Task HandleAsync(CancellationToken c) | |
=> SendAsync($"hello from version: {Definition.Version.Current}"); | |
} | |
class MyEndpoint_V1 : MyEndpoint | |
{ | |
public override void Configure() | |
{ | |
base.Configure(); | |
Version(1, deprecateAt: 2); // specify when to deprecate | |
} | |
} | |
class MyEndpoint_V2 : MyEndpoint | |
{ | |
public override void Configure() | |
{ | |
base.Configure(); | |
Version(2); // latest version doesn't need to specify deprecation | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment