private static OpenApiInfo CreateInfoForApiVersion(ApiVersionDescription description, OpenApiSettings settings)
        {
            var contact = new OpenApiContact
            {
                Name  = (string.IsNullOrWhiteSpace(settings.Contact?.Name))?null: settings.Contact.Name,
                Email = (string.IsNullOrWhiteSpace(settings.Contact?.Email))?null:settings.Contact.Email,
                Url   = (string.IsNullOrWhiteSpace(settings.Contact?.Url)) ? null : new Uri(settings.Contact.Url)
            };
            var license = new OpenApiLicense
            {
                Name = (string.IsNullOrWhiteSpace(settings.License?.Name) ? null : settings.License.Name),
                Url  = (string.IsNullOrWhiteSpace(settings.License?.Url)) ? null : new Uri(settings.License.Url)
            };
            var apiDescription = (string.IsNullOrWhiteSpace(settings.ServiceDescription))
                ? ApiName
                : settings.ServiceDescription;

            return(new OpenApiInfo()
            {
                Title = $"{ApiName}",
                Version = description.ApiVersion.ToString(),
                Description = (description.IsDeprecated)
                            ? $"{apiDescription} This API version has been deprecated."
                            : apiDescription,
                Contact = contact,
                License = license,
                TermsOfService = (string.IsNullOrWhiteSpace(settings.TermsOfServiceUrl))?null:new Uri(settings.TermsOfServiceUrl)
            });
        }
Exemplo n.º 2
0
        public void Configure(SwaggerGenOptions options)
        {
            if (_swaggerConfiguration.ServerUri != null)
            {
                options.AddServer(new OpenApiServer {
                    Url = _swaggerConfiguration.ServerUri.ToString()
                });
            }

            OpenApiLicense license = null;

            if (!string.IsNullOrWhiteSpace(_swaggerConfiguration.License.Name))
            {
                license = new OpenApiLicense
                {
                    Name = _swaggerConfiguration.License.Name,
                    Url  = _swaggerConfiguration.License.Url,
                };
            }
            foreach (ApiVersionDescription description in _provider.ApiVersionDescriptions)
            {
                options.SwaggerDoc(
                    description.GroupName,
                    new OpenApiInfo
                {
                    Title   = _swaggerConfiguration.Title,
                    Version = description.ApiVersion.ToString(),
                    License = license,
                });
            }
        }
Exemplo n.º 3
0
        internal static void Add(ref IServiceCollection services, IConfiguration configuration)
        {
            var apiVersionDescriptionProvider = services.BuildServiceProvider().GetService <IApiVersionDescriptionProvider>();

            services.AddSwaggerGen(config =>
            {
                var title          = "SimpleChat.API";
                var description    = "This is a Web API for SimpleChat Application";
                var termsOfService = new Uri("https://github.com/SimpleChatApp/SimpleChat-WebAPI/blob/master/LICENSE");
                var license        = new OpenApiLicense()
                {
                    Name = "MIT"
                };
                var contact = new OpenApiContact()
                {
                    Name  = "Sevcan Alkan",
                    Email = "*****@*****.**",
                    Url   = new Uri("https://github.com/SevcanAlkan")
                };

                foreach (var versionDescription in apiVersionDescriptionProvider.ApiVersionDescriptions)
                {
                    config.SwaggerDoc(versionDescription.GroupName, new OpenApiInfo
                    {
                        Version        = versionDescription.ApiVersion.ToString(),
                        Title          = title + $" {versionDescription.ApiVersion.ToString()}",
                        Description    = description,
                        TermsOfService = termsOfService,
                        License        = license,
                        Contact        = contact
                    });
                }

                // config.ResolveConflictingActions(apiDescriptions => apiDescriptions.First());
                // config.CustomSchemaIds(x => x.FullName);

                // XML Documentation settings for the Swagger
                var xmlCommentsFile         = $"{Assembly.GetAssembly(typeof(Program)).GetName().Name}.xml";
                var xmlCommentsFileFullPath = Path.Combine(AppContext.BaseDirectory, xmlCommentsFile);
                config.IncludeXmlComments(xmlCommentsFileFullPath);

                config.DocumentFilter <SwaggerDocsFilter>();
            });

            // services.Configure<ApiBehaviorOptions>(options =>
            // {
            //     options.InvalidModelStateResponseFactory = actionContext =>
            //     {
            //         var actionExecutingContext = actionContext as Microsoft.AspNetCore.Mvc.Filters.ActionExecutingContext;

            //         if (actionExecutingContext.ModelState.ErrorCount > 0
            //             && actionExecutingContext?.ActionArguments.Count == actionContext.ActionDescriptor.Parameters.Count)
            //         {
            //             return new UnprocessableEntityObjectResult(actionContext.ModelState);
            //         }

            //         return new BadRequestObjectResult(actionContext.ModelState);
            //     };
            // });
        }
