andreytreyt / yarp-swagger

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

Using transforms #31

Open q-bertsuit opened 8 months ago

q-bertsuit commented 8 months ago

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?

andreytreyt commented 8 months ago

@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.

fruhnow commented 5 months ago

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!