yarp-swagger icon indicating copy to clipboard operation
yarp-swagger copied to clipboard

Using transforms

Open q-bertsuit opened this issue 1 year ago • 2 comments

If I have an app behind my YARP Reverse Proxy that exposes this endpoint

http://localhost:5001/MyController/MyEndpoint

And I want the user to be able to reach this via my reverse proxy like this (using a dash):

http://localhost:5000/api/v1/my-controller/MyEndpoint

I could add a transform to my YARP config like so:

"ReverseProxy": {
    "Routes": [
      {
        "RouteId": "my-service",
        "ClusterId": "my-service",
        "Match": {
          "Path": "/api/v1/my-controller/{**catch-all}"
        },
        "Transforms": [
          {
            "PathPattern": "/mycontroller/{**catch-all}"
          }
        ]
      }
}

A problem arises when I try to define my swaggers. I can add a PrefixPath like "/api/v1/my-controller/", but the swagger documentation will then expose the endpoint as /api/v1/my-controller/mycontroller/myendpoint

Is there a way to handle transforms like this?

q-bertsuit avatar Mar 13 '24 09:03 q-bertsuit

@q-bertsuit Hi! Yes, you're right. I recommend to try to change configuration of path patterns. Maybe configuration of a few routes and clusters helps you.

andreytreyt avatar Mar 20 '24 16:03 andreytreyt

I am running into the same problem. I set up Yarp to proxy requests to my services and used this library to unify my swagger definitions. When visiting the new unified swagger instance it uses the initial Paths of the services it combines behind the Yarp instance instead of the new Yarp Paths which lead to no success. I tried to implement a TransformFactory but couldn't find a way to manipulate the request urls. Are there any hints u can give to resolve this issue?

Kind Regards and thanks for your awesome work!

fruhnow avatar Jun 26 '24 09:06 fruhnow