Exemplo n.º 4
0
        private void ConfigureSwagger(IServiceCollection services)
        {
            var contact = new OpenApiContact()
            {
                Name  = "Daniil Nichitenco",
                Email = "*****@*****.**",
                Url   = new Uri("http://www.example.com")
            };

            var license = new OpenApiLicense()
            {
                Name = "My License",
                Url  = new Uri("http://www.example.com")
            };

            var info = new OpenApiInfo()
            {
                Version        = "v1",
                Title          = "Swagger Expense Tracker API",
                Description    = "Swagger Expense Tracker API Description",
                TermsOfService = new Uri("http://www.example.com"),
                Contact        = contact,
                License        = license
            };

            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", info);
            });
        }
Exemplo n.º 5
0
        public static IServiceCollection AddSwaggerConfiguration(this IServiceCollection services)
        {
            var contact = new OpenApiContact()
            {
                Name  = "Demo API",
                Email = "*****@*****.**"
            };

            var license = new OpenApiLicense()
            {
                Name = "Demo API",
                Url  = new Uri("https://demoapi.com")
            };

            var info = new OpenApiInfo()
            {
                Version        = "v1",
                Title          = "Demo API",
                Description    = "Demo API",
                TermsOfService = new Uri("https://demoapi.com"),
                Contact        = contact,
                License        = license
            };

            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("DemoAPI", info);
                c.ResolveConflictingActions(apiDescriptions => apiDescriptions.First());

                //Adding configuration of jwt for swagger UI ----------------------------------

                c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme()
                {
                    Description = @"JWT Authorization header using the Bearer scheme. 
                      Enter 'Bearer' [space] and then your token in the text input below.
                      Example: 'Bearer 12345abcdef'",
                    Name        = "Authorization",
                    In          = ParameterLocation.Header,
                    Type        = SecuritySchemeType.ApiKey,
                    Scheme      = "Bearer"
                });
                c.AddSecurityRequirement(new OpenApiSecurityRequirement()
                {
                    {
                        new OpenApiSecurityScheme
                        {
                            Reference = new OpenApiReference
                            {
                                Type = ReferenceType.SecurityScheme,
                                Id   = "Bearer"
                            }
                        },
                        new List <string>()
                    }
                });
                //----------------------------------------
            });

            return(services);
        }
Exemplo n.º 6
0
        static OpenApiInfo CreateInfoForApiVersion(ApiVersionDescription description)
        {
            var contact = new OpenApiContact()
            {
                Name  = "Miloslav Moravec",
                Email = "*****@*****.**",
                Url   = new Uri("https://www.alza.cz")
            };

            var license = new OpenApiLicense()
            {
                Name = "My License",
                Url  = new Uri("https://www.alza.cz")
            };

            var info = new OpenApiInfo()
            {
                Version     = description.ApiVersion.ToString(),
                Title       = "Swagger Demo API",
                Description = "Swagger API for Alza products",
                Contact     = contact,
                License     = license
            };

            if (description.IsDeprecated)
            {
                info.Description += "This API version has been deprecated";
            }

            return(info);
        }
