コード例 #1
0
        public void EnableSwaggerUi(
            string routeTemplate,
            Action <SwaggerUiConfig> configure = null)
        {
            var config = new SwaggerUiConfig(_discoveryPaths, _rootUrlResolver);

            if (configure != null)
            {
                configure(config);
            }

            _httpConfig.Routes.MapHttpRoute(
                name: "swagger_ui",
                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: null,
                    handler: new RedirectHandler(_rootUrlResolver, "swagger/ui/index"));
            }
        }
コード例 #2
0
        public void EnableSwaggerUi(
            string routeTemplate,
            Action<SwaggerUiConfig> configure = null)
        {
            var config = new SwaggerUiConfig(_discoveryPaths, _rootUrlResolver);
            if (configure != null) configure(config);

            _httpConfig.Routes.MapHttpRoute(
                name: "swagger_ui",
                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(_rootUrlResolver, "swagger/ui/index"));
            }
        }
コード例 #3
0
        public static SwaggerUiConfig MobileAppUi(this SwaggerUiConfig config)
        {
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }

            Assembly thisAssembly = typeof(SwaggerUiConfigExtensions).Assembly;

            config.CustomAsset("o2c-html", thisAssembly, "Microsoft.Azure.Mobile.Server.Swagger.o2c.html");
            config.CustomAsset("lib/swagger-oauth-js", thisAssembly, "Microsoft.Azure.Mobile.Server.Swagger.swagger-oauth.js");

            return(config);
        }
コード例 #4
0
        public void EnableSwaggerUi(string routeTemplate, Action <SwaggerUiConfig> configure = null)
        {
            var config = new SwaggerUiConfig(_discoveryPaths, _rootUrlResolver);

            if (configure != null)
            {
                configure(config);
            }

            if (!string.IsNullOrWhiteSpace(config.RoutePrefix))
            {
                routeTemplate = config.RoutePrefix + "/" + routeTemplate;
            }

            _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(_rootUrlResolver, "swagger/ui/index"));
            }

            if (routeTemplate == config.RoutePrefix + "/" + DefaultRouteTemplate)
            {
                _httpConfig.Routes.MapHttpRoute(
                    name: "swagger_ui_shortcut" + routeTemplate,
                    routeTemplate: config.RoutePrefix + "/" + "swagger",
                    defaults: null,
                    constraints: new { uriResolution = new HttpRouteDirectionConstraint(HttpRouteDirection.UriResolution) },
                    handler: new RedirectHandler(_rootUrlResolver, config.RoutePrefix + "/" + "swagger/ui/index"));
            }
        }
コード例 #5
0
        public void EnableSwaggerUi(string routeTemplate, Action <SwaggerUiConfig> configure = null)
        {
            SwaggerUiConfig config = new SwaggerUiConfig(this._discoveryPaths, this._rootUrlResolver);

            if (configure != null)
            {
                configure(config);
            }
            HttpRouteCollectionExtensions.MapHttpRoute(this._httpConfig.get_Routes(), "swagger_ui" + routeTemplate, routeTemplate, (object)null, (object)new
            {
                assetPath = ".+"
            }, (HttpMessageHandler) new SwaggerUiHandler(config));
            if (!(routeTemplate == SwaggerEnabledConfiguration.DefaultRouteTemplate))
            {
                return;
            }
            HttpRouteCollectionExtensions.MapHttpRoute(this._httpConfig.get_Routes(), "swagger_ui_shortcut", "swagger", (object)null, (object)new
            {
                uriResolution = new HttpRouteDirectionConstraint((HttpRouteDirection)0)
            }, (HttpMessageHandler) new RedirectHandler(this._rootUrlResolver, "swagger/ui/index"));
        }
コード例 #6
0
        public static SwaggerUiConfig MobileAppUi(this SwaggerUiConfig config, HttpConfiguration httpConfig)
        {
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }

            if (httpConfig == null)
            {
                throw new ArgumentNullException("httpConfig");
            }

            httpConfig.MessageHandlers.Add(new SwaggerUiSecurityFilter(httpConfig));

            Assembly thisAssembly = typeof(SwaggerUiConfigExtensions).Assembly;

            config.CustomAsset("o2c-html", thisAssembly, "Microsoft.Azure.Mobile.Server.Swagger.o2c.html");
            config.CustomAsset("swagger-ui-min-js", thisAssembly, "Microsoft.Azure.Mobile.Server.Swagger.swagger-ui.min.js");
            config.CustomAsset("index", thisAssembly, "Microsoft.Azure.Mobile.Server.Swagger.index.html");

            return(config);
        }
コード例 #7
0
        public void EnableSwaggerUi(
            string areaRouteTemplate,
            Action <SwaggerUiConfig> configure = null)
        {
            foreach (var area in _areasDiscoveryPaths.Keys)
            {
                var routeTemplate        = areaRouteTemplate.Replace("{area}", area.Name.ToLowerInvariant());
                var configurationContext = _areasDiscoveryPaths[area];
                var config = new SwaggerUiConfig(configurationContext.DiscoveryPaths, configurationContext.RootUrlResolver);
                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(configurationContext.RootUrlResolver, "swagger/ui/index"));
                }
            }

            var swaggerEnabledConfiguration = new SwaggerEnabledConfiguration(_httpConfig, _noAreaConfigurationContext.RootUrlResolver, _noAreaConfigurationContext.DiscoveryPaths);
            var noAreaRouteTemplate         = areaRouteTemplate.Replace("{area}/", string.Empty);

            swaggerEnabledConfiguration.EnableSwaggerUi(noAreaRouteTemplate, configure);
        }
コード例 #8
0
 public SwaggerUiHandler(SwaggerSpecConfig swaggerSpecConfig, SwaggerUiConfig config)
 {
     _swaggerSpecConfig = swaggerSpecConfig;
     _swaggerUiConfig = config;
 }
コード例 #9
0
 public SwaggerUiHandler(SwaggerUiConfig config)
 {
     _config = config;
 }
コード例 #10
0
 public SwaggerUiHandler()
 {
     _config = SwaggerUiConfig.StaticInstance;
 }
コード例 #11
0
 public SwaggerUiHandler(SwaggerSpecConfig swaggerSpecConfig, SwaggerUiConfig config)
 {
     _swaggerSpecConfig = swaggerSpecConfig;
     _swaggerUiConfig   = config;
 }
コード例 #12
0
 public SwaggerUiHandler()
     : this(SwaggerUiConfig.StaticInstance)
 {
     _config = SwaggerUiConfig.StaticInstance;
 }
コード例 #13
0
 public SwaggerUiHandler(SwaggerUiConfig config)
 {
     _config = config;
 }
コード例 #14
0
        public void EnableSwaggerUi(string routeTemplate, Action<SwaggerUiConfig> configure = null)
        {
            var config = new SwaggerUiConfig(_discoveryPaths, _rootUrlResolver);
            if (configure != null) configure(config);

            var apiKey = _swaggerDocsConfig.GetApiKeyDetails();
            if (apiKey != null)
            {
                config.SetApiKeyDetails(apiKey);
            }

            _httpConfig.Routes.MapHttpRoute(
                name: "swagger_ui",
                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: null,
                    handler: new RedirectHandler(_rootUrlResolver, "swagger/ui/index"));
            }
        }