Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can I configure swashbuckle to display the api version instead of the v{version} variable?

I'm using Swashbuckle to document my Web API 2.2 API. When I load the Swagger page, the uri's display with a version placeholder variable instead of the actual version. For example:

/api/v{version}/authentication

Instead of:

/api/v2/authentication

How can I configure my app or Swashbuckle to display the version number instead of the version variable?

like image 626
user9393635 Avatar asked Oct 17 '22 16:10

user9393635


1 Answers

Updated code for WebApiConfig:

// Web API configuration and services
            var constraintResolver = new System.Web.Http.Routing.DefaultInlineConstraintResolver()
            {
                ConstraintMap =
                {
                    ["apiVersion"] = typeof(Microsoft.Web.Http.Routing.ApiVersionRouteConstraint)
                }
            };

            config.AddVersionedApiExplorer(opt =>
            {
                opt.SubstituteApiVersionInUrl = true;

            });

            config.MapHttpAttributeRoutes(constraintResolver);
            config.AddApiVersioning();

            // Web API routes
            //config.MapHttpAttributeRoutes();

            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );

Some references Swagger

like image 96
Boxed Avatar answered Oct 20 '22 01:10

Boxed