I have an Angular 7 app and at a specific route I am loading swagger-ui (3.22.1) with deep-linking enabled. when ever I click on a tag or operation it appends the #/{tagName}/{operationId}
to the base URL of app , Instead of appending it to the route at which swagger-ui was loaded.How can I make swagger-ui append tag/operationId to the route at which it was loaded instead of appending to base URL of angular app.
Let's say Angular app is hosted at localhost:4500
and at localhost:4500/swagger-ui
I am loading swagger-ui with deep-linking enabled.when ever I click on a tag or operation it appends the #/{tagName}/{operationId}
to the localhost:4500
like http://localhost:4500/#/pet
, Instead of appending it to the route at which swagger-ui was loaded i.e localhost:4500/swagger-ui
?
How can I make swagger-ui append tag/operationId to the localhost:4500/swagger-ui
like localhost:4500/swagger-ui/#/pet
instead of http://localhost:4500/#/pet
?
SwaggerUI config
import SwaggerUI from 'swagger-ui';SwaggerUI({url: 'http://petstore.swagger.io/v2/swagger.json',dom_id: '#swagger-ui-container',deepLinking: true,presets: [SwaggerUI.presets.apis]});
Best Answer
I think this is a bug with swagger-ui. See open issue https://github.com/swagger-api/swagger-ui/issues/5811You can fix it temporarily with a monkey patch
const pushState = window.history.pushStatewindow.history.pushState = function (state, title, url) {if (state === null && title === null && url.startsWith('#/')) {url = window.location.pathname + url}pushState.apply(this, [state, title, url])}