Skip to content

Commit

Permalink
fix(resolver): allow to provide relative URI Reference in browser env (
Browse files Browse the repository at this point in the history
…#3177)

Refs #3170
Refs #3150 
Refs #3148
  • Loading branch information
char0n authored Oct 11, 2023
1 parent 708be44 commit a477240
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/resolver/utils/options.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
import Http from '../../http/index.js';

export const retrievalURI = (options) => {
/**
* Swagger-UI uses baseDoc instead of url, this helper function exists
* to allow both.
*
* In browser environment, we allow to pass a relative URI Reference,
* and we resolve it against the document's baseURI before passing it deeper
* to swagger-client code.
*/
const { baseDoc, url } = options;
const retrievalURL = baseDoc ?? url ?? '';

// @TODO Swagger-UI uses baseDoc instead of url, this is to allow both
// need to fix and pick one.
return baseDoc || url || '';
return typeof globalThis.document?.baseURI === 'string'
? String(new URL(retrievalURL, globalThis.document.baseURI))
: retrievalURL;
};

export const httpClient = (options) => {
Expand Down

0 comments on commit a477240

Please sign in to comment.