samples/server/petstore/aspnetcore-mixed/src/IO.Swagger/Startup.cs
/// <summary>
/// This method gets called by the runtime. Use this method to add services to the container.
/// </summary>
/// <param name="services"></param>
This method gets called by the runtime. Use this method to add services to the container.
This method gets called by the runtime . Use this method to add services to the container .
public void ConfigureServices(IServiceCollection services)
        {
            services
                .AddMvc(options =>
                {
                    options.InputFormatters.RemoveType<Microsoft.AspNetCore.Mvc.Formatters.SystemTextJsonInputFormatter>();
                    options.OutputFormatters.RemoveType<Microsoft.AspNetCore.Mvc.Formatters.SystemTextJsonOutputFormatter>();
                })
                .AddNewtonsoftJson(opts =>
                {
                    opts.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
                    opts.SerializerSettings.Converters.Add(new StringEnumConverter(new CamelCaseNamingStrategy()));
                })
                .AddXmlSerializerFormatters();
            services.AddAuthentication(ApiKeyAuthenticationHandler.SchemeName)
                .AddScheme<AuthenticationSchemeOptions, ApiKeyAuthenticationHandler>(ApiKeyAuthenticationHandler.SchemeName, null);
            services.AddAuthentication(ApiKeyAuthenticationHandler.SchemeName)
                .AddScheme<AuthenticationSchemeOptions, ApiKeyAuthenticationHandler>(ApiKeyAuthenticationHandler.SchemeName, null);
            services.AddAuthentication(BasicAuthenticationHandler.SchemeName)
                .AddScheme<AuthenticationSchemeOptions, BasicAuthenticationHandler>(BasicAuthenticationHandler.SchemeName, null);
            services.AddAuthentication(BearerAuthenticationHandler.SchemeName)
                .AddScheme<AuthenticationSchemeOptions, BearerAuthenticationHandler>(BearerAuthenticationHandler.SchemeName, null);
            services.AddAuthentication(BearerAuthenticationHandler.SchemeName)
                .AddScheme<AuthenticationSchemeOptions, BearerAuthenticationHandler>(BearerAuthenticationHandler.SchemeName, null);
            services
                .AddSwaggerGen(c =>
                {
                    c.SwaggerDoc("1.0.0", new OpenApiInfo
                    {
                        Version = "1.0.0",
                        Title = "Swagger Petstore",
                        Description = "Swagger Petstore (ASP.NET Core 3.1)",
                        Contact = new OpenApiContact()
                        {
                           Name = "Swagger Codegen Contributors",
                           Url = new Uri("https://github.com/swagger-api/swagger-codegen"),
                           Email = "apiteam@swagger.io"
                        },
                        TermsOfService = new Uri("http://swagger.io/terms/")
                    });
                    c.CustomSchemaIds(type => type.FullName);
                    c.IncludeXmlComments($"{AppContext.BaseDirectory}{Path.DirectorySeparatorChar}{_hostingEnv.ApplicationName}.xml");
                    c.OperationFilter<GeneratePathParamsValidationFilter>();
                });
        }
public void ConfigureServices ( IServiceCollection services ) { services . AddMvc ( options => { options . InputFormatters . RemoveType < Microsoft . AspNetCore . Mvc . Formatters . SystemTextJsonInputFormatter > ( ) ; options . OutputFormatters . RemoveType < Microsoft . AspNetCore . Mvc . Formatters . SystemTextJsonOutputFormatter > ( ) ; } ) . AddNewtonsoftJson ( opts => { opts . SerializerSettings . ContractResolver = new CamelCasePropertyNamesContractResolver ( ) ; opts . SerializerSettings . Converters . Add ( new StringEnumConverter ( new CamelCaseNamingStrategy ( ) ) ) ; } ) . AddXmlSerializerFormatters ( ) ; services . AddAuthentication ( ApiKeyAuthenticationHandler . SchemeName ) . AddScheme < AuthenticationSchemeOptions , ApiKeyAuthenticationHandler > ( ApiKeyAuthenticationHandler . SchemeName , null ) ; services . AddAuthentication ( ApiKeyAuthenticationHandler . SchemeName ) . AddScheme < AuthenticationSchemeOptions , ApiKeyAuthenticationHandler > ( ApiKeyAuthenticationHandler . SchemeName , null ) ; services . AddAuthentication ( BasicAuthenticationHandler . SchemeName ) . AddScheme < AuthenticationSchemeOptions , BasicAuthenticationHandler > ( BasicAuthenticationHandler . SchemeName , null ) ; services . AddAuthentication ( BearerAuthenticationHandler . SchemeName ) . AddScheme < AuthenticationSchemeOptions , BearerAuthenticationHandler > ( BearerAuthenticationHandler . SchemeName , null ) ; services . AddAuthentication ( BearerAuthenticationHandler . SchemeName ) . AddScheme < AuthenticationSchemeOptions , BearerAuthenticationHandler > ( BearerAuthenticationHandler . SchemeName , null ) ; services . AddSwaggerGen ( c => { c . SwaggerDoc ( " " , new OpenApiInfo { Version = " " , Title = " " , Description = " " , Contact = new OpenApiContact ( ) { Name = " " , Url = new Uri ( " " ) , Email = " " } , TermsOfService = new Uri ( " " ) } ) ; c . CustomSchemaIds ( type => type . FullName ) ; c . IncludeXmlComments ( $" { AppContext . BaseDirectory } { Path . DirectorySeparatorChar } { _hostingEnv . ApplicationName } .xml " ) ; c . OperationFilter < GeneratePathParamsValidationFilter > ( ) ; } ) ; }
This method gets called by the runtime.
This method gets called by the runtime .
// Add framework services. // Include DataAnnotation attributes on Controller Action parameters as Swagger validation rules (e.g required, pattern, ..) // Use [ValidateModelState] on Actions to actually validate it in C# as well!
services
IServiceCollection
None