Exemple #1
0
        public void EnableSwaggerUi(string routeTemplate, Action <SwaggerUiConfig> configure = null)
        {
            SecurityScheme secScheme = null;
            var            config    = new SwaggerUiConfig(_config.DiscoveryPaths(_route), _config.GetRootUrl);

            if (configure != null)
            {
                if (_config.ApiKeyScheme != null)
                {
                    secScheme = _config.ApiKeyScheme.Build();
                    config.ApiKeySupport(secScheme.name, secScheme.@in);
                }
                configure(config);
            }

            _httpConfig.Routes.MapHttpRoute(
                name: "swagger_ui" + routeTemplate,
                routeTemplate: routeTemplate,
                defaults: null,
                constraints: new { assetPath = @".+" },
                handler: new SwaggerUiHandler(config)
                );

            if (routeTemplate == DefaultRouteTemplate)
            {
                _httpConfig.Routes.MapHttpRoute(
                    name: "swagger_ui_shortcut",
                    routeTemplate: "swagger",
                    defaults: null,
                    constraints: new { uriResolution = new HttpRouteDirectionConstraint(HttpRouteDirection.UriResolution) },
                    handler: new RedirectHandler(_config.GetRootUrl, "swagger/ui/index"));
            }
        }
Exemple #2
0
        public void EnableSwaggerUi(string routeTemplate, Action <SwaggerUiConfig> configure = null)
        {
            var config = new SwaggerUiConfig(_config.DiscoveryPaths(_route), _config.GetRootUrl);

            configure?.Invoke(config);

            _httpConfig.Routes.MapHttpRoute(
                name: "swagger_ui" + routeTemplate,
                routeTemplate: routeTemplate,
                defaults: null,
                constraints: new { assetPath = @".+" },
                handler: new SwaggerUiHandler(config)
                );

            if (routeTemplate == DefaultRouteTemplate)
            {
                _httpConfig.Routes.MapHttpRoute(
                    name: "swagger_ui_shortcut",
                    routeTemplate: "swagger",
                    defaults: null,
                    constraints: new { uriResolution = new HttpRouteDirectionConstraint(HttpRouteDirection.UriResolution) },
                    handler: new RedirectHandler(_config.GetRootUrl, "swagger/ui/index"));
            }
        }
Exemple #3
0
 public SwaggerUiHandler(SwaggerUiConfig config)
 {
     _config = config;
 }