Skip to content

Commit db2be89

Browse files
jacob-thetalakemrin9
authored andcommitted
Localize the change to the security template and still use computedUrl
1 parent a5101dd commit db2be89

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

src/templates/security-scheme-template.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,14 +262,18 @@ function oAuthFlowTemplate(flowName, clientId, clientSecret, securitySchemeId, a
262262
let { authorizationUrl, tokenUrl, refreshUrl } = authFlow;
263263
const pkceOnly = authFlow['x-pkce-only'] || false;
264264
const isUrlAbsolute = (url) => (url.indexOf('://') > 0 || url.indexOf('//') === 0);
265+
// Calculcate base URL
266+
const url = new URL(this.selectedServer.computedUrl);
267+
const baseUrl = `${url.protocol}://${url.hostname}`;
268+
265269
if (refreshUrl && !isUrlAbsolute(refreshUrl)) {
266-
refreshUrl = `${this.selectedServer.baseUrl}/${refreshUrl.replace(/^\//, '')}`;
270+
refreshUrl = `${baseUrl}/${refreshUrl.replace(/^\//, '')}`;
267271
}
268272
if (tokenUrl && !isUrlAbsolute(tokenUrl)) {
269-
tokenUrl = `${this.selectedServer.baseUrl}/${tokenUrl.replace(/^\//, '')}`;
273+
tokenUrl = `${baseUrl}/${tokenUrl.replace(/^\//, '')}`;
270274
}
271275
if (authorizationUrl && !isUrlAbsolute(authorizationUrl)) {
272-
authorizationUrl = `${this.selectedServer.baseUrl}/${authorizationUrl.replace(/^\//, '')}`;
276+
authorizationUrl = `${baseUrl}/${authorizationUrl.replace(/^\//, '')}`;
273277
}
274278
let flowNameDisplay;
275279
if (flowName === 'authorizationCode') {

src/utils/spec-parser.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,6 @@ 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-
121117
let computedUrl = v.url.trim();
122118
if (!(computedUrl.startsWith('http') || computedUrl.startsWith('//') || computedUrl.startsWith('{'))) {
123119
if (window.location.origin.startsWith('http')) {

0 commit comments

Comments
 (0)