Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Versioning through custom headers no longer working after v14 upgrade #5017

Open
jfoley96 opened this issue Nov 11, 2024 · 0 comments
Open

Comments

@jfoley96
Copy link

jfoley96 commented Nov 11, 2024

Hello,
We have been using the API "Versioning through custom headers" principle, wherein nswag was generating {version} placeholder and we replaced the value based on incoming client request header value. This {version} placeholder is not available anymore after upgrading to the latest version of NSwag.

Startup.cs implementation:

` services
.AddControllers(options =>
{
options.UseGeneralRoutePrefix("api/v{version:apiVersion}");
options.EnableEndpointRouting = true;
options.Filters.Add();
})
.AddNewtonsoftJson();

        services.AddRouting(options => options.LowercaseUrls = true);

        services.AddApiVersioning(options =>
        {
            options.ReportApiVersions = true;
            options.AssumeDefaultVersionWhenUnspecified = true;
            options.DefaultApiVersion = new ApiVersion(1, 0);
        });

        services.AddInfrastructure(Configuration);

        // Register the Swagger generator, defining 1 or more Swagger documents
        services.AddOpenApiDocument(document =>
        {
            document.DocumentName = "v1";
            document.Title = "xxxxxx Web APIs";
            document.Version = "1.0";
      
            // This adds the ability to handle a custom required header in the OpenAPI contract
            document.OperationProcessors.Add(new OperationRequiredHeaderAttributes());
        });

Generated code (missing the version number in the url) :
// Operation Path: "api/v{version}/security/groups" urlBuilder_.Append("api/v"); urlBuilder_.Append("/security/groups");
`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant