Leverage MultipleApiVersions in Swagger with attribute versioning

后端 未结 2 1833
一生所求
一生所求 2021-01-04 14:06

Is it possible to leverage MultipleApiVersions in Swagger UI / Swashbuckle when using attribute routing?

Specifically, I implemented versioning by:



        
2条回答
  •  不知归路
    2021-01-04 15:07

    Swagger supports multiple versions. Configure the URL such that Swagger can specify the version correctly.

    httpConfiguration
    .EnableSwagger(c =>
        {
            c.MultipleApiVersions(
                (apiDesc, targetApiVersion) => ResolveVersionSupportByRouteConstraint(apiDesc, targetApiVersion),
                (vc) =>
                {
                    vc.Version("v2", "Swashbuckle Dummy API V2");
                    vc.Version("v1", "Swashbuckle Dummy API V1");
                });
        });
    .EnableSwaggerUi(c =>
        {
            c.EnableDiscoveryUrlSelector();
        });
    
    
        private static bool ResolveVersionSupportByRouteConstraint(ApiDescription apiDesc, string targetApiVersion)
        {
            return apiDesc.ActionDescriptor.ControllerDescriptor.ControllerType.FullName.Contains($"{targetApiVersion}.");
        }
    

    References:

    • https:https://github.com/domaindrivendev/Swashbuckle#describing-multiple-api-versions

提交回复
热议问题