Created
January 24, 2023 16:42
-
-
Save alexanderankin/f9197a6ee7ad66c86bfb6755f6c4ffe8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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