Code Monkey home page Code Monkey logo

Comments (4)

Burgyn avatar Burgyn commented on June 10, 2024 1

Hi @sandyrepo

thanks for your report. It's look like problem with transformation by Ocelot config. You use {url} as wild card in your configuration. Unfortunately now this project support only {everything} as wildcard. (see #68)

Please try use {everything}.

from mmlib.swaggerforocelot.

sandyrepo avatar sandyrepo commented on June 10, 2024

{
"ReRoutes": [
{
"DownstreamPathTemplate": "/{url}",
"DownstreamScheme": "http",
"UpstreamPathTemplate": "/abc/{url}",
"UpstreamHttpMethod": [ "Get", "POST", "PUT" ],
"ServiceName": "ani.abc.api",
"LoadBalancerOptions": {
"Type": "LeastConnection"
},
"RateLimitOptions": {
"ClientWhitelist": [],
"EnableRateLimiting": true,
"Period": "1s",
"PeriodTimespan": 1,
"Limit": 1
},
"SwaggerKey": "swaggerabc"
}
],
"SwaggerEndPoints": [
{
"Key": "swaggerabc",
"Config": [
{
"Name": "abc API",
"Version": "v1",
"Url": "http://ani.abc.api:80/swagger/v1/swagger.json"
}
]
}
],
"GlobalConfiguration": {
"ServiceDiscoveryProvider": {
"Host": "consul",
"Port": 8500,
"Type": "Consul"
},
"RequestIdKey": "OcRequestId"
}
}

--------------Gateway startup file--------------
public void ConfigureServices(IServiceCollection services)
{
services.AddOcelot().AddConsul();
services.AddSwaggerForOcelot(Configuration);
services.AddControllers();
}

    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }

       // app.UseHttpsRedirection();

        app.UseRouting();

        //app.UseAuthorization();

        app.UseEndpoints(endpoints =>
        {
            endpoints.MapControllers();
        });
        //app.UseSwaggerForOcelotUI(Configuration).UseOcelot().Wait();
        app.UseSwaggerForOcelotUI(Configuration, opt =>
        {
            opt.ReConfigureUpstreamSwaggerJson = AlterUpstreamSwaggerJson;               
        }).UseOcelot().Wait();

        //app.UseSwaggerForOcelotUI(Configuration, opt =>
        //{
        //    opt.PathToSwaggerGenerator = "/swagger/docs";
        //});
        //app.UseSwaggerForOcelotUI(Configuration, opt =>
        //{
        //    opt.ReConfigureUpstreamSwaggerJson = AlterUpstreamSwaggerJson;
        //    //opt.DownstreamSwaggerEndPointBasePath = "/swagger/docs";
        //    //opt.PathToSwaggerGenerator = "/swagger/docs";
        //}).UseOcelot().Wait();

    }
    public string AlterUpstreamSwaggerJson(HttpContext context, string swaggerJson)
    {
        var swagger = JObject.Parse(swaggerJson);            
        return swagger.ToString(Formatting.Indented);
    }

-------------------------------------Microservice startup file

public void ConfigureServices(IServiceCollection services)
{

        services.AddControllers();
        services.AddSwaggerGen(c =>
        {
            c.SwaggerDoc("v1", new OpenApiInfo { Title = "abc API", Version = "v1" });
        });
    }

    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }
        app.UseRouting();
        app.UseAuthorization();
        app.UseEndpoints(endpoints =>
        {
            endpoints.MapControllers();
        });
        app.UseSwagger();
        app.UseSwaggerUI(c =>
        {
            c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");                
        });
    }

from mmlib.swaggerforocelot.

 avatar commented on June 10, 2024

I tried with setting swaggerkey as service name but got http error "cannot assign address"

from mmlib.swaggerforocelot.

sandyrepo avatar sandyrepo commented on June 10, 2024

Thanks for your quick reply. this resolved my issue

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.