SwaggerEndPoints configuration section is missing or empty for merged ocelot jsons

See original GitHub issue

Hi,

When I’m using per service ocelot.json configuration and file merging, I get System.InvalidOperationException: “SwaggerEndPoints configuration section is missing or empty.” Approach is described here: https://ocelot.readthedocs.io/en/latest/features/configuration.html#merging-configuration-files

When I put whole configuration in standalone ocelot.json, everything works fine.

I would like to use both configurations merging and swagger on api gateway.

My configuration below:

Startup.cs

        public void ConfigureServices(IServiceCollection services)
        {
            services.AddOcelot();
            services.AddSwaggerForOcelot(Configuration);
            ...
        }
        public async void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
          ...
            app.UseStaticFiles();

            await app.UseSwaggerForOcelotUI(Configuration, opt =>
            {
                opt.PathToSwaggerGenerator = "/swagger/docs";

            }).UseOcelot();
           ...
        }

Program.cs

        public static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
                .ConfigureWebHostDefaults(webBuilder =>
                {
                    webBuilder.ConfigureAppConfiguration((hostingContext, config) =>
                    {
                        config
                            .AddOcelot("./Ocelot", hostingContext.HostingEnvironment)
                            .AddEnvironmentVariables();
                    });
                    webBuilder.UseStartup<Startup>();
                });

ocelot.service1.json

{
  "ReRoutes": [
    {
      "SwaggerKey": "service1",
      "UpstreamPathTemplate": "/service1/{everything}",
      "UpstreamHttpMethod": [ "GET", "PUT" ],
      "DownstreamPathTemplate": "/service1/{everything}",
      "DownstreamScheme": "http",
      "DownstreamHostAndPorts": [
        {
          "Host": "localhost",
          "Port": 5010
        }
      ]
    }
  ]
}

ocelot.global.json

{
  "SwaggerEndPoints": [
    {
      "Key": "service1",
      "Config": [
        {
          "Name": "Service1 API V1",
          "Version": "v1",
          "Url": "http://localhost:5010/swagger/v1/swagger.json"
        }
      ]
    }
  ],
  "GlobalConfiguration": {
    "BaseUrl": "http://localhost:5014"
  }
}

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Burgyncommented, Jan 22, 2020

Hi,

when you use .AddOcelot("./Ocelot", hostingContext.HostingEnvironment) extension, then Ocelot merge configuration by own way and remove unknown elements.

As workaround you can move SwaggerEndPoints section into your appsettings.json file. I hope, that help you.

0reactions
habtu12commented, Aug 18, 2021

You can config teh Program.cs to read ocelot.json or ocelot.dev.json like this: Screenshot 2021-08-18 141339

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why SwaggerForOcelot not load services swagge ...
I trying some solutions but nothing seem to work. My first solution is to add the SwaggerEndPoints key in the ocelot.authentication.json but ...
Read more >
MMLib.SwaggerForOcelot 7.0.0
SwaggerEndPoint is configuration for downstream service swagger generator endpoint. Property Key is used to pair with the Route configuration. Name is displayed ...
Read more >
Using Swagger with Ocelot API Gateway | by Sanchit
I was recently trying to configure Swagger on the Ocelot API gateway for one of ... Add the “SwaggerEndPoints” section in the ocelot.json....
Read more >
Ocelot Documentation
At the moment there is no validation at this stage it only happens when Ocelot validates the final merged configuration.
Read more >
Swagger for Ocelot API Gateway - Burgyn's blog
Configure SwaggerForOcelot in ocelot.json . ... The SwaggerEndPoints section contains the configurations needed to obtain documentation for ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found