andreytreyt / yarp-swagger

It's an easy to use Swagger extension for the YARP project.
MIT License
63 stars 14 forks source link

Issue with Multiple Configuration files and its not supported #1

Closed hafeezansar closed 1 year ago

hafeezansar commented 1 year ago

Step 1: Api1.json

{
  "Api1ReverseProxy": {
    "Routes": {
      "api1": {
        "ClusterId": "api1",
        "Match": {
          "Path": "/Api1/{*any}"
        }
      }
    },
    "Clusters": {
      "api1": {
        "Destinations": {
          "destination1": {
            "Address": "https://localhost:7010",
            "Swaggers": [ // <-- this block
              {
                "Paths": [
                  "/swagger/v1/swagger.json"
                ]
              }
            ]
          }
        }
      }
    }
  }
}

Step 2: Api2.json

{
  "Api2ReverseProxy": {
    "Routes": {
      "api2": {
        "ClusterId": "api2",
        "Match": {
          "Path": "Api2/{**catchall}"
        }
      }
    },
    "Clusters": {
      "api2": {
        "Destinations": {
          "destination1": {
            "Address": "https://localhost:7050",
            "Swaggers": [ // <-- this block
              {
                "Paths": [
                  "/swagger/v1/swagger.json"
                ]
              }
            ]
          }
        }
      }
    }
  }
}

Step 3: Added the below code in Program.cs file

var proxyBuilder = builder.Services.AddReverseProxy();

proxyBuilder
    .LoadFromConfig(builder.Configuration.GetSection("Api1ReverseProxy"))
    .LoadFromConfig(builder.Configuration.GetSection("Api2ReverseProxy"));

proxyBuilder
    .AddSwagger(builder.Configuration.GetSection("Api1ReverseProxy"))
    .AddSwagger(builder.Configuration.GetSection("Api2ReverseProxy"));

Swagger is only showing for Api2.json and not showing for Api1.json.

andreytreyt commented 1 year ago

@hafeezansar Hi there! Thanks for your issue. Fixed it in https://github.com/andreytreyt/yarp-swagger/pull/2 New package version is available on https://www.nuget.org/packages/Treyt.Yarp.ReverseProxy.Swagger/1.2.0

hafeezansar commented 1 year ago

Thanks for your update. Its working fine as expected.