Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Support custom supported/deprecated version headers #875

Copy link
Copy link
Closed
@pinkfloydx33

Description

@pinkfloydx33
Issue body actions

Is there an existing issue for this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe the problem.

Our APIs use header versioning with a custom header name, x-ourcompany-api-version. We were able to easily achieve this using the tools available in this library.

This x-ourcompany- header prefix convention applies to many of the headers we emit/consume generally, but particularly to the supported/deprecated API version headers. At present, those header names are hard-coded into the DefaultApiVersionReporter:

private const string ApiSupportedVersions = "api-supported-versions";
private const string ApiDeprecatedVersions = "api-deprecated-versions";

This required us to provide our own custom IReportApiVersions implementation. It's a nearly verbatim copy of the DefaultApiVersionReporter that reads the header names from options instead. I also have to take care to register/replace the service as well.

Describe the solution you'd like

I propose that the api-supported-versions and api-deprecated-versions header names be read from options, defaulting/falling-back to the existing constants.

For example, perhaps something akin to:

builder.Services.AddApiVersioning(options =>
{
    // reporting api versions will return the headers
    // "api-supported-versions" and "api-deprecated-versions"
    options.ReportApiVersions = true;
    options.SupportedVersionsHeader = "x-custom-api-supported-versions";
    options.DeprecatedVersionsHeader = "x-custom-api-deprecated-versions";
});

Additional context

The obvious work around is to continue with our custom implementation. This is really heavy handed considering we only need to customize the header names. It also suffers from the fact that it doesn't automatically receive updates to the source material (suppose the writing of the sunset policy or optimizations to the header output changes).

Perhaps if the class weren't sealed it could have virtual members for either retrieving the header names or writing the headers, though the latter would work best with a change in accessibility of AddApiVersionHeader (which might actually be useful on its own). This would at least make is easier for us to customize the behavior without needing to reimplement the entire class if new options are deemed undesirable.

cocowalla

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.