HttpApiDispatcher Swagger base path issue with Ingress Controller

We have an API exposed and it produces a swagger document similar to below using the following URL:

http://<server>/api

Produces:

{
“swagger”: “2.0”,
“info”: {
“version”: “1.0.0”,
“title”: “CEPAVendorSpecificInterface”
},
“basePath”: “/api”,
“consumes”: [
“application/json”
],

This works fine when running locally, but we’re deploying it to a server using Kubernetes and Ingress, in which case the URL becomes:

https://<server>/cepavsi/api

This returns the exact same swagger document, and our automated test software fails our tests with the error “Swagger Compliance Assertion”.

So ideally the basepath could be change to reflect the new URL. To do this, I tried the following:

server.ApiDispatcher.Path = "/cepavsi/api/";

But then the URL for accessing the server, because of Ingress, duplicates cepavsi and becomes:

https://localhost/cepavsi/cepavsi/api/

Which returns the following:

{
“swagger”: “2.0”,
“info”: {
“version”: “1.0.0”,
“title”: “CEPAVendorSpecificInterface”
},
“basePath”: “/cepavsi/api”,
“consumes”: [
“application/json”
],

Is there a way to change the Swagger document to match the “basePath” exposed by the Ingress controller as “/cepavsi/api” but still serve “/api”?

Tim

Hi,

Can you specify platform (.NET or Delphi) are you using, pls?

Hi Evgeny,

This is .NET.

Tim

Hi,

You can create descendant of HttpApiDispatcher and override metadata request where you can change basePath.

example is attached
testcase.zip (59.1 KB)

Thanks Evgeny.

I’ll give that a try this morning.

Tim

Thanks Evgeny.

I tried it this morning, and can confirm that this technique works for our C# .NET API service. Our ReadyAPI tests now successfully validate the Swagger document.

Tim