question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`Asp.Versioning.Http` package support

See original GitHub issue

HI

Thanks for the awesome package. Its awesome.

we add versions to our Apis via api header:

services.AddApiVersioning(options =>
        {
            options.AssumeDefaultVersionWhenUnspecified = true;
            options.DefaultApiVersion = ApiVersion.Default;
            options.ReportApiVersions = true;
            options.ApiVersionReader = new HeaderApiVersionReader("api-version");
        });

The API versioning on https://fast-endpoints.com/docs/api-versioning#deprecate-an-endpoint uses a path for the versioning. For fast endpoints we are also using the “Configure()” override. How can we utilize our version header for apis and using the Configure option. The “Version()” override does not appear to work 😕

Would be awesome if it fastendpoints could support https://github.com/dotnet/aspnet-api-versioning

Thanks again…

Issue Analytics

  • State:closed
  • Created 10 months ago
  • Reactions:1
  • Comments:22 (12 by maintainers)

github_iconTop GitHub Comments

2reactions
dj-nitehawkcommented, Apr 26, 2023

okay soo… with v5.9.0.1-beta you can now do the following (if you really must) 😉

using Asp.Versioning;
using Asp.Versioning.Builder;
using Asp.Versioning.Conventions;
using FastEndpoints;
using FastEndpoints.Swagger;

var builder = WebApplication.CreateBuilder();

builder.Services
    .AddApiVersioning(o =>
    {
        o.DefaultApiVersion = new(1.0);
        o.AssumeDefaultVersionWhenUnspecified = true;
        o.ApiVersionReader = new HeaderApiVersionReader("x-api-version");
    })
    .AddApiExplorer(o => o.GroupNameFormat = "'v'VVV");

var versionSet = new ApiVersionSetBuilder(null)
    .HasApiVersion(1.0)
    .HasApiVersion(2.0)
    .Build();

builder.Services
    .AddSingleton(versionSet) //this is the only part that's specific to FastEndpoints
    .AddFastEndpoints()
    .AddSwaggerDoc(x =>
    {
        x.DocumentName = "version one";
        x.ApiGroupNames = new[] { "v1" }; //needs to conform to 'GroupNameFormat' above
    })
    .AddSwaggerDoc(x =>
    {
        x.DocumentName = "version two";
        x.ApiGroupNames = new[] { "v2" }; //needs to conform to 'GroupNameFormat' above
    });

var app = builder.Build();
app.UseAuthorization()
   .UseFastEndpoints()
   .UseSwaggerGen();
app.Run();

public class Endpoint_v1 : Endpoint<Request>
{
    public ApiVersionSet VersionSet { get; set; }

    public override void Configure()
    {
        Post("test");
        AllowAnonymous();
        Options(x => x
            .WithApiVersionSet(VersionSet)
            .MapToApiVersion(1.0));
    }

    public override async Task HandleAsync(Request r, CancellationToken c)
    {
        await SendAsync($"v1 - {r.Name}");
    }
}

public class Endpoint_v2 : Endpoint<Request>
{
    public ApiVersionSet VersionSet { get; set; }

    public override void Configure()
    {
        Post("test");
        AllowAnonymous();
        Options(x => x
            .WithApiVersionSet(VersionSet)
            .MapToApiVersion(2.0));
    }

    public override async Task HandleAsync(Request r, CancellationToken c)
    {
        await SendAsync($"v2 - {r.Name}");
    }
}

public sealed class Request
{
    public string Name { get; set; }
}
1reaction
zfchaicommented, Apr 26, 2023

Let’s first take a look at two images, as follows:

  • using FastEndpoints.Swagger;

d6083dd70651c6d03e168f66f9d020a

  • using IGeekFan.AspNetCore.Knife4jUI;

ebdcd8c2d5e75e73d7aef09c75f13d3

demo => Solution1.zip

The above API essentially only has three APIs, as shown below:

  • /my/create
  • /user/create
  • /your/create

My belongs to Admin,The other two APIs belong to Users。

Reference Documents:https://fast-endpoints.com/docs/swagger-support#swagger-operation-tags

After testing, it is clear that it does not meet expectations. Are you sure this is not a problem?

Do you understand what I mean, or should you tell me what to do?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Asp.Versioning.Http 7.0.1
This package contains the foundational library for API versioning with ASP.NET Core and only includes support for Minimal APIs. For additional functionality ...
Read more >
ASP.NET API Versioning
Provides a set of libraries which add service API versioning to ASP. ... The client-side libraries make it simple to create API version-aware...
Read more >
Which package should be used for versioning API ...
I am using NET 7 in a project and I have a question about which package to use for versioning API controllers. There...
Read more >
How to version minimal APIs in ASP.NET Core 6
Install the API versioning NuGet packages. ASP.NET Core 6 minimal APIs support versioning using any of these three packages: Asp.Versioning.Http ...
Read more >
ASP.NET Core Versioning: Minimal APIs - CodeWithStu
Versioning.Http package from NuGet. It's worth noting that the name of this package has changed from the previous Microsoft.AspNetCore.Mvc.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found