Skip to content

Instantly share code, notes, and snippets.

@dj-nitehawk
Last active September 13, 2023 06:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dj-nitehawk/c32e7f887389460c661b955d233b650d to your computer and use it in GitHub Desktop.
Save dj-nitehawk/c32e7f887389460c661b955d233b650d to your computer and use it in GitHub Desktop.
Showing deprecated endpoint versions in Swagger
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
}
}
@dj-nitehawk
Copy link
Author

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment