Пример #1
0
        public static IServiceCollection AddNSwagger(this IServiceCollection services, Action <SwaggerOptions>?configureOptions = null)
        {
            if (configureOptions != null)
            {
                services.Configure(configureOptions);
            }

            var paths = Helper.GetCommentsXmlPaths();

            services.Configure <DocXmlOptions>(i => i.Paths.AddRange(paths));

            services.AddSwaggerGen(i =>
            {
#if !NETCOREAPP3_1
#pragma warning disable 618
                i.DescribeAllEnumsAsStrings();
#pragma warning restore 618
#endif
                paths.ForEach(path => { i.IncludeXmlComments(path); });
                i.SchemaFilter <ExampleSchemaFilter>();
            });

#if NETCOREAPP3_1
            services.AddControllers().AddJsonOptions(options =>
                                                     options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter()));
#endif

            services.TryAddTransient <INSwaggerProvider, NSwaggerProvider>();
            services.TryAddSingleton <SwaggerKeyRoles>();
            return(services);
        }
Пример #2
0
        public static IServiceCollection AddNSwagger(this IServiceCollection services, Action <SwaggerOptions>?configureOptions = null)
        {
            if (configureOptions != null)
            {
                services.Configure(configureOptions);
            }

            var paths = Helper.GetCommentsXmlPaths();

            services.Configure <DocXmlOptions>(i => i.Paths.AddRange(paths));

            services.AddSwaggerGen(i =>
            {
                paths.ForEach(path => { i.IncludeXmlComments(path); });
                i.SchemaFilter <ExampleSchemaFilter>();
            });

            services.AddControllers().AddJsonOptions(options =>
                                                     options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter(JsonNamingPolicy.CamelCase)));

            services.TryAddTransient <PathProcessor>();
            services.TryAddTransient <INSwaggerProvider, NSwaggerProvider>();
            services.TryAddSingleton <SwaggerKeyRoles>();
            services.TryAddSingleton <IInjectSwaggerHtml, NullInjectSwaggerHtml>();

            return(services);
        }
Пример #3
0
        public static IServiceCollection AddNetRpcSwagger(this IServiceCollection services)
        {
            var paths = Helper.GetCommentsXmlPaths();

            services.AddSwaggerGen(i =>
            {
#if !NETCOREAPP3_1
                i.DescribeAllEnumsAsStrings();
#endif
                paths.ForEach(path => { i.IncludeXmlComments(path); });
                i.SchemaFilter <ExampleSchemaFilter>();
            });

#if NETCOREAPP3_1
            services.AddControllers().AddJsonOptions(options =>
                                                     options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter()));
#endif
            services.TryAddTransient <INetRpcSwaggerProvider, NetRpcSwaggerProvider>();
            return(services);
        }