Andrey Golubev
Andrey Golubev

Reputation: 141

How to set 1.1 API version as default in Swagger

I have such settings that set my v1 as default:

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

How can I set 1.1 to DefaultApiVersion? There are no string, double or float constructor of ApiVersion

Upvotes: 0

Views: 548

Answers (2)

Xinran Shen
Xinran Shen

Reputation: 9993

I'm guessing you misunderstood this setting.

Are you setting like this:

services.AddApiVersioning(config =>
{
    config.DefaultApiVersion = new ApiVersion(1.1, 0);
    config.AssumeDefaultVersionWhenUnspecified = true;
});

and it will report an error.

check the source code about ApiVersion, It is described like:

// Summary:
        //     Initializes a new instance of the Microsoft.AspNetCore.Mvc.ApiVersion class.
        //
        // Parameters:
        //   majorVersion:
        //     The major version.
        //
        //   minorVersion:
        //     The minor version.
        public ApiVersion(int majorVersion, int minorVersion)
            : this(null, majorVersion, minorVersion, null)
        {
        }

So, you just need to set:

//version 1.1
config.DefaultApiVersion = new ApiVersion(1, 1);

Upvotes: 1

Lindstrøm
Lindstrøm

Reputation: 456

Try to add this:

services.AddVersionedApiExplorer(options =>
    {
        options.GroupNameFormat = "'v'VVV";
        options.SubstituteApiVersionInUrl = true;
    });

Upvotes: 0

Related Questions