Code Monkey home page Code Monkey logo

Comments (8)

Burgyn avatar Burgyn commented on June 2, 2024 1

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.

from mmlib.swaggerforocelot.

Burgyn avatar Burgyn commented on June 2, 2024

Hi,

thanks for your issue. I never test this scenario.

I'll look into it in the near future.

from mmlib.swaggerforocelot.

Cichyy7 avatar Cichyy7 commented on June 2, 2024

Hi,
Thanks for the quick reply!

Moving SwaggerEndPoints to appsettings.json of gateway indeed helped with SwaggerEndPoints configuration section is missing or empty
but now i'm getting
IndexOutOfRangeException: Index was outside the bounds of the array.
MMLib.SwaggerForOcelot.Middleware.SwaggerForOcelotMiddleware.GetEndPointInfo(string path)

Also, I'm wondering how to move "SwaggerKey": "service1" from ReRoutes of service. From what I saw .AddOcelot() is also removing it from merged ocelot.json.

UPDATE:
IndexOutOfRangeException was caused by accidentally removed /docs suffix from .PathToSwaggerGenerator.
Now swagger page is loaded but with "No operations defined in spec!" info. I guess that's because of missing SwaggerKey in ReRoutes.

from mmlib.swaggerforocelot.

Burgyn avatar Burgyn commented on June 2, 2024

Hi,

yes you are right SwaggerKey is removed. Unfortunately now I don't have any workaround for this. I apologize.

from mmlib.swaggerforocelot.

Cichyy7 avatar Cichyy7 commented on June 2, 2024

Hi,

No problem ;)
Thanks for the help anyway ;)

from mmlib.swaggerforocelot.

Navaladi2019 avatar Navaladi2019 commented on June 2, 2024

Hi,
On such case if we can take ServiceName from route and map it to SwaggerKey.it will work

from mmlib.swaggerforocelot.

habtu12 avatar habtu12 commented on June 2, 2024

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

from mmlib.swaggerforocelot.

Mostafa-Youssef avatar Mostafa-Youssef commented on June 2, 2024

Hi,
sorry for the 3 years delay,
i was making a gateway 2 weeks ago with ocelot and MMLib.SwaggerForOcelot and i have faced the same problem when using ocelot merging the swagger properties and swagger endpoints are missing then i read the ocelot implementation

image

image

and i found that they are using specific properties so i have added more my self
image
image
image
in the last image the FileRoute is the for ocelot i have just inherited from it the same as SwaggerEndPointOptions it is for MMLib.SwaggerForOcelot,
and for the implementation with the help of this awesome guy i got the idea from him to add my own swagger end point the link

so as ocelot said in the documentation they use the ocelot.json as the entry point so we made our own extension and put all the files content in the ocelot.json with our extra properties as you can see in the previous images
and for the extension implementation
image

extension implementation

`
public static class ConfigurationBuilderExtensions
{
public static IConfigurationBuilder AddOcelotConfigFiles(this IConfigurationBuilder builder, string folder, string[] appNames, IWebHostEnvironment env)
{
const string primaryConfigFile = "ocelot.json";

     var files = new DirectoryInfo(folder)
         .EnumerateFiles()
         .Where(fi => fi.Name.Contains($"ocelot.{env.EnvironmentName}.json") && appNames.Any(e => fi.Name.Contains(e)))
         .ToList();

     var fileConfiguration = new MyFileConfiguration();

     foreach (var file in files)
     {
         if (files.Count > 1 && file.Name.Equals(primaryConfigFile, StringComparison.OrdinalIgnoreCase))
         {
             continue;
         }

         var lines = File.ReadAllText(file.FullName);

         var config = JsonConvert.DeserializeObject<MyFileConfiguration>(lines);

         fileConfiguration.Aggregates.AddRange(config.Aggregates);
         fileConfiguration.Routes.AddRange(config.Routes);
         fileConfiguration.SwaggerEndPoints.AddRange(config.SwaggerEndPoints);
     }

     var json = JsonConvert.SerializeObject(fileConfiguration);

     File.WriteAllText(primaryConfigFile, json);

     builder.AddJsonFile(primaryConfigFile, true, true);

     return builder;
 }

}
`

and for the programs.cs
image

and that's it.

from mmlib.swaggerforocelot.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.