简体   繁体   中英

Swashbuckle Swagger asking for api-version?

We have implemented api versioning as mentioned here https://referbruv.com/blog/integrating-aspnet-core-api-versions-with-swagger-ui/

But why are we getting this api-version fields when it should know that it is version 2?

在此处输入图像描述

I have decorated the endpoint with the following yet it still displays this api-version field?

[HttpGet("summary/all")]
[MapToApiVersion("1.0")]

I have also done the same for the v2 endpoint but change to 2.0

Adding the ApiVersionReader seemed to correct this:

services.AddApiVersioning(setup =>
{
    setup.AssumeDefaultVersionWhenUnspecified = true;
    setup.DefaultApiVersion = new ApiVersion(1, 0);
    setup.ReportApiVersions = true;
    setup.ApiVersionReader = ApiVersionReader.Combine(new UrlSegmentApiVersionReader(),
        new HeaderApiVersionReader("x-api-version"),
        new MediaTypeApiVersionReader("x-api-version"));
});

A full example of what works for me can be found as the answer in this question Replacing app.UseMvc() with app.UserRouting() gives us error `The request matched multiple endpoints`

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM