Skip to content

Instantly share code, notes, and snippets.

@generalgw
Forked from dj-nitehawk/Program.cs
Created April 12, 2025 20:40
Show Gist options
  • Save generalgw/302fb2e4384b1363c411f738e9e0a533 to your computer and use it in GitHub Desktop.
Save generalgw/302fb2e4384b1363c411f738e9e0a533 to your computer and use it in GitHub Desktop.

Revisions

  1. @dj-nitehawk dj-nitehawk revised this gist Sep 13, 2023. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions Program.cs
    Original file line number Diff line number Diff line change
    @@ -42,7 +42,7 @@ public override void Configure()
    {
    Get("say-hello");
    AllowAnonymous();
    Version(0, deprecateAt: 1); // every endpoint needs to specify deprecation
    Version(0, deprecateAt: 1); // specify when to deprecate
    }

    public override Task HandleAsync(CancellationToken c)
    @@ -54,7 +54,7 @@ class MyEndpoint_V1 : MyEndpoint
    public override void Configure()
    {
    base.Configure();
    Version(1, deprecateAt: 2); // every endpoint needs to specify deprecation
    Version(1, deprecateAt: 2); // specify when to deprecate
    }
    }

    @@ -63,6 +63,6 @@ class MyEndpoint_V2 : MyEndpoint
    public override void Configure()
    {
    base.Configure();
    Version(2, deprecateAt: 3); // every endpoint needs to specify deprecation
    Version(2); // latest version doesn't need to specify deprecation
    }
    }
  2. @dj-nitehawk dj-nitehawk revised this gist Sep 13, 2023. 1 changed file with 5 additions and 5 deletions.
    10 changes: 5 additions & 5 deletions Program.cs
    Original file line number Diff line number Diff line change
    @@ -12,7 +12,7 @@
    .SwaggerDocument(o =>
    {
    o.MaxEndpointVersion = 1;
    o.ShowDeprecatedOps = true;
    o.ShowDeprecatedOps = true; // specify to show deprecated versions
    o.DocumentSettings = s =>
    {
    s.DocumentName = "Release 1";
    @@ -22,7 +22,7 @@
    .SwaggerDocument(o =>
    {
    o.MaxEndpointVersion = 2;
    o.ShowDeprecatedOps = true;
    o.ShowDeprecatedOps = true; // specify to show deprecated versions
    o.DocumentSettings = s =>
    {
    s.DocumentName = "Release 2";
    @@ -42,7 +42,7 @@ public override void Configure()
    {
    Get("say-hello");
    AllowAnonymous();
    Version(0, deprecateAt: 1);
    Version(0, deprecateAt: 1); // every endpoint needs to specify deprecation
    }

    public override Task HandleAsync(CancellationToken c)
    @@ -54,7 +54,7 @@ class MyEndpoint_V1 : MyEndpoint
    public override void Configure()
    {
    base.Configure();
    Version(1, deprecateAt: 2);
    Version(1, deprecateAt: 2); // every endpoint needs to specify deprecation
    }
    }

    @@ -63,6 +63,6 @@ class MyEndpoint_V2 : MyEndpoint
    public override void Configure()
    {
    base.Configure();
    Version(2, deprecateAt: 3);
    Version(2, deprecateAt: 3); // every endpoint needs to specify deprecation
    }
    }
  3. @dj-nitehawk dj-nitehawk created this gist Sep 13, 2023.
    68 changes: 68 additions & 0 deletions Program.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,68 @@
    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;
    o.DocumentSettings = s =>
    {
    s.DocumentName = "Release 1";
    s.Version = "v1";
    };
    })
    .SwaggerDocument(o =>
    {
    o.MaxEndpointVersion = 2;
    o.ShowDeprecatedOps = true;
    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);
    }

    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);
    }
    }

    class MyEndpoint_V2 : MyEndpoint
    {
    public override void Configure()
    {
    base.Configure();
    Version(2, deprecateAt: 3);
    }
    }