本文整理汇总了C#中IServiceCollection.ConfigureSwaggerSchema方法的典型用法代码示例。如果您正苦于以下问题:C# IServiceCollection.ConfigureSwaggerSchema方法的具体用法?C# IServiceCollection.ConfigureSwaggerSchema怎么用?C# IServiceCollection.ConfigureSwaggerSchema使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IServiceCollection
的用法示例。
在下文中一共展示了IServiceCollection.ConfigureSwaggerSchema方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConfigureServices
/// <summary>
/// This method gets called by a runtime.
/// Use this method to add services to the container
/// </summary>
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc(c =>
{
var jsonFormatter = c.OutputFormatters.OfType<JsonOutputFormatter>().First();
jsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
jsonFormatter.SerializerSettings.Converters.Add(new StringEnumConverter { CamelCaseText = true });
jsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/html"));
});
// Uncomment the following line to add Web API services which makes it easier to port Web API 2 controllers.
// You will also need to add the Microsoft.AspNet.Mvc.WebApiCompatShim package to the 'dependencies' section of project.json.
//// services.AddWebApiConventions();
services.AddSwagger();
services.ConfigureSwaggerDocument(c =>
{
c.SingleApiVersion(new Info { Version = "v1", Title = "GreenvilleWiApi" });
c.OperationFilter<GreenvilleApiFilter>();
c.OperationFilter<ApplySwaggerOperationFilterAttributes>();
c.DocumentFilter<GreenvilleApiFilter>();
c.IgnoreObsoleteActions = true;
});
services.ConfigureSwaggerSchema(c =>
{
c.DescribeAllEnumsAsStrings = true;
c.ModelFilter<GreenvilleApiFilter>();
});
}
示例2: ConfigureServices
// This method gets called by a runtime.
// Use this method to add services to the container
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
// Uncomment the following line to add Web API services which makes it easier to port Web API 2 controllers.
// You will also need to add the Microsoft.AspNet.Mvc.WebApiCompatShim package to the 'dependencies' section of project.json.
// services.AddWebApiConventions();
services.AddSwagger();
services.ConfigureSwaggerDocument(options =>
{
options.SingleApiVersion(new Info
{
Version = "v1",
Title = "Swashbuckle Sample API",
Description = "A sample API for testing Swashbuckle",
TermsOfService = "Some terms ..."
});
options.OperationFilter<AssignOperationVendorExtensions>();
});
services.ConfigureSwaggerSchema(options =>
{
options.DescribeAllEnumsAsStrings = true;
});
}
示例3: ConfigureServices
// This method gets called by the runtime. Use this method to add services to the container
public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
services.AddApplicationInsightsTelemetry(Configuration);
services.AddMvc();
services.AddSwaggerGen();
var filePath = Environment.CurrentDirectory.Split(new[] { "src" }, StringSplitOptions.None)[0] + Configuration["Documentation:SwaggerDocXml"];
services.ConfigureSwaggerDocument(options =>
{
options.SingleApiVersion(new Info
{
Version = "v1",
Title = "Todo API",
Description = "A sample api",
TermsOfService = "None"
});
options.OperationFilter(new Swashbuckle.SwaggerGen.XmlComments.ApplyXmlActionComments(filePath));
});
services.ConfigureSwaggerSchema(options =>
{
options.DescribeAllEnumsAsStrings = true;
options.ModelFilter(new Swashbuckle.SwaggerGen.XmlComments.ApplyXmlTypeComments(filePath));
});
services.AddSingleton<ITodoRepository, TodoRepository>();
}
示例4: ConfigureServices
public void ConfigureServices(IServiceCollection services)
{
// add Entity Framework
services.AddEntityFramework()
.AddSqlServer()
.AddDbContext<MoviesAppContext>(options =>
options.UseSqlServer("Server=(localdb)\\mssqllocaldb;Database=MoviesDatabase;Trusted_Connection=True;MultipleActiveResultSets=true"));
// add ASP.NET Identity
services.AddIdentity<ApplicationUser, IdentityRole>() //Configuration)
.AddEntityFrameworkStores<MoviesAppContext>()
.AddDefaultTokenProviders();
// add ASP.NET MVC
services.AddMvc();
services.AddSwagger();
services.ConfigureSwaggerDocument(options =>
{
options.SingleApiVersion(new Info
{
Version = "v2",
Title = "Swashbuckle Sample API",
Description = "A sample API for testing Swashbuckle",
TermsOfService = "Some terms ..."
});
options.OperationFilter<AssignOperationVendorExtensions>();
});
services.ConfigureSwaggerSchema(options =>
{
options.DescribeAllEnumsAsStrings = true;
});
}
示例5: ConfigureServices
// This method gets called by a runtime.
// Use this method to add services to the container
public void ConfigureServices(IServiceCollection services)
{
services.Configure<AppSettings>(Configuration.GetSection("AppSettings"));
services.AddMvc();
services.AddCors();
services.AddSwagger();
services.ConfigureSwaggerSchema(o =>
{
o.DescribeAllEnumsAsStrings = true;
});
services.ConfigureSwaggerDocument(o =>
{
o.SingleApiVersion(new Info
{
Version = "v1",
Title = "Film Industry Network API",
Description = "Documentation of the API for interfacing with the Film Industry Network",
TermsOfService = "Use at your own risk"
});
});
services.AddRouting();
services.AddSingleton<IContext, NetworkContext>();
services.AddScoped<IPersonRepository, PersonRepository>();
services.AddScoped<IMovieRepository, MovieRepository>();
services.AddScoped<IPersonService, PersonService>();
services.AddScoped<IMovieService, MovieService>();
services.AddScoped<IGraphMovieService, GraphMovieService>();
services.AddScoped<IGraphPersonService, GraphPersonService>();
services.AddTransient<IDataCollectorFactory, DataCollectorFactory>();
services.Configure<MvcOptions>(options =>
{
var settings = new JsonSerializerSettings
{
TypeNameHandling = TypeNameHandling.Auto
};
var jsonFormatter = options.OutputFormatters.Single(o => o.GetType() == typeof(JsonOutputFormatter));
options.OutputFormatters.Remove(jsonFormatter);
var outputFormatter = new JsonOutputFormatter { SerializerSettings = settings };
options.OutputFormatters.Add(outputFormatter);
});
//services.AddWebApiConventions();
}
示例6: ConfigureServices
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
services.AddMvc()
.AddJsonOptions(
opts => { opts.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); });
services.AddSwaggerGen();
services.ConfigureSwaggerDocument(options =>
{
options.SingleApiVersion(new Info
{
Version = "v1",
Title = "PetStore",
Description = "An example ASP.NET 5 Web API 2.2 of Swagger PetStore"
});
});
services.ConfigureSwaggerSchema(options => { options.DescribeAllEnumsAsStrings = true; });
}
示例7: ConfigureServices
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
services.AddMvc();
services.AddSwagger();
services.ConfigureSwaggerDocument(options =>
{
options.SingleApiVersion(new Info
{
Version = "v1",
Title = "Swashbuckle Sample API",
Description = "A sample API for testing Swashbuckle",
TermsOfService = "Some terms ..."
});
});
services.ConfigureSwaggerSchema(options =>
{
options.DescribeAllEnumsAsStrings = true;
});
}
示例8: ConfigureServices
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
string xmlComments = string.Format(@"{0}{4}artifacts{4}{1}{4}{2}{3}{4}Kasisto.API.xml",
GetSolutionBasePath(),
_appEnv.Configuration,
_appEnv.RuntimeFramework.Identifier.ToLower(),
_appEnv.RuntimeFramework.Version.ToString().Replace(".", string.Empty),
Path.DirectorySeparatorChar);
// Add framework services.
services.AddMvc()
.AddJsonOptions(
opts => { opts.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); });
// Uncomment the following line to add Web API services which makes it easier to port Web API 2 controllers.
// You will also need to add the Microsoft.AspNet.Mvc.WebApiCompatShim package to the 'dependencies' section of project.json.
// services.AddWebApiConventions();
services.AddSwaggerGen();
services.ConfigureSwaggerDocument(options =>
{
options.SingleApiVersion(new Info
{
Version = "v1",
Title = "Kasisto.API",
Description = "Kasisto.API (ASP.NET 5 Web API 2.x)"
});
options.OperationFilter(new ApplyXmlActionCommentsFixed(xmlComments));
});
services.ConfigureSwaggerSchema(options => {
options.DescribeAllEnumsAsStrings = true;
options.ModelFilter(new ApplyXmlTypeCommentsFixed(xmlComments));
});
}
示例9: ConfigureServices
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.Configure<AuthSettings>(Configuration.GetSection("Auth"));
// Add framework services.
services.AddApplicationInsightsTelemetry(Configuration);
services.AddEntityFramework()
.AddSqlServer()
.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"]));
/*
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
*/
services.AddMvc();
// Add application services.
services.AddTransient<IEmailSender, AuthMessageSender>();
services.AddTransient<ISmsSender, AuthMessageSender>();
services.AddTransient<IUserIdentityService, UserIdentityService>();
var mapperConfig = new MapperConfiguration(cfg =>{});
services.AddSingleton<IMapper>(provider => mapperConfig.CreateMapper());
// swagger
services.AddSwaggerGen();
services.ConfigureSwaggerDocument(options =>
{
options.MultipleApiVersions(new Info[]
{
new Swashbuckle.SwaggerGen.Info
{
Version = "v1",
Title = "Dite API",
Description = "Dite RESTful API"
},
new Swashbuckle.SwaggerGen.Info
{
Version = "v2",
Title = "Dite API (v2)",
Description = "Dite RESTful API"
}
}, VersionSupportResolver);
//options.OperationFilter(new Swashbuckle.SwaggerGen.XmlComments.ApplyXmlActionComments(pathToDoc));
});
services.ConfigureSwaggerSchema(options =>
{
options.DescribeAllEnumsAsStrings = true;
//options.ModelFilter(new Swashbuckle.SwaggerGen.XmlComments.ApplyXmlTypeComments(pathToDoc));
});
}
示例10: ConfigureServices
// This method gets called by a runtime.
// Use this method to add services to the container
public void ConfigureServices(IServiceCollection services)
{
services.AddOptions();
services.Configure<AppSettings>(Configuration);
services.AddMvc();
// Uncomment the following line to add Web API services which makes it easier to port Web API 2 controllers.
// You will also need to add the Microsoft.AspNet.Mvc.WebApiCompatShim package to the 'dependencies' section of project.json.
// services.AddWebApiConventions();
services.AddSwagger();
services.ConfigureSwaggerDocument(options =>
{
options.SingleApiVersion(new Info
{
Version = "v1",
Title = "Gateway API",
Description = "The documentation for the Gateway API"
});
});
services.ConfigureSwaggerSchema(options =>
{
options.DescribeAllEnumsAsStrings = true;
});
}
示例11: ConfigureServices
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc(options =>
{
options.OutputFormatters.Clear();
options.OutputFormatters.Add(new HypermediaApiJsonOutputFormatter());
options.InputFormatters.Clear();
var inputFormatter = new HypermediaApiJsonInputFormatter();
inputFormatter.AcceptedContentTypes.Add("text/plain");
options.InputFormatters.Add(inputFormatter);
// TODO: automatize filter discovering and registering using reflection (take into account standard and service filters)
options.Filters.Add(new PayloadValidationFilter());
options.Filters.Add(new RequiredPayloadFilter());
});
services.AddApiServices();
services.AddApiMappers(typeof(Startup).GetTypeInfo().Assembly);
// TODO: take into account these
// services.AddScoped<CacheDirectory>();
// services.AddLinkHelper<LinkHelper>();
// services.AddLogging();
services.AddCors(options =>
options.AddPolicy("Default", builder =>
builder.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader()
.AllowCredentials()));
services.AddSwaggerGen();
services.ConfigureSwaggerDocument(options =>
{
options.SingleApiVersion(new Swashbuckle.SwaggerGen.Info()
{
Version = "current",
Title = "Relay API"
});
// TODO: take into account these
// options.OperationFilter<RelationMetadataOperationFilter>();
// options.DocumentFilter<DocumentFilter>();
});
services.ConfigureSwaggerSchema(options =>
{
// TODO: move this and other code to a new independent project
options.DescribeAllEnumsAsStrings = true;
// TODO: take into account this
// options.ModelFilter<LinkModelFilter>();
options.CustomSchemaIds(T =>
T.GetTypeInfo()
.GetCustomAttributes(false)
.OfType<SchemaAttribute>()
.FirstOrDefault()?.SchemaName
?? T.Name);
});
services.AddInstance(RemoteMediaConfiguration);
}
示例12: ConfigureSwagger
private void ConfigureSwagger(IServiceCollection services)
{
services.AddSwaggerGen();
services.ConfigureSwaggerDocument(options => {
options.SingleApiVersion(new Info
{
Version = "v1",
Title = "Matter Center API Version V1",
Description = "This matter center api is for V1 release"
});
options.IgnoreObsoleteActions = true;
options.OperationFilter(new Swashbuckle.SwaggerGen.XmlComments.ApplyXmlActionComments(pathToDoc));
});
services.ConfigureSwaggerSchema(options =>
{
options.DescribeAllEnumsAsStrings = true;
options.IgnoreObsoleteProperties = true;
options.ModelFilter(new Swashbuckle.SwaggerGen.XmlComments.ApplyXmlTypeComments(pathToDoc));
});
}
示例13: ConfigureServices
// For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
public IServiceProvider ConfigureServices(IServiceCollection services)
{
services.AddEntityFramework()
.AddInMemoryDatabase()
.AddDbContext<DatabaseContext>(
options => options.UseInMemoryDatabase());
services.AddMvc();
services.AddSwagger();
services.ConfigureSwaggerDocument(options =>
{
options.IgnoreObsoleteActions = true;
options.SingleApiVersion(new Info
{
Version = "v1",
Title = "Ignite API",
Description = "The Ignite API",
TermsOfService = "",
Contact = new Contact
{
Name = "Oconics Pty Ltd",
Email = "[email protected]",
Url = "http://www.oconics.com"
},
License = new License { Name = "License Terms Here...", Url = "http://www.oconics.com" }
});
});
services.ConfigureSwaggerSchema(options =>
{
options.DescribeAllEnumsAsStrings = true;
});
var serviceProvider = ConfigureDependencyInjection(services);
return serviceProvider;
}
示例14: ConfigureSwaggerApiDocumentation
private void ConfigureSwaggerApiDocumentation(IServiceCollection services)
{
string pathToXmlDoc = Path.Combine(_hostingEnvironment.WebRootPath, "bin", "Debug", "dnxcore50", "WebAPI.xml");
Console.WriteLine(pathToXmlDoc);
if (!File.Exists(pathToXmlDoc))
{
pathToXmlDoc = String.Empty;
}
services.AddSwaggerGen();
services.ConfigureSwaggerDocument(options =>
{
options.SingleApiVersion(new Info()
{
Version = "v1",
Title = "Sample ASP.NET Core 1.0 API",
Description = "Sample Web API to show case ASP.NET Core 1.0 compared to Node.js",
Contact = new Contact()
{
Name = "Thinktecture AG",
Email = "[email protected]",
Url = "http://thinktecture.com"
}
});
if (!String.IsNullOrWhiteSpace(pathToXmlDoc))
{
options.OperationFilter(new ApplyXmlActionComments(pathToXmlDoc));
}
});
services.ConfigureSwaggerSchema(options =>
{
if (!String.IsNullOrWhiteSpace(pathToXmlDoc))
{
options.ModelFilter(new ApplyXmlTypeComments(pathToXmlDoc));
}
});
}