コード例 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SwaggerEndPointProvider"/> class.
        /// </summary>
        /// <param name="swaggerEndPoints">The swagger end points.</param>
        public SwaggerEndPointProvider(
            IOptions <List <SwaggerEndPointOptions> > swaggerEndPoints,
            OcelotSwaggerGenOptions options)
        {
            _swaggerEndPointsOptions = Check.NotNull(swaggerEndPoints, nameof(swaggerEndPoints));

            _swaggerEndPoints = new Lazy <Dictionary <string, SwaggerEndPointOptions> >(Init);
            _options          = options;
        }
 private static void AddGatewayItSelfDocs(SwaggerGenOptions c, OcelotSwaggerGenOptions options)
 {
     if (options.GenerateDocsForGatewayItSelf)
     {
         c.SwaggerDoc(OcelotSwaggerGenOptions.GatewayKey, new OpenApiInfo
         {
             Title   = "Gateway",
             Version = OcelotSwaggerGenOptions.GatewayKey,
         });
     }
 }
コード例 #3
0
 private static void AddAggregatesDocs(SwaggerGenOptions c, OcelotSwaggerGenOptions options)
 {
     if (options.GenerateDocsForAggregates)
     {
         c.SwaggerDoc(OcelotSwaggerGenOptions.AggregatesKey, new OpenApiInfo
         {
             Title   = "Aggregates",
             Version = OcelotSwaggerGenOptions.AggregatesKey
         });
         c.DocumentFilter <AggregatesDocumentFilter>();
     }
 }
コード例 #4
0
        private static void AddGatewayItSelfDocs(SwaggerGenOptions c, OcelotSwaggerGenOptions options)
        {
            if (options.GenerateDocsForGatewayItSelf)
            {
                c.SwaggerDoc(OcelotSwaggerGenOptions.GatewayKey, new OpenApiInfo
                {
                    Title   = "Gateway",
                    Version = OcelotSwaggerGenOptions.GatewayKey,
                });

                if (options.OcelotGatewayItSelfSwaggerGenOptions is not null)
                {
                    AddDocumentFilterForGatewayItSelf(options.OcelotGatewayItSelfSwaggerGenOptions.DocumentFilterActions, c);
                    IncludeXmlComments(options.OcelotGatewayItSelfSwaggerGenOptions.FilePathsForXmlComments, c);
                }
            }
        }
コード例 #5
0
        /// <summary>
        /// Adds configuration for for <see cref="SwaggerForOcelotMiddleware"/> into <see cref="IServiceCollection"/>.
        /// </summary>
        /// <param name="services">The services.</param>
        /// <param name="configuration">The configuration.</param>
        /// <param name="ocelotSwaggerSetup">Setup action for configraution thios package.</param>
        /// <param name="swaggerSetup">Setup acton for configuration of swagger generator.</param>
        /// <returns><see cref="IServiceCollection"/></returns>
        public static IServiceCollection AddSwaggerForOcelot(
            this IServiceCollection services,
            IConfiguration configuration,
            Action <OcelotSwaggerGenOptions> ocelotSwaggerSetup = null,
            Action <SwaggerGenOptions> swaggerSetup             = null)
        {
            services
            .AddTransient <IRoutesDocumentationProvider, RoutesDocumentationProvider>()
            .AddTransient <IDownstreamSwaggerDocsRepository, DownstreamSwaggerDocsRepository>()
            .AddTransient <ISwaggerServiceDiscoveryProvider, SwaggerServiceDiscoveryProvider>()
            .AddTransient <ISwaggerJsonTransformer, SwaggerJsonTransformer>()
            .Configure <List <RouteOptions> >(options => configuration.GetSection("Routes").Bind(options))
            .Configure <List <SwaggerEndPointOptions> >(options
                                                        => configuration.GetSection(SwaggerEndPointOptions.ConfigurationSectionName).Bind(options))
            .AddHttpClient()
            .AddMemoryCache()
            .AddSingleton <ISwaggerEndPointProvider, SwaggerEndPointProvider>();

            services.TryAddTransient <IAggregateRouteDocumentationGenerator, AggregateRouteDocumentationGenerator>();

            var options = new OcelotSwaggerGenOptions();

            ocelotSwaggerSetup?.Invoke(options);

            services.AddSingleton(options);
            services.AddSingleton(options.AggregateDocsGeneratorPostProcess);

            if (options.GenerateDocsForAggregates)
            {
                services.Configure <List <SwaggerAggregateRoute> >(options => configuration.GetSection("Aggregates").Bind(options));
            }

            services.AddSwaggerGen(c =>
            {
                swaggerSetup?.Invoke(c);

                AddAggregatesDocs(c, options);
                AddGatewayItSelfDocs(c, options);
            });

            return(services);
        }