This is my ocelot configuration...
{
"Routes": [
{
"UpstreamPathTemplate": "/api/test/{url}",
"DownstreamPathTemplate": "/api/{url}",
"DownstreamScheme": "http",
"DownstreamHostAndPorts": [
{
"Host": "test-host",
"Port": 8080
}
],
"SwaggerKey": "test"
}
],
"SwaggerEndPoints": [
{
"Key": "test",
"Config": [
{
"Name": "Test API",
"Version": "v1",
"Url": "http://test-host:8080/swagger/v1/swagger.json",
}
]
}
]
}
Testing results are as follows...
The downstream endpoint:
- running in a container, without an external port forward
- is alive as an internal call to
http://test-host:8080/api/weather-forecastwill return an expected result - is running local swagger at
http://test-host:8080/swaggerand endpoints are shown and function correctly (json listed below)
The upstream endpoint (via Ocelot):
- running on a different container (with access to downstream) and forwarded to
localhost:80 - is routing correctly (as per config) as a call to the external endpoint
http://localhost/api/test/weather-forecastis remapping and will correctly return a result from the internal API - Is providing a central swagger at
http://localhost/swagger/that detects the down stream swagger (shown in the drop down as "Test API", however - Shows no endpoints! I get the "No operations defined in spec!" provided when the
pathsobject in the spec is empty.
Things I have tried:
- I believe it can see the downstream swagger spec ok because if I add
RemoveUnusedComponentsFromScheme: falsethen it will find and render the models, but still no endpoints; further more intentionally breaking the URL returns an error; so I'm confident the downstream swagger spec is loaded correctly - If I add
TransformByOcelotConfig: falseit WILL show the endpoints (further proof the spec if loaded ok), but then the generated url's are wrong; the hostname is correct but the rest of the url uses the internal/downstream path not the re-written external/upstream path - Bumping package versions up/down to see if its a mismatch (currently Microsoft.AspNetCore.OpenApi 9.0.11, MMLib.SwaggerForOcelot 9.0.0, Swashbuckle.AspNetCore 9.0.6
Downstream swagger doc looks like...
{
"openapi": "3.0.4",
"info": {
"title": "Test API",
"version": "1.0"
},
"paths": {
"/api/weather-forecast": {
"get": {
"tags": ["WeatherForecast"],
"operationId": "GetWeatherForecast",
"responses": {
"200": {
"description": "OK",
"content": {
"text/plain": {
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/WeatherForecast"
}
}
},
"application/json": {
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/WeatherForecast"
}
}
},
"text/json": {
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/WeatherForecast"
}
}
}
}
}
}
}
}
},
"components": {
"schemas": {
"WeatherForecast": {
"type": "object",
"properties": {
"date": {
"type": "string",
"format": "date"
},
"temperatureC": {
"type": "integer",
"format": "int32"
},
"temperatureF": {
"type": "integer",
"format": "int32",
"readOnly": true
},
"summary": {
"type": "string",
"nullable": true
}
},
"additionalProperties": false
}
}
}
}
Upstream swagger doc looks like...
{
"openapi": "3.0.4",
"info": {
"title": "Test API",
"version": "1.0"
},
"paths": {},
"components": {
"schemas": {}
}
}
What am I missing here?