Exemplo n.º 7
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();
            var contact = new OpenApiContact()
            {
                Name  = "Prashant Aggarwal",
                Email = "*****@*****.**",
                Url   = new Uri("http://www.example.com")
            };

            var license = new OpenApiLicense()
            {
                Name = "My License",
                Url  = new Uri("http://www.example.com")
            };

            var info = new OpenApiInfo()
            {
                Version        = "v1",
                Title          = "Swagger Demo API",
                Description    = "Swagger Demo API Description",
                TermsOfService = new Uri("http://www.example.com"),
                Contact        = contact,
                License        = license
            };

            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", info);
                var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
                var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
                c.IncludeXmlComments(xmlPath);
            });
        }
Exemplo n.º 8
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddDbContext <HDataSetContext>(opt =>
                                                    opt.UseMySql(Configuration.GetConnectionString("HDataSet"))
                                                    );

            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);

            //Register the Swagger generator, defining 1 or more Swagger documents
            services.AddSwaggerGen(c => {
                c.SwaggerDoc("v1", new OpenApiInfo {
                    Title          = "HDataSetApi",
                    Version        = "v1",
                    Description    = "Horticulture Data Set that store info about relation between plants",
                    TermsOfService = new Uri("https://*****:*****@protonmail.com"
                                      Url = new Uri("https://linkedin.com/wilgon")
                    },
                    License = new OpenApiLicense {
                        Name = "Use under MIT License",
                        Url  = new Uri("https://example.com/license"),
                    }
                });
Exemplo n.º 9
0
        private static OpenApiInfo CreateInfoForApiVersion(ApiVersionDescription description)
        {
            OpenApiInfo info = new()
            {
                Title       = "Clean Architecture KPMG",
                Version     = description.ApiVersion.ToString(),
                Description = "",
                Contact     = new OpenApiContact {
                    Name = "nome aqui", Email = "email@aqui"
                },
                TermsOfService = new Uri(UriString),
                License        = new OpenApiLicense
                {
                    Name = "Apache License",
                    Url  = new Uri(
                        UriString1)
                }
            };

            if (description.IsDeprecated)
            {
                info.Description += " This API version has been deprecated.";
            }

            return(info);
        }
    }
Exemplo n.º 10
0
        public static void RegisterServices(IServiceCollection services)
        {
            services.AddSwaggerGen(options =>
            {
                var contato = new OpenApiContact()
                {
                    Name  = "Igor Freitas Couto",
                    Email = "*****@*****.**",
                    Url   = new Uri("https://github.com/igor-couto/cities-br-api")
                };

                var licenca = new OpenApiLicense()
                {
                    Name = "Licença Apache 2.0",
                    Url  = new Uri("https://www.apache.org/licenses/LICENSE-2.0.html")
                };

                options.SwaggerDoc("v1",
                                   new OpenApiInfo {
                    Title       = "API Cidades Br",
                    Version     = "1.0",
                    Description = "API de Cidades do Brasil",
                    Contact     = contato,
                    License     = licenca
                });

                var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
                var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);

                if (File.Exists(xmlPath))
                {
                    options.IncludeXmlComments(xmlPath);
                }
            });
        }
Exemplo n.º 11
0
        public void Configure(SwaggerGenOptions options)
        {
            var openApiContact = new OpenApiContact()
            {
                Name  = configuration["ConfigurationOptions:SwaggerGenOptions:OpenApiContact_Name"],
                Email = configuration["ConfigurationOptions:SwaggerGenOptions:OpenApiContact_Email"],
                Url   = new Uri(configuration["ConfigurationOptions:SwaggerGenOptions:CompanyUrl"])
            };

            var openApiLicense = new OpenApiLicense()
            {
                Name = configuration["ConfigurationOptions:SwaggerGenOptions:OpenApiLicense_Name"],
                Url  = new Uri(configuration["ConfigurationOptions:SwaggerGenOptions:CompanyUrl"])
            };

            foreach (var description in provider.ApiVersionDescriptions)
            {
                options.SwaggerDoc(
                    description.GroupName,
                    new OpenApiInfo()
                {
                    Title          = $"{configuration["ConfigurationOptions:SwaggerGenOptions:ProjectName"]} {description.ApiVersion}",
                    Version        = description.ApiVersion.ToString(),
                    Description    = configuration["ConfigurationOptions:SwaggerGenOptions:ProjectDescription"],
                    TermsOfService = new Uri(configuration["ConfigurationOptions:SwaggerGenOptions:CompanyUrl"]),
                    Contact        = openApiContact,
                    License        = openApiLicense
                });
            }
        }
