예제 #1
0
        private static void Configuration(IAppBuilder appBuilder)
        {
            var config = new HttpConfiguration
            {
                IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always
            };
            var server = new HttpServer(config);

            appBuilder.UseWebApi(server);
            config.EnableSwagger(c =>
            {
                // Use "SingleApiVersion" to describe a single version API. Swagger 2.0 includes an "Info" object to
                // hold additional metadata for an API. Version and title are required but you can also provide
                // additional fields by chaining methods off SingleApiVersion.
                //
                c.SingleApiVersion("v1", "A title for your API");

                // Wrap the default SwaggerGenerator with additional behavior (e.g. caching) or provide an
                // alternative implementation for ISwaggerProvider with the CustomProvider option.
                //
                c.CustomProvider(defaultProvider => new ODataSwaggerProvider(defaultProvider, c, config));
            }).EnableSwaggerUi();

            FormatterConfig.Register(config);

            config.Services.Replace(typeof(IHttpControllerSelector), new RestierControllerSelector(config));
#if Restier
            await config.MapRestierRoute <EntityFrameworkApi <TestRestierODataContext> >("RESTierRoute", "restier", new RestierBatchHandler(server));
#endif

            config.EnsureInitialized();
        }
예제 #2
0
        public static HttpConfiguration GetStandardHttpConfig(this IAppBuilder appBuilder, Type targetController, Action <SwaggerDocsConfig> unitTestConfigs = null)
        {
            var config = new HttpConfiguration
            {
                IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always
            };
            var server = new HttpServer(config);

            appBuilder.UseWebApi(server);
            config.EnableSwagger(c =>
            {
                // Use "SingleApiVersion" to describe a single version API. Swagger 2.0 includes an "Info" object to
                // hold additional metadata for an API. Version and title are required but you can also provide
                // additional fields by chaining methods off SingleApiVersion.
                //
                c.SingleApiVersion("v1", "A title for your API");

                // Wrap the default SwaggerGenerator with additional behavior (e.g. caching) or provide an
                // alternative implementation for ISwaggerProvider with the CustomProvider option.
                //
                c.CustomProvider(defaultProvider => new ODataSwaggerProvider(defaultProvider, c, config));

                // Apply test-specific configs
                unitTestConfigs?.Invoke(c);
            }).EnableSwaggerUi();

            FormatterConfig.Register(config);

            config.Services.Replace(typeof(IHttpControllerSelector), new UnitTestControllerSelector(config, targetController));

            return(config);
        }
예제 #3
0
        /// <summary>
        /// This code configures Web API.
        /// The TestWebApiStartup class is specified as a type parameter in the WebApp.Start method.
        /// </summary>
        /// <param name="appBuilder">The application builder.</param>
        public async void NorthwindConfiguration(IAppBuilder appBuilder)
        {
            var config = new HttpConfiguration
            {
                IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always
            };
            var server = new HttpServer(config);

            WebApiConfig.Register(config);
            appBuilder.UseWebApi(server);

            config
            .EnableSwagger(c =>
            {
                // Use "SingleApiVersion" to describe a single version API. Swagger 2.0 includes an "Info" object to
                // hold additional metadata for an API. Version and title are required but you can also provide
                // additional fields by chaining methods off SingleApiVersion.
                //
                c.SingleApiVersion("v1", "A title for your API");

                // Wrap the default SwaggerGenerator with additional behavior (e.g. caching) or provide an
                // alternative implementation for ISwaggerProvider with the CustomProvider option.
                //
                c.CustomProvider(defaultProvider => new ODataSwaggerProvider(defaultProvider, c, config));
            })
            .EnableSwaggerUi();

            FormatterConfig.Register(config);

            config.Services.Replace(typeof(IHttpControllerSelector), new RestierControllerSelector(config));

            var customSwaggerRoute = await config.MapRestierRoute <DbApi <NorthwindContext> >("RESTierRoute", "restier", new RestierBatchHandler(server));

            config.AddCustomSwaggerRoute(customSwaggerRoute, "/Customers({CustomerId})/Orders({OrderId})")
            .Operation(HttpMethod.Get)
            .PathParameter <string>("CustomerId")
            .PathParameter <int>("OrderId");

            config.EnsureInitialized();
        }
예제 #4
0
        public static HttpConfiguration ConfigureHttpConfig(this IAppBuilder appBuilder, HttpConfiguration config, Action <SwaggerDocsConfig> swaggerDocsConfig, Action <ODataSwaggerDocsConfig> odataSwaggerDocsConfig, params Type[] targetControllers)
        {
            var server = new HttpServer(config);

            appBuilder.UseWebApi(server);
            config.EnableSwagger(c =>
            {
                // Use "SingleApiVersion" to describe a single version API. Swagger 2.0 includes an "Info" object to
                // hold additional metadata for an API. Version and title are required but you can also provide
                // additional fields by chaining methods off SingleApiVersion.
                //
                c.SingleApiVersion("v1", "A title for your API");

                // Wrap the default SwaggerGenerator with additional behavior (e.g. caching) or provide an
                // alternative implementation for ISwaggerProvider with the CustomProvider option.
                //
                c.CustomProvider(defaultProvider => new ODataSwaggerProvider(defaultProvider, c, config).Configure(odataSwaggerDocsConfig));

                //Add the xml comments File
                var baseDirectory    = AppDomain.CurrentDomain.BaseDirectory;
                var commentsFileName = "SwashbuckleODataSample.XML";
                var commentsFile     = Path.Combine(baseDirectory, commentsFileName);
                if (File.Exists(commentsFile))
                {
                    c.IncludeXmlComments(commentsFile);
                }

                // Apply test-specific configs
                swaggerDocsConfig?.Invoke(c);
            }).EnableSwaggerUi();

            FormatterConfig.Register(config);

            config.Services.Replace(typeof(IHttpControllerSelector), new UnitTestControllerSelector(config, targetControllers));

            return(config);
        }