Skip to content

Commit a5101dd

Browse files
jacob-thetalakemrin9
authored andcommitted
Use baseUrl of apiServer to calculate relative refreshUrl, tokenUrl, and authorizationUrl
1 parent 0034eef commit a5101dd

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

src/templates/security-scheme-template.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -263,13 +263,13 @@ function oAuthFlowTemplate(flowName, clientId, clientSecret, securitySchemeId, a
263263
const pkceOnly = authFlow['x-pkce-only'] || false;
264264
const isUrlAbsolute = (url) => (url.indexOf('://') > 0 || url.indexOf('//') === 0);
265265
if (refreshUrl && !isUrlAbsolute(refreshUrl)) {
266-
refreshUrl = `${this.selectedServer.computedUrl}/${refreshUrl.replace(/^\//, '')}`;
266+
refreshUrl = `${this.selectedServer.baseUrl}/${refreshUrl.replace(/^\//, '')}`;
267267
}
268268
if (tokenUrl && !isUrlAbsolute(tokenUrl)) {
269-
tokenUrl = `${this.selectedServer.computedUrl}/${tokenUrl.replace(/^\//, '')}`;
269+
tokenUrl = `${this.selectedServer.baseUrl}/${tokenUrl.replace(/^\//, '')}`;
270270
}
271271
if (authorizationUrl && !isUrlAbsolute(authorizationUrl)) {
272-
authorizationUrl = `${this.selectedServer.computedUrl}/${authorizationUrl.replace(/^\//, '')}`;
272+
authorizationUrl = `${this.selectedServer.baseUrl}/${authorizationUrl.replace(/^\//, '')}`;
273273
}
274274
let flowNameDisplay;
275275
if (flowName === 'authorizationCode') {
@@ -340,11 +340,11 @@ function oAuthFlowTemplate(flowName, clientId, clientSecret, securitySchemeId, a
340340
<input type="text" part="textbox textbox-auth-client-id" value = "${clientId || ''}" placeholder="client-id" spellcheck="false" class="oauth2 ${flowName} ${securitySchemeId} oauth-client-id">
341341
${flowName === 'authorizationCode' || flowName === 'clientCredentials' || flowName === 'password'
342342
? html`
343-
<input
344-
type="password" part="textbox textbox-auth-client-secret"
345-
value = "${clientSecret || ''}" placeholder="client-secret" spellcheck="false"
346-
class="oauth2 ${flowName} ${securitySchemeId}
347-
oauth-client-secret"
343+
<input
344+
type="password" part="textbox textbox-auth-client-secret"
345+
value = "${clientSecret || ''}" placeholder="client-secret" spellcheck="false"
346+
class="oauth2 ${flowName} ${securitySchemeId}
347+
oauth-client-secret"
348348
style = "margin:0 5px;${pkceOnly ? 'display:none;' : ''}"
349349
>
350350
<select style="margin-right:5px;${pkceOnly ? 'display:none;' : ''}" class="${flowName} ${securitySchemeId} oauth-send-client-secret-in">

src/utils/spec-parser.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ export default async function ProcessSpec(specUrl, generateMissingTags = false,
114114
let servers = [];
115115
if (jsonParsedSpec.servers && Array.isArray(jsonParsedSpec.servers)) {
116116
jsonParsedSpec.servers.forEach((v) => {
117+
// Calculcate base URL
118+
const url = new URL(v.url);
119+
v.baseUrl = url.protocol + '://' + url.hostname; // eslint-disable-line
120+
117121
let computedUrl = v.url.trim();
118122
if (!(computedUrl.startsWith('http') || computedUrl.startsWith('//') || computedUrl.startsWith('{'))) {
119123
if (window.location.origin.startsWith('http')) {

0 commit comments

Comments
 (0)