Exemplo n.º 12
0
        private void ConfigureSwagger(IServiceCollection services)
        {
            var contact = new OpenApiContact()
            {
                Name  = "Ivan Scoropad",
                Email = "*****@*****.**",
            };

            var license = new OpenApiLicense()
            {
                Name = "My License",
            };

            var info = new OpenApiInfo()
            {
                Version     = "v1",
                Title       = "Swagger Demo API",
                Description = "Swagger Api YourChoice",
                Contact     = contact,
                License     = license
            };

            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", info);
            });
        }
Exemplo n.º 13
0
        private void ConfigureSwagger(IServiceCollection services)
        {
            var contact = new OpenApiContact()
            {
                Name  = "FirstName LastName",
                Email = "*****@*****.**",
                Url   = new Uri("http://www.example.com")
            };

            var license = new OpenApiLicense()
            {
                Name = "My License",
                Url  = new Uri("http://www.example.com")
            };

            var info = new OpenApiInfo()
            {
                Version        = "v1",
                Title          = "Swagger Demo API",
                Description    = "Swagger Demo API Description",
                TermsOfService = new Uri("http://www.example.com"),
                Contact        = contact,
                License        = license
            };

            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", info);
            });
        }
Exemplo n.º 14
0
        /// <summary>
        /// Adds Swagger to the services.
        /// </summary>
        /// <param name="value">The <see cref="IServiceCollection"/> to add the service to.</param>
        /// <param name="environment">The current hosting environment.</param>
        /// <returns>
        /// The value specified by <paramref name="value"/>.
        /// </returns>
        public static IServiceCollection AddSwagger(this IServiceCollection value, IWebHostEnvironment environment)
        {
            return(value.AddSwaggerGen(
                       (p) =>
            {
                var provider = value.BuildServiceProvider();
                var options = provider.GetRequiredService <SiteOptions>();

                var terms = new UriBuilder()
                {
                    Scheme = "https",
                    Host = options.Metadata?.Domain !,
                    Path = "terms-of-service/",
                };

                var info = new OpenApiInfo()
                {
                    Contact = new OpenApiContact()
                    {
                        Name = options.Metadata?.Author?.Name,
                        Url = new Uri(options.Metadata?.Repository !, UriKind.Absolute),
                    },
                    Description = options.Metadata?.Description,
                    License = new OpenApiLicense()
                    {
                        Name = "Apache 2.0",
                        Url = new Uri("https://www.apache.org/licenses/LICENSE-2.0.html", UriKind.Absolute),
                    },
                    TermsOfService = terms.Uri,
                    Title = options.Metadata?.Name,
                    Version = string.Empty,
                };
Exemplo n.º 15
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddDbContext <ApplicationDbContext>(options =>
                                                         options.UseSqlServer(
                                                             Configuration.GetConnectionString("DefaultConnection")));
            services.AddDefaultIdentity <IdentityUser>(options => options.SignIn.RequireConfirmedAccount = false)
            .AddEntityFrameworkStores <ApplicationDbContext>();
            services.AddControllersWithViews();
            services.AddRazorPages();

            services.Configure <IdentityOptions>(options =>
            {
                // Password settings.
                options.Password.RequireDigit           = true;
                options.Password.RequireLowercase       = true;
                options.Password.RequireNonAlphanumeric = false;
                options.Password.RequireUppercase       = false;
                options.Password.RequiredLength         = 6;
                options.Password.RequiredUniqueChars    = 1;

                // Lockout settings.
                options.Lockout.DefaultLockoutTimeSpan  = TimeSpan.FromMinutes(485);
                options.Lockout.MaxFailedAccessAttempts = 3;
                options.Lockout.AllowedForNewUsers      = true;

                // User settings.
                options.User.AllowedUserNameCharacters =
                    "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._@+";
                options.User.RequireUniqueEmail = false;
            });

            var contact = new OpenApiContact()
            {
                Name  = "FirstName LastName",
                Email = "*****@*****.**",
                Url   = new Uri("http://www.example.com")
            };

            var license = new OpenApiLicense()
            {
                Name = "My License",
                Url  = new Uri("http://www.example.com")
            };

            var info = new OpenApiInfo()
            {
                Version        = "v1",
                Title          = "Swagger Demo API",
                Description    = "Swagger Demo API Description",
                TermsOfService = new Uri("http://www.example.com"),
                Contact        = contact,
                License        = license
            };

            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", info);
            });
        }
Exemplo n.º 16
0
 public void Traverse(OpenApiLicense license)
 {
     if (license == null)
     {
         return;
     }
     Visitor.Visit(license);
 }
Exemplo n.º 17
0
        /// <summary>
        /// Visits <see cref="OpenApiLicense"/> and child objects
        /// </summary>
        internal void Walk(OpenApiLicense license)
        {
            if (license == null)
            {
                return;
            }

            _visitor.Visit(license);
        }
Exemplo n.º 18
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();

            //Register the Swagger generator, defining 1 or more Swagger documents
            //services.AddSwaggerGen(c =>
            //{
            //    c.SwaggerDoc("v1", new OpenApiInfo { Title = "My API", Version = "v1" });
            //});

            services.AddControllers(options =>
            {
                options.Conventions.Add(new GroupingByNamespaceConvention());
            });

            services.AddSwaggerGen(config =>
            {
                var titlebase      = "Ytdemo1";
                var desc           = "Description";
                var termsofservice = new Uri("http://achrafbenalaya.com/");
                var license        = new OpenApiLicense()
                {
                    Name = "MIT"
                };

                var contact = new OpenApiContact()
                {
                    Name  = "achraf",
                    Email = "*****@*****.**",
                    Url   = new Uri("http://achrafbenalaya.com/")
                };


                config.SwaggerDoc("v1", new OpenApiInfo
                {
                    Version        = "v1",
                    Title          = titlebase + " V 1",
                    Description    = desc,
                    Contact        = contact,
                    License        = license,
                    TermsOfService = termsofservice
                });

                config.SwaggerDoc("v2", new OpenApiInfo
                {
                    Version        = "v2",
                    Title          = titlebase + " V2",
                    Description    = desc,
                    Contact        = contact,
                    License        = license,
                    TermsOfService = termsofservice
                });
            }

                                   );
        }
        internal static OpenApiLicense LoadLicense(ParseNode node)
        {
            var mapNode = node.CheckMapNode("License");

            var license = new OpenApiLicense();

            ParseMap(mapNode, license, _licenseFixedFields, _licensePatternFields);

            return(license);
        }
        internal OpenApiLicense ToOpenApi()
        {
            var item = new OpenApiLicense()
            {
                Name       = this.Name,
                Url        = new Uri(this.Url),
                Extensions = this.Extensions
            };

            return(item);
        }
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            var connection = Configuration.GetConnectionString("Student1Database");

            services.AddDbContextPool <Student1Context>(options => options.UseSqlServer(connection));
            services.AddControllers();
            services.AddScoped <IStudent, StudentRepository>();

            var contact = new OpenApiContact()
            {
                Name  = "FirstName LastName",
                Email = "*****@*****.**",
                Url   = new Uri("http://www.example.com")
            };

            var license = new OpenApiLicense()
            {
                Name = "My License",
                Url  = new Uri("http://www.example.com")
            };

            var info = new OpenApiInfo()
            {
                Version        = "v1",
                Title          = "Swagger Demo API",
                Description    = "Swagger Demo API Description",
                TermsOfService = new Uri("http://www.example.com"),
                Contact        = contact,
                License        = license
            };

            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", info);
            });

            services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
            .AddJwtBearer(options =>
            {
                options.TokenValidationParameters = new TokenValidationParameters
                {
                    ValidateIssuer           = true,
                    ValidateAudience         = true,
                    ValidateLifetime         = true,
                    ValidateIssuerSigningKey = true,
                    ValidIssuer      = Configuration["Jwt:Issuer"],
                    ValidAudience    = Configuration["Jwt:Issuer"],
                    IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration["Jwt:Key"]))
                };
            });
        }
Exemplo n.º 22
0
    private OALicense CreateLicence(OpenApiLicense openApiLicense)
    {
        if (openApiLicense == null)
        {
            return(new OALicense());
        }

        return(new OALicense()
        {
            Name = openApiLicense.Name,
            Url = openApiLicense.Url.ToString(),
            Present = true,
        });
    }
Exemplo n.º 23
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddCors(options =>
            {
                options.AddPolicy(name: _originsCors,
                                  builder =>
                {
                    builder.WithOrigins("http://*****:*****@example.com",
                Url   = new Uri("http://www.example.com")
            };

            var license = new OpenApiLicense()
            {
                Name = "My License",
                Url  = new Uri("http://www.example.com")
            };

            var info = new OpenApiInfo()
            {
                Version        = "v1",
                Title          = "Swagger Demo API",
                Description    = "Swagger Demo API Description",
                TermsOfService = new Uri("http://www.example.com"),
                Contact        = contact,
                License        = license
            };

            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", info);
            });

            services.AddScoped <IWriterExcel, WriterExcel>();
        }
Exemplo n.º 24
0
        // TODO: extract all methods into extensions.
        public void ConfigureServices(IServiceCollection services, IConfiguration configuration)
        {
            services.AddDbContext <ApiObjectContext>(optionsBuilder =>
            {
                optionsBuilder.UseSqlServerWithLazyLoading(services);
            });

            AddRequiredConfiguration();

            AddBindingRedirectsFallbacks();

            JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();

            AddTokenGenerationPipeline(services);

            AddAuthorizationPipeline(services);

            var contact = new OpenApiContact()
            {
                Name  = "FirstName LastName",
                Email = "*****@*****.**",
                Url   = new Uri("http://www.example.com")
            };

            var license = new OpenApiLicense()
            {
                Name = "My License",
                Url  = new Uri("http://www.example.com")
            };

            var info = new OpenApiInfo()
            {
                Version        = "v1",
                Title          = "Swagger Demo API",
                Description    = "Swagger Demo API Description",
                TermsOfService = new Uri("http://www.example.com"),
                Contact        = contact,
                License        = license
            };

            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", info);
            });
        }
Exemplo n.º 25
0
 public static OpenApiInfo Info(
     string title,
     string version,
     string description,
     string termsOfService,
     OpenApiContact contact,
     OpenApiLicense license)
 {
     return(new OpenApiInfo
     {
         Title = title,
         Version = version,
         Description = description,
         TermsOfService = new Uri(termsOfService),
         Contact = contact,
         License = license
     });
 }
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers(options =>
            {
                options.Conventions.Add(new GroupingByNamespaceConvention());
            });

            services.AddSwaggerGen(config =>
            {
                var titleBase      = "Movies API";
                var description    = "This is a Web API for Movies operations";
                var TermsOfService = new Uri("https://udemy.com/user/felipegaviln/");
                var License        = new OpenApiLicense()
                {
                    Name = "MIT"
                };
                var Contact = new OpenApiContact()
                {
                    Name  = "Felipe Gavilán",
                    Email = "*****@*****.**",
                    Url   = new Uri("https://gavilan.blog/")
                };

                config.SwaggerDoc("v1", new OpenApiInfo
                {
                    Version        = "v1",
                    Title          = titleBase + " v1",
                    Description    = description,
                    TermsOfService = TermsOfService,
                    License        = License,
                    Contact        = Contact
                });

                config.SwaggerDoc("v2", new OpenApiInfo
                {
                    Version        = "v2",
                    Title          = titleBase + " v2",
                    Description    = description,
                    TermsOfService = TermsOfService,
                    License        = License,
                    Contact        = Contact
                });
            });
        }
Exemplo n.º 27
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddCors(o => o.AddPolicy("MyPolicy", builder =>
            {
                builder.AllowAnyOrigin()
                .AllowAnyMethod()
                .AllowAnyHeader();
            }));

            services.AddControllers();
            var contact = new OpenApiContact()
            {
                Name  = "FirstName LastName",
                Email = "*****@*****.**",
                Url   = new Uri("http://www.example.com")
            };
            var license = new OpenApiLicense()
            {
                Name = "My License",
                Url  = new Uri("http://www.example.com")
            };

            var info = new OpenApiInfo()
            {
                Version        = "v1",
                Title          = "Swagger Demo API",
                Description    = "Swagger Demo API Description",
                TermsOfService = new Uri("http://www.example.com"),
                Contact        = contact,
                License        = license
            };

            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", info);
            });

            services.AddScoped <IAuthenticationService, AuthenticationService>();
            services.AddScoped <IAuthenticationRepository, AuthenticationRepository>();
            services.AddScoped <IUserRepository, UserRepository>();
            services.AddScoped <IUserService, UserService>();
        }
        private static OpenApiInfo CreateInfoForApiVersion(ApiVersionDescription description)
        {
            OpenApiInfo info = new()
            {
                Title       = "Startup WEB",
                Version     = description.ApiVersion.ToString(),
                Description = "A sample web application with Swagger, Swashbuckle, and API versioning.",
                License     = new OpenApiLicense()
                {
                    Name = "MIT", Url = new Uri("https://opensource.org/licenses/MIT")
                }
            };

            if (description.IsDeprecated)
            {
                info.Description += " This API version has been deprecated.";
            }

            return(info);
        }
    }
Exemplo n.º 29
0
        public void ValidateFieldIsRequiredInLicense()
        {
            // Arrange
            IEnumerable <OpenApiError> errors;
            OpenApiLicense             license = new OpenApiLicense();

            // Act
            var validator = new OpenApiValidator();
            var walker    = new OpenApiWalker(validator);

            walker.Walk(license);

            errors = validator.Errors;
            bool result = !errors.Any();

            // Assert
            Assert.False(result);
            Assert.NotNull(errors);
            OpenApiError error = Assert.Single(errors);

            Assert.Equal(String.Format(SRResource.Validation_FieldIsRequired, "name", "license"), error.Message);
        }
Exemplo n.º 30
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddScoped <IUserStore, UsersStore>();
            services.AddSingleton <AuthService>();

            services.AddControllers();

            var cont = new OpenApiContact {
                Url = new Uri("https://*****:*****@asd.asd", Name = "Developer"
            };
            var licence = new OpenApiLicense {
                Name = "APACHE", Url = new Uri("https://localhost:44313/#license")
            };

            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo {
                    Title = "WebAPIApp", Version = "v1", Contact = cont, Description = "Test Web API project", TermsOfService = new Uri("https://localhost:44313/#terms"), License = licence
                });
            });

            services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
            .AddJwtBearer(opts => {
                //opts.RequireHttpsMetadata = false;
                opts.TokenValidationParameters = new TokenValidationParameters {
                    ValidateIssuer = true,
                    ValidIssuer    = AuthOptions.ISSUER,

                    ValidateAudience = true,
                    ValidAudience    = AuthOptions.AUDIENCE,

                    ValidateLifetime = true,

                    ValidateIssuerSigningKey = true,
                    IssuerSigningKey         = AuthOptions.GetKey()
                };
            });
        }