Multi tenant and Swagger 2

I have the swagger working on my server using the header value, but I am trying to make it work with a base path instead of a header.

The TTenantSparkleMiddleware.BasePath = http://localhost:2018/api/ and the call being made is http://localhost:2018/api/TENANT/swaggerui

this results in {"error":{"code":"TenantRequired","message":"Tenant not specified"}}

Have I configued my BasePath correctly?

No, just provide the path part of the URL. Thus, set BasePath property to /api

1 Like

Thanks, that works - in as far as the tenant is recognised.

So now I get:

Fetch error
Not Found http://localhost:2018/api/openapi/swagger.json

The issue is that the swaggerui page is not adding the tenant as a call to

http://localhost:2018/api/TENANT/openapi/swagger.json

works

Yes, that's expected behavior, the tenant middleware puts everything under the tenant.

I was probably unclear.

I call swaggerui with http://localhost:2018/api/TENANT/swaggerui. That's fine and the tenant is identified.

However, the swaggerui page calls http://localhost:2018/api/openapi/swagger.json without the tenant id included in the first call, so the swaggerui does not display, it just shows the error:

Fetch error
Not Found http://localhost:2018/api/openapi/swagger.json

which is correct as the middletier tenant would read 'openai' as the tenant id.

So how do you make the swaggerui page make the call with the tenant id in the url?

Understood. Indeed the Swagger document doesn't know exactly how to recreate the original URL when the request URL is modified by the tenant middleware.

I'm not sure how easy is to solve this automatically, but in the meanwhile, you can use the OnGetAbsoluteUrl event to manually provide the correct swagger.json URL.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Solution: