So both API endpoints are mapped to /all/ocelot route, but POST endpoint is also mapped to /post/ocelot.
Former implementation of generating Swagger JSON file worked this way
Walked through all paths in downstream.
For each path (in this case just /api/test) found first suitable Ocelot route, which was /post/ocelot.
Then for processing path walked through all its methods (GET, POST in this case) and checked if matched route can handle these methods.
If method was not hanlded by Ocelot route, it was completely removed. In this example, GET method is not in the first route, so it was removed from downstream.
If all methods was removed from processing path (meaning this path remained empty), the whole path was removed from downstrem.
New implementation in this PR
Key changes in implementation are:
Not just paths, but every method in path is checked against Ocelot routes separately.
All suitable Ocelot routes are used, not just first one.
All original paths in downstream are removed and new ones are built based on matched Ocelot routes.
So the previous example works this way:
All suitable Ocelot routes for GET /api/test are found.
Only second route /all/ocelot matches, because the first one is only for POST.
New downstream path /all/ocelot is created and GET method is added to it.
All suitable Ocelot routes for POST /api/test are found.
Now both Ocelot routes match. First one is explicitly for POST, second one is for all methods.
Downstream path /all/ocelot/ is already created, so POST method is added to it.
New downstream path /post/ocelot is created and POST method is added to it.
When all paths and their methods are processed:
All original paths are removed from downstream.
All new generated downstream paths with methods are added.
Downstream paths are matched against all relevant Ocelot routes and used all routes that fit. Consider following downstream API:
GET /api/test
POST /api/test
Which is represented in OpenApi JSON as:
And this
ocelot.json
:So both API endpoints are mapped to
/all/ocelot
route, butPOST
endpoint is also mapped to/post/ocelot
.Former implementation of generating Swagger JSON file worked this way
/api/test
) found first suitable Ocelot route, which was/post/ocelot
.GET
,POST
in this case) and checked if matched route can handle these methods.GET
method is not in the first route, so it was removed from downstream.New implementation in this PR
Key changes in implementation are:
So the previous example works this way:
GET /api/test
are found./all/ocelot
matches, because the first one is only forPOST
./all/ocelot
is created andGET
method is added to it.POST /api/test
are found.POST
, second one is for all methods./all/ocelot/
is already created, soPOST
method is added to it./post/ocelot
is created andPOST
method is added to it.