public void Configure(IServiceCollection services, IConfiguration configuration)
        {
            if (SillycoreAppBuilder.Instance.DataStore.Get <bool>(Constants.UseSwagger))
            {
                services.AddSwaggerGen(c =>
                {
                    SwaggerConfiguration swaggerConfiguration = new SwaggerConfiguration();
                    configuration.Bind("Sillycore:Swagger", swaggerConfiguration);

                    c.SwaggerDoc(swaggerConfiguration.Version, swaggerConfiguration.GetSwaggerInfo());

                    c.AddSecurityDefinition("Bearer", new ApiKeyScheme
                    {
                        Description = "JWT Authorization header using the Bearer scheme. Example: \"Authorization: Bearer {token}\"",
                        Name        = "Authorization",
                        In          = "header",
                        Type        = "apiKey"
                    });
                    c.DescribeAllEnumsAsStrings();
                    c.DescribeStringEnumsInCamelCase();
                    c.DescribeAllParametersInCamelCase();
                    c.IgnoreObsoleteActions();
                    c.IgnoreObsoleteProperties();

                    string filePath = Path.Combine(PlatformServices.Default.Application.ApplicationBasePath, $"{SillycoreAppBuilder.Instance.DataStore.Get<string>(Constants.ApplicationName)}.xml");

                    if (File.Exists(filePath))
                    {
                        c.IncludeXmlComments(filePath);
                    }
                });
            }
        }
Esempio n. 2
0
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, IConfiguration configuration, IServiceProvider serviceProvider)
        {
            if (SillycoreAppBuilder.Instance.DataStore.Get <bool>(Constants.UseSwagger))
            {
                SwaggerConfiguration swaggerConfiguration = new SwaggerConfiguration();
                configuration.Bind("Sillycore:Swagger", swaggerConfiguration);

                app.UseSwagger();
                app.UseSwaggerUI(c =>
                {
                    c.SwaggerEndpoint($"/swagger/{swaggerConfiguration.Version}/swagger.json", swaggerConfiguration.Version);
                });
            }
        }