Skip to content

Instantly share code, notes, and snippets.

@alexanderankin
Created January 24, 2023 16:42
Show Gist options
  • Select an option

  • Save alexanderankin/f9197a6ee7ad66c86bfb6755f6c4ffe8 to your computer and use it in GitHub Desktop.

Select an option

Save alexanderankin/f9197a6ee7ad66c86bfb6755f6c4ffe8 to your computer and use it in GitHub Desktop.
#!/usr/bin/env node
(async () => {
var url = process.argv[2];
var result = await get(url);
var resolved = await resolve(result);
console.log(resolved);
})();
// todo handle
// for i in $(curl -sL 'https://json-schema.org/draft/2020-12/schema' | jq '.allOf[]["$ref"]' -r) ; do curl -sL "https://json-schema.org/draft/2020-12/$i" ; done
async function resolve(schema) {
for (var key in schema) {
if (key === '$ref' && typeof schema[key] === 'string') {
schema[key] = await get(schema[key])
} else if (schema[key] && typeof schema[key] === 'object') {
schema[key] = await resolve(schema[key])
}
}
return schema;
}
async function get(url) {
return await fetch(url)
.then(r => r.json())
.catch(e => url)
;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment