I am integrating the swagger UI in my project. I need to pass the token to make a request.
const mytoken = "heareismytoken";
const ui = SwaggerUIBundle({
url: "/swagger/v2/swagger.json",
dom_id: '#swagger-ui',
deepLinking: true,
requestInterceptor: function (req) {
var key = mytoken;
if (key && key.trim() !== "") {
req.headers.Authorization = 'Bearer ' + key;
console.log('Authorized from authKey');
}
},
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIStandalonePreset
],
plugins: [
SwaggerUIBundle.plugins.DownloadUrl
],
layout: "StandaloneLayout",
});
With the above code I am getting the successful response but the problem is curl command is showing as undefined like below image
If I removed the following part of code
/*
requestInterceptor: function (req) {
var key = mytoken;
if (key && key.trim() !== "") {
req.headers.Authorization = 'Bearer ' + key;
console.log('Authorized from authKey');
}
}, */
the curl command is showing but the response is throwing the authentication error.
I don't know exactly where I am missing it. How to the show both CURL command and the Response.?