Skip to content

Commit

Permalink
Fix URI resolution for inline $refs in schemas
Browse files Browse the repository at this point in the history
Fixes #81
  • Loading branch information
jethron committed May 24, 2024
1 parent 424edc5 commit e290f0b
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/uri.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
/*
/**
* This is just a hack to adapt the jsonschema lib to work without a polyfill for the "url" lib.
*/

// https://nodejs.org/api/url.html#urlresolvefrom-to
/**
* @see {@link https://nodejs.org/api/url.html#urlresolvefrom-to}
* @param {string} from
* @param {string} to
* @returns {string}
*/
export const resolve = (from, to) => {
if (!to) return from;
const resolved = new URL(to, new URL(from, "resolve://"));
if (to.startsWith("#")) return (from || "") + to;
const resolved = new URL(to, new URL(from, "resolve://resolve/"));

if (resolved.protocol === "resolve:") {
const { pathname, search, hash } = resolved;
Expand All @@ -15,4 +21,8 @@ export const resolve = (from, to) => {
return resolved.toString();
};

/**
* @param {string} uri
* @returns {URL}
*/
export const parse = (uri) => new URL(uri);

0 comments on commit e290f0b

Please sign in to comment.