[Swagger] ApiVersionNeutralAttribute clarification #998
-
Hi guys, could you please explain how We have ApiVersioning like that: serviceCollection.AddApiVersioning(options =>
{
options.ReportApiVersions = true;
options.AssumeDefaultVersionWhenUnspecified = true;
options.ApiVersionReader = new HeaderApiVersionReader("X-Api-version");
options.ApiVersionSelector = new ConstantApiVersionSelector(ApiVersion.Default);
}).AddVersionedApiExplorer(options =>
{
options.GroupNameFormat = "'v'VVV";
}); And we have single controller with My expectation that openapi document with ApiVersionNeutralAttribute should have optional X-Api-Version header parameter. Does my assumption wrong? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
When an API is version-neutral, it will accept any API version, including none at all. In terms of API collation, a version-neutral API will appear in a group for every API version. This posits an interesting question. Should a version-neutral document an API version? It can and it would not be wrong, but it doesn't have to. Most people have indicated that they do not want to see or document the API version as input in these cases, so that is the default behavior. This can be easily be changed however. The magic is setting the serviceCollection.AddApiVersioning(options =>
{
options.ReportApiVersions = true;
options.AssumeDefaultVersionWhenUnspecified = true;
options.ApiVersionReader = new HeaderApiVersionReader("X-Api-version");
options.ApiVersionSelector = new ConstantApiVersionSelector(ApiVersion.Default);
}).AddVersionedApiExplorer(options =>
{
options.GroupNameFormat = "'v'VVV";
options.AddApiVersionParametersWhenVersionNeutral = true;
}); With this option enabled, all version-neutral APIs will show the API version parameter(s) just like any other API. |
Beta Was this translation helpful? Give feedback.
When an API is version-neutral, it will accept any API version, including none at all. In terms of API collation, a version-neutral API will appear in a group for every API version. This posits an interesting question. Should a version-neutral document an API version? It can and it would not be wrong, but it doesn't have to. Most people have indicated that they do not want to see or document the API version as input in these cases, so that is the default behavior. This can be easily be changed however. The magic is setting the
AddApiVersionParametersWhenVersionNeutral
option totrue
. For example: