Ejemplo n.º 1
0
        public static void ConfigureSwagger(this IServiceCollection services)
        {
            #region Assembly Info
            services.AddControllers();

            var assembly     = typeof(Program).Assembly;
            var assemblyInfo = assembly.GetName();

            var descriptionAttribute = assembly
                                       .GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false)
                                       .OfType <AssemblyDescriptionAttribute>()
                                       .FirstOrDefault();
            var productAttribute = assembly
                                   .GetCustomAttributes(typeof(AssemblyProductAttribute), false)
                                   .OfType <AssemblyProductAttribute>()
                                   .FirstOrDefault();
            var copyrightAttribute = assembly
                                     .GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false)
                                     .OfType <AssemblyCopyrightAttribute>()
                                     .FirstOrDefault();
            #endregion

            var openApiInfo = new Microsoft.OpenApi.Models.OpenApiInfo
            {
                Title       = productAttribute.Product,
                Version     = assemblyInfo.Version.ToString(),
                Description = descriptionAttribute.Description,
                Contact     = new Microsoft.OpenApi.Models.OpenApiContact
                {
                    Name  = copyrightAttribute.Copyright,
                    Url   = new Uri(@"https://github.com/willimar/DevelopersChallenge2"),
                    Email = "*****@*****.**",
                },
                TermsOfService = null,
                License        = new Microsoft.OpenApi.Models.OpenApiLicense()
                {
                    Name = "GNU GENERAL PUBLIC LICENSE",
                    Url  = new Uri(@"https://github.com/willimar/DevelopersChallenge2/blob/master/LICENSE")
                }
            };

            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc($"v{Program.API_V_1_0}", openApiInfo);
                c.EnableAnnotations();
            });
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc($"v{Program.API_V_2_0}", openApiInfo);
                c.EnableAnnotations();
            });
        }
Ejemplo n.º 2
0
        public static void AddSwagger(this IServiceCollection services)
        {
            services.AddSwaggerGen(setup =>
            {
                var apiInfo = new Microsoft.OpenApi.Models.OpenApiInfo()
                {
                    Title   = "LibraryAPI",
                    Version = "v1"
                };

                setup.SwaggerDoc("LibraryAPI", apiInfo);
            });
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Configure
        /// </summary>
        /// <param name="options">SwaggerGenOptions</param>
        public void Configure(SwaggerGenOptions options)
        {
            foreach (var description in this.provider.ApiVersionDescriptions)
            {
                var info = new Microsoft.OpenApi.Models.OpenApiInfo()
                {
                    Title   = $"{this.AppName} {description.ApiVersion}",
                    Version = description.ApiVersion.ToString(),
                };

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

                options.SwaggerDoc(description.GroupName, info);
            }
        }
Ejemplo n.º 4
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddCors();

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

            string connectionString = Configuration.GetConnectionString("Default");

            services.AddDbContext <EntityContext>(options =>
                                                  options.UseMySQL(connectionString)
                                                  );

            NativeInjector.Registros(services);

            var configuracoesSwagger = new Microsoft.OpenApi.Models.OpenApiInfo {
                Title = "TodoAPI", Version = "v1"
            };

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