public static IServiceCollection AddSwagger(
            this IServiceCollection services,
            APIClient client,
            InnerSaceAPI api,
            string filePath
            )
        {
            var scopes          = api.Scope.Split(',');
            var scopeDictionary = new Dictionary <string, string>();

            foreach (string scope in scopes)
            {
                scopeDictionary.Add(scope, scope);
            }
            services.AddSwaggerGen(o =>
            {
                o.AddSecurityDefinition("oauth2", new OAuth2Scheme
                {
                    Type             = "oauth2",
                    Flow             = api.AuthorizationFLow,
                    AuthorizationUrl = $"{client.IdpUrl}connect/authorize",
                    TokenUrl         = $"{client.IdpUrl}connect/token",
                    Scopes           = scopeDictionary
                });


                o.AddSecurityRequirement(new Dictionary <string, IEnumerable <string> >
                {
                    { "Bearer", new string[] { } },
                    { "oauth2", new  [] { api.Name } },
                });


                o.CustomSchemaIds(x => x.FullName);
                o.SwaggerDoc(api.Version, new Info {
                    Title = api.Title, Version = api.Version
                });
                o.OperationFilter <SwaggerAuthorizationHeaderParameterOperationFilter>();


                o.IncludeXmlComments(filePath);
            });

            return(services);
        }
        /// <summary>
        /// Add Swagger generator for downstream services and UI into application pipeline.
        /// </summary>
        /// <param name="app">The application builder.</param>
        /// <param name="configuration">The configuration.</param>
        /// <param name="setupAction">Setup <see cref="SwaggerForOCelotUIOptions"/></param>
        /// <returns>
        /// <see cref="IApplicationBuilder"/>.
        /// </returns>
        public static IApplicationBuilder UseSwaggerForOcelotUI(
            this IApplicationBuilder app,
            IConfiguration configuration,
            Action <SwaggerForOCelotUIOptions> setupAction, InnerSaceAPI api)
        {
            var options = new SwaggerForOCelotUIOptions();

            setupAction?.Invoke(options);

            UseSwaggerForOcelot(app, options);

            app.UseSwaggerUI(c =>
            {
                InitUIOption(c, options, api);

                var endPoints = GetConfugration(configuration);
                AddSwaggerEndPoints(c, endPoints, options.EndPointBasePath);
            });

            return(app);
        }
        private static void InitUIOption(SwaggerUIOptions c, SwaggerForOCelotUIOptions options, InnerSaceAPI api)
        {
            c.ConfigObject      = options.ConfigObject;
            c.DocumentTitle     = options.DocumentTitle;
            c.HeadContent       = options.HeadContent;
            c.IndexStream       = options.IndexStream;
            c.OAuthConfigObject = options.OAuthConfigObject;
            c.RoutePrefix       = options.RoutePrefix;

            options.InjectJavascript("Swaggerinit.js");
            //c.RoutePrefix = string.Empty;
            //c.SwaggerEndpoint("/swagger/v1/swagger.json", "Messages service getaway API V1");
            c.OAuthClientId(api.ClientId);
            c.OAuthAppName(api.Name);
        }
 /// <summary>
 /// Add Swagger generator for downstream services and UI into application pipeline.
 /// </summary>
 /// <param name="app">The application builder.</param>
 /// <param name="configuration">The configuration.</param>
 /// <returns>
 /// <see cref="IApplicationBuilder"/>.
 /// </returns>
 public static IApplicationBuilder UseSwaggerForOcelotUI(
     this IApplicationBuilder app,
     IConfiguration configuration, InnerSaceAPI api)
 => app.UseSwaggerForOcelotUI(configuration, null, api);