本文整理汇总了C#中System.Web.Http.HttpConfiguration.EnableSwagger方法的典型用法代码示例。如果您正苦于以下问题:C# HttpConfiguration.EnableSwagger方法的具体用法?C# HttpConfiguration.EnableSwagger怎么用?C# HttpConfiguration.EnableSwagger使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.Http.HttpConfiguration
的用法示例。
在下文中一共展示了HttpConfiguration.EnableSwagger方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Configuration
public void Configuration(IAppBuilder appBuilder, Action<ContainerBuilder> action)
{
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug()
.WriteTo.ColoredConsole()
.WriteTo.TextWriter(new StreamWriter(@"SampleProject.Provider.log"))
.CreateLogger();
var config = new HttpConfiguration();
config.MapHttpAttributeRoutes();
config
.EnableSwagger(c => c.SingleApiVersion("v1", "Sample Provider"))
.EnableSwaggerUi();
var container = GetContainer(action);
config.DependencyResolver = new AutofacWebApiDependencyResolver(container);
appBuilder
.Use(typeof(LoggingMiddleware))
.UseAutofacWebApi(config)
.UseWebApi(config);
}
示例2: Configuration
public void Configuration(IAppBuilder app)
{
var builder = new ContainerBuilder();
builder.RegisterInstance(GetDbExecutor(ConnectionString)).As<IDbExecutor>();
builder.RegisterApiControllers(Assembly.GetExecutingAssembly());
builder.RegisterType<SqlServerRepository>().As<IFeatureToggleRepository>().SingleInstance();
builder.RegisterType<FeatureToggleValidator>().As<IFeatureToggleValidator>().SingleInstance();
var container = builder.Build();
app.UseCors(CorsOptions.AllowAll);
app.UseAutofacMiddleware(container);
var config = new HttpConfiguration();
config.EnableSwagger(c => c.SingleApiVersion("v1", "Feature Toggle Service API"))
.EnableSwaggerUi();
config.DependencyResolver = new AutofacWebApiDependencyResolver(container);
config.Formatters.Remove(config.Formatters.XmlFormatter);
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
config.Services.Replace(typeof(IExceptionHandler), new UnhandledErrorService());
app.Use(typeof(AuditMiddlware));
app.UseWebApi(config);
}
示例3: ConfigureSwagger
private static void ConfigureSwagger(HttpConfiguration config)
{
config.EnableSwagger(
c => c.SingleApiVersion("v1", "IconKeeper").Description("Icon Keeper Web Api"))
.EnableSwaggerUi(
c => c.CustomAsset("index", typeof(Startup).Assembly, "IconKeeper.Server.WebApi.Swagger.index.html"));
}
示例4: InitialiseSwagger
/// <summary>
/// Initializes Swagger Documentation
/// </summary>
/// <param name="httpConfig"></param>
private static void InitialiseSwagger(HttpConfiguration httpConfig)
{
try
{
httpConfig
.EnableSwagger(c =>
{
c.SingleApiVersion("v1", "fIT Api");
c.IncludeXmlComments(GetXmlPath());
c.IgnoreObsoleteActions();
c.DescribeAllEnumsAsStrings();
c.OAuth2("oauth2")
.Description("OAuth2 Password Grant")
.Flow("password")
//.AuthorizationUrl("http://petstore.swagger.wordnik.com/api/oauth/dialog")
.TokenUrl("/Accounts/Login")
.Scopes(scopes =>
{
scopes.Add("user", "Read access to protected resources");
scopes.Add("admin", "Write access to protected resources");
});
})
.EnableSwaggerUi(c =>
{
c.InjectJavaScript(typeof(Startup).Assembly, "fIT.WebApi/js/onComplete.js");
});
}
catch (Exception e)
{
throw new Exception("Error on creating Swagger: " + e.Message + Environment.NewLine + e.StackTrace);
}
}
示例5: ConfigureHttpConfig
public static HttpConfiguration ConfigureHttpConfig(this IAppBuilder appBuilder, HttpConfiguration config, Action<SwaggerDocsConfig> unitTestConfigs, 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));
// Apply test-specific configs
unitTestConfigs?.Invoke(c);
}).EnableSwaggerUi();
FormatterConfig.Register(config);
config.Services.Replace(typeof (IHttpControllerSelector), new UnitTestControllerSelector(config, targetControllers));
return config;
}
示例6: Configuration
public void Configuration(IAppBuilder app)
{
HttpConfiguration config = new HttpConfiguration();
config.Formatters.JsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
//See info about OWIN in https://github.com/domaindrivendev/Swashbuckle
//Manually enable the Swagger docs and, optionally, the swagger-ui by invoking the
//extension methods (in namespace Swashbuckle.Application) on an instance of HttpConfiguration in Startup.cs
config
.EnableSwagger(c =>
{
c.SingleApiVersion("v1", "MyHealth.MobileApp");
// Set filter to eliminate duplicate operation ids from being generated
// when there are multiple operations with the same verb in the API.
c.OperationFilter<IncludeParameterNamesInOperationIdFilter>();
// Set another filter to eliminate duplciation operation ids from being generated
// when there are multiple Web API routes, like /tables and /api
c.OperationFilter<IncludeRouteNameInOperationIdFilter>();
}
)
.EnableSwaggerUi();
new MobileAppConfiguration()
.UseDefaultConfiguration()
.ApplyTo(config);
app.UseWebApi(config);
}
示例7: Register
public static void Register(HttpConfiguration config, AutofacWebApiDependencyResolver resolver)
{
config.EnableEnumPrefixFree(enumPrefixFree: true);
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
config.DependencyResolver = resolver;
ConfigureFormatters(config);
config.EnableSwagger("docs/{apiVersion}/", c =>
{
var baseDirectory = AppDomain.CurrentDomain.BaseDirectory + @"bin\";
var commentsFileName = Assembly.GetExecutingAssembly().GetName().Name + ".XML";
var commentsFile = Path.Combine(baseDirectory, commentsFileName);
c.IncludeXmlComments(commentsFile);
c.DescribeAllEnumsAsStrings();
c.SingleApiVersion("v1", "TaskCat Core Api");
}).EnableSwaggerUi();
}
示例8: Configuration
public void Configuration(IAppBuilder app)
{
var config = new HttpConfiguration();
config.MapHttpAttributeRoutes();
config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;
config.EnableSwagger("help/{apiVersion}", c =>
{
c.IncludeXmlComments("Slight.WeMo.Service.XML");
c.SingleApiVersion("v1", "Slight.WeMo REST Api");
}).EnableSwaggerUi("help/ui/{*assetPath}");
app.UseWebApi(config);
GlobalConfiguration.Configuration.UseMemoryStorage();
app.UseHangfireDashboard("/hangfire", new DashboardOptions
{
AuthorizationFilters = new IAuthorizationFilter[] { new AllowAllFilter() }
});
app.UseHangfireServer();
app.Use(async (context, func) =>
{
if (new[] { "/", "/help" }.Any(x => context.Request.Path.Value.StartsWith(x)))
{
context.Response.Redirect("/help/ui/index");
return;
}
await func.Invoke();
});
}
示例9: GetWebApiConfig
private static HttpConfiguration GetWebApiConfig(IAppBuilder appBuilder)
{
Metric.Config
.WithHttpEndpoint("http://localhost:9999/metrics/")
.WithReporting(r => r.WithConsoleReport(TimeSpan.FromSeconds(30)));
//.WithOwin(middleware => appBuilder.Use(middleware), x => x
// .WithRequestMetricsConfig(c => c.WithAllOwinMetrics())
// .WithMetricsEndpoint());
//.WithInternalMetrics()
// .WithAllCounters();
var config = new HttpConfiguration();
config.Formatters.Add(new JsonHalMediaTypeFormatter(BuildHypermediaConfiguration()));
config
.EnableSwagger(c =>
{
c.SingleApiVersion("v1", "A title for your API");
c.IncludeXmlComments("OwinSelfHost.XML");
})
.EnableSwaggerUi();
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "ActionApi",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional }
);
return config;
}
示例10: Register
/// <summary>
/// Registers the configuration.
/// </summary>
/// <param name="config">The http configuration</param>
public static void Register(HttpConfiguration config)
{
config
.EnableSwagger(c =>
{
// assembly comments
var baseDirectory = AppDomain.CurrentDomain.BaseDirectory + "\\Bin";
c.IncludeXmlComments(Path.Combine(baseDirectory, "AngularSkeleton.Web.Application.xml"));
c.IncludeXmlComments(Path.Combine(baseDirectory, "AngularSkeleton.Service.Model.xml"));
// information
c.SingleApiVersion("v1", "AngularSkeleton.NET")
.Description("AngularSkeleton application API")
.TermsOfService("MIT License")
.Contact(cc => cc
.Name("Christopher Town")
.Url("https://github.com/christophla/AngularSkeleton.NET"))
.License(lc => lc
.Name("License")
.Url("https://github.com/christophla/AngularSkeleton.NET/blob/master/LICENSE"));
// authorization
c
.OAuth2("oauth2")
.Description("Resource owner password credentials grant")
.Flow("password")
.AuthorizationUrl("http://localhost:54391/api/rest/v1/accesstoken");
})
.EnableSwaggerUi("api/rest/docs/{*assetPath}");
}
示例11: Register
public static void Register(HttpConfiguration configuration)
{
var serviceVersion = string.Empty;
configuration.EnableSwagger(
c =>
{
c.SingleApiVersion(string.IsNullOrEmpty(serviceVersion) ? "1" : serviceVersion, "Concept Search API")
.Description("Save drawing and share on social medias")
.Contact(cc => cc
.Name("DrawPub Team")
.Email("[email protected]"))
.License(lc => lc
.Name("DrawPub License"));
c.RootUrl(req => new Uri(req.RequestUri, req.GetRequestContext().VirtualPathRoot).ToString());
c.ResolveConflictingActions(apiDescriptions => apiDescriptions.First());
c.IgnoreObsoleteActions();
c.IncludeXmlComments(GetXmlCommentsPath());
})
.EnableSwaggerUi(
c =>
{
c.EnableDiscoveryUrlSelector();
c.DocExpansion(DocExpansion.None);
c.EnableOAuth2Support("client_id", "realm", "Swagger UI");
});
}
示例12: Configuration
public void Configuration(IAppBuilder app)
{
// SignalR - real-time io.
app.MapSignalR();
// Setting the camel case resolver for web api below does not cause camel case to be invoked for signalr
// or other serialization events. This enforces camel case through all serialization.
GlobalHost.DependencyResolver.Register(typeof(JsonSerializer), () => JsonSerializerFactory.Value);
// Configure Web API.
HttpConfiguration config = new HttpConfiguration();
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
config.Formatters.Remove(config.Formatters.XmlFormatter);
config.Formatters.JsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
config.MessageHandlers.Add(new NoCacheHeaderHandler());
app.UseWebApi(config);
// Swagger API publishing.
config.EnableSwagger(c => c.SingleApiVersion("v1", "Mouselight Acquisition Acquisition API")).EnableSwaggerUi();
MonitorManager.SharedManager.HostApplicationVersion = String.Format("v{0}", typeof(Startup).Assembly.GetName().Version);
}
示例13: Configuration
public void Configuration(IAppBuilder appBuilder)
{
HttpConfiguration config = new HttpConfiguration();
try
{
config
.EnableSwagger(c =>
{
c.RootUrl(req =>
{
return req.RequestUri.GetLeftPart(UriPartial.Authority) + "/dartshooting";
});
c.SingleApiVersion("v1", "A title for your API");
})
.EnableSwaggerUi(
);
config.EnableCors();
config.MapHttpAttributeRoutes();
RouteConfig.RegisterRoutes(config.Routes);
appBuilder.UseWebApi(config);
}
catch (Exception e)
{
Trace.WriteLine(e);
}
}
示例14: ConfigureSwagger
public static void ConfigureSwagger(HttpConfiguration config)
{
// Use the custom ApiExplorer that applies constraints. This prevents
// duplicate routes on /api and /tables from showing in the Swagger doc.
config.Services.Replace(typeof(IApiExplorer), new MobileAppApiExplorer(config));
config
.EnableSwagger(c =>
{
c.SingleApiVersion("v1", "myService");
// Tells the Swagger doc that any MobileAppController needs a
// ZUMO-API-VERSION header with default 2.0.0
c.OperationFilter<MobileAppHeaderFilter>();
// Looks at attributes on properties to decide whether they are readOnly.
// Right now, this only applies to the DatabaseGeneratedAttribute.
c.SchemaFilter<MobileAppSchemaFilter>();
// 1. Adds an OAuth implicit flow description that points to App Service Auth with the specified provdier
// 2. Adds a Swashbuckle filter that applies this Oauth description to any Action with [Authorize]
c.AppServiceAuthentication("https://{mysite}.azurewebsites.net/", "{provider}");
})
.EnableSwaggerUi(c =>
{
c.EnableOAuth2Support("na", "na", "na");
// Replaces some javascript files with specific logic to:
// 1. Do the OAuth flow using the App Service Auth parameters
// 2. Parse the returned token
// 3. Apply the token to the X-ZUMO-AUTH header
c.MobileAppUi();
});
}
示例15: Configuration
public void Configuration(IAppBuilder app)
{
ConfigureAuth(app);
//SwaggerConfig.Register();
HttpConfiguration httpConfiguration = new HttpConfiguration();
httpConfiguration.EnableSwagger(c => c.SingleApiVersion("v1", "A title for your API")).EnableSwaggerUi();
httpConfiguration.EnsureInitialized();
}