在 Swagger 中拦截消息 UI

Intercept messages in Swagger UI

我正在尝试使用以下代码拦截 Swagger 中的响应消息:

var full = location.protocol + '//' + location.hostname + (location.port ? ':' + location.port : '');

var ui = SwaggerUIBundle({

    url: full + "/swagger/v2/swagger.json",

    responseInterceptor: function (resp) {
        console.log('#response');
        return resp;
    },

    onComplete: function () {
        console.log('#onComplete');

    }
});

问题是响应拦截器仅被调用一次(对于 https://localhost:5001/swagger/v2/swagger.json 文件)并且不会为任何 API 消息调用。

是否可以拦截所有 swagger API 消息?

根据这个 post 应该是可能的:,但由于某些原因这对我不起作用。

这个 Swagger 配置 UI 对我有用 post.

区别在于这一行:

dom_id: '#swagger-ui',

使用此行时,拦截器会拦截每条消息。如果没有这一行,拦截器只会捕获第一条消息。