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

Can an API version be supported but not advertised? #1117

Open
jovinson-ms opened this issue Dec 24, 2024 · 1 comment
Open

Can an API version be supported but not advertised? #1117

jovinson-ms opened this issue Dec 24, 2024 · 1 comment
Assignees
Labels

Comments

@jovinson-ms
Copy link

Based off the discussion here it sounds possible - I haven't been able to find a way to not advertise an API version that is added by namespace convention.

The specific use case is to add a preview API version that only a small number of users would be aware of without advertising it in the header.

@commonsensesoftware
Copy link
Collaborator

Yes, it's possible. There are a few possible solutions, but the simplest is probably to replace the IReportApiVersions service. The built-in DefaultApiVersionReporter is sealed, but it's still very easy to decorate. You would filter out undesired API versions from the model before they are reported. You can then forward the rest of the logic to the default implementation.

Something like:

sealed class MyApiVersionReporter(ISunsetPolicyManager sunsetPolicyManager) : IReportApiVersions
{
    readonly DefaultApiVersionReporter inner = new(sunsetPolicyManager);

    public ApiVersionMapping Mapping => inner.Mapping;

    public void Report(HttpResponse response, ApiVersionModel apiVersionModel)
    {
        // TODO: apply your filtering
        apiVersionModel = new(
            apiVersionModel.SupportedApiVersions.Where(v => true),
            apiVersionModel.DeprecatedApiVersions.Where(v => true));

        inner.Report(response, apiVersionModel);
    }
}

This would omit API versions you don't want to advertise from being emitted, but it doesn't change any declarations. Routing will continue to as is with your undisclosed versions.

You'd register it with:

services.Add(ServiceDescriptor.Singleton<IReportApiVersions, MyApiVersionReporter>());

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

No branches or pull requests

2 participants