Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#252 Fix error on inputs with circular references #448

Merged
merged 2 commits into from
Oct 6, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 21 additions & 10 deletions lib/schemaProxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function loadExamples(file, num = 1) {
}

const handler = ({
root = '', fullpath = null, filename = '.', schemas, parent = null, slugger,
root = '', fullpath = null, filename = '.', schemas, subschemas, parent = null, slugger,
}) => {
const meta = {};

Expand Down Expand Up @@ -162,14 +162,23 @@ const handler = ({
}

// console.log('making new proxy from', target, prop, 'receiver', receiver[symbols.id]);
const subschema = new Proxy(retval, handler({
root: `${root}/${prop}`,
parent: receiver,
fullpath,
filename,
schemas,
slugger,
}));
let subschema;
if (subschemas.has(retval)) {
subschema = subschemas.get(retval);
}
else {
subschema = new Proxy(retval, handler({
root: `${root}/${prop}`,
parent: receiver,
fullpath,
filename,
schemas,
subschemas,
slugger,
}));

subschemas.set(retval, subschema);
}

if (subschema[keyword`$id`]) {
// stow away the schema for lookup
Expand All @@ -190,14 +199,16 @@ export default function loader() {
files: {},
};

const subschemas = new Map();

const slugger = new GhSlugger();

return (/** @type {string} */ name, /** @type {any} */ schema) => {
// console.log('loading', name);
const filename = path.basename(name);
const fullpath = name === filename ? undefined : name;
const proxied = new Proxy(schema, handler({
filename, fullpath, schemas, slugger,
filename, fullpath, schemas, subschemas, slugger,
}));
schemas.loaded.push(proxied);
if (proxied[keyword`$id`]) {
Expand Down