Skip to content
Draft
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"@docusaurus/core": "2.4.0",
"@docusaurus/preset-classic": "2.4.0",
"@mdx-js/react": "^1.6.22",
"@stoplight/json-ref-readers": "^1.2.2",
"@stoplight/json-schema-ref-parser": "^9.2.5",
"clsx": "^1.2.1",
"deepmerge": "^4.3.1",
"docusaurus-json-schema-plugin": "^1.6.0",
Expand Down
52 changes: 7 additions & 45 deletions src/plugins/deref-json-schemas/deref-json-schema.js
Original file line number Diff line number Diff line change
@@ -1,53 +1,15 @@
const { Resolver } = require("@stoplight/json-ref-resolver");
const { resolveHttp } = require("@stoplight/json-ref-readers");
const { merge, mergeWithCustomize } = require("webpack-merge");
const fs = require("fs");
// @ts-check
const $RefParser = require("@stoplight/json-schema-ref-parser");

const schemasPath = "schemas";

function resolveFile(path) {
path = String(path);
if (path.startsWith("/")) {
path = path.slice("/");
} else {
path = `${schemasPath}/${path}`;
}

return JSON.parse(fs.readFileSync(path));
}

const resolver = new Resolver({
resolvers: {
https: { resolve: resolveHttp },
http: { resolve: resolveHttp },
file: { resolve: resolveFile },
},
});

const mergeCustomized = mergeWithCustomize({
customizeArray(resolved, original, key) {
return original;
},
customizeObject(resolved, original, key) {
const { $ref: _originalRef, ...originalClean } = original;
return mergeCustomized(resolved, originalClean);
},
});

async function derefJsonSchema(schema) {
const { result: resolved } = await resolver.resolve(schema);
const { $defs, _resolvedDefs, ...resolvedClean } = resolved;
const { $ref: _ref, $defs: _schemaDefs, ...schemaClean } = schema;
return mergeCustomized(resolvedClean, schemaClean);
}
// use global parser to avoid re-resolving paths that we've already seen in previous schemas
const parser = new $RefParser();

async function derefSchemaPath(schemaPath) {
const schema = JSON.parse(fs.readFileSync(schemaPath));
return await derefJsonSchema(schema);
// TODO bundle instead?
await parser.dereference(schemaPath);
return parser.schema;
}

module.exports = {
schemasPath,
derefJsonSchema,
derefSchemaPath,
};
13 changes: 8 additions & 5 deletions src/plugins/deref-json-schemas/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
const { schemasPath, derefSchemaPath } = require("./deref-json-schema");
// @ts-check
const { derefSchemaPath } = require("./deref-json-schema");
const fs = require("fs");

const resolvedSchemas = {};
const schemasPath = "schemas";

function schemas() {
return fs
Expand All @@ -10,7 +11,8 @@ function schemas() {
.map((file) => `${schemasPath}/${file}`);
}

module.exports = async function derefJsonSchemas(context, options) {
/** @returns {import('@docusaurus/types').Plugin} */
module.exports = function derefJsonSchemas(context, options) {
return {
name: "deref-json-schemas",
async loadContent() {},
Expand All @@ -23,11 +25,12 @@ module.exports = async function derefJsonSchemas(context, options) {
const schema = await derefSchemaPath(schemaPath);
fs.writeFileSync(
`${props.outDir}/${schemaPath}`,
JSON.stringify(schema)
JSON.stringify(schema),
);
console.log(`Wrote ${schemaPath}.`);
}
},
/** @returns {any} devServer is missing from the webpack config definition? */
configureWebpack() {
return {
devServer: {
Expand All @@ -45,7 +48,7 @@ module.exports = async function derefJsonSchemas(context, options) {
} else {
resp.sendStatus(404);
}
}
},
);
},
},
Expand Down
85 changes: 69 additions & 16 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1923,6 +1923,11 @@
"@jridgewell/resolve-uri" "3.1.0"
"@jridgewell/sourcemap-codec" "1.4.14"

"@jsdevtools/ono@^7.1.3":
version "7.1.3"
resolved "https://registry.yarnpkg.com/@jsdevtools/ono/-/ono-7.1.3.tgz#9df03bbd7c696a5c58885c34aa06da41c8543796"
integrity sha512-4JQNk+3mVzK3xh2rqd6RB4J46qUR19azEHBneZyTZM+c456qOrbbM/5xcR8huNCCcbVt7+UmizG6GuUvPvKUYg==

"@leichtgewicht/ip-codec@^2.0.1":
version "2.0.4"
resolved "https://registry.yarnpkg.com/@leichtgewicht/ip-codec/-/ip-codec-2.0.4.tgz#b2ac626d6cb9c8718ab459166d4bb405b8ffa78b"
Expand Down Expand Up @@ -2039,14 +2044,6 @@
p-map "^4.0.0"
webpack-sources "^3.2.2"

"@stoplight/json-ref-readers@^1.2.2":
version "1.2.2"
resolved "https://registry.yarnpkg.com/@stoplight/json-ref-readers/-/json-ref-readers-1.2.2.tgz#e5992bae597f228f988f362a4c0304c03a92008b"
integrity sha512-nty0tHUq2f1IKuFYsLM4CXLZGHdMn+X/IwEUIpeSOXt0QjMUbL0Em57iJUDzz+2MkWG83smIigNZ3fauGjqgdQ==
dependencies:
node-fetch "^2.6.0"
tslib "^1.14.1"

"@stoplight/json-ref-resolver@^3.1.5":
version "3.1.5"
resolved "https://registry.yarnpkg.com/@stoplight/json-ref-resolver/-/json-ref-resolver-3.1.5.tgz#e4454a69027559ef3f7272941e99310a19dc8fdf"
Expand All @@ -2063,6 +2060,19 @@
tslib "^2.3.1"
urijs "^1.19.11"

"@stoplight/json-schema-ref-parser@^9.2.5":
version "9.2.5"
resolved "https://registry.yarnpkg.com/@stoplight/json-schema-ref-parser/-/json-schema-ref-parser-9.2.5.tgz#2039445d06123758d17cf926f3ad6014d8e35d52"
integrity sha512-7UI3pX5oyGzAdGPah001CyPnIsJZJW+38sGjvx862zXQFidBe0sxFO5MUety61Zr/RaygCQ2RU/KfD7hSfOLxg==
dependencies:
"@jsdevtools/ono" "^7.1.3"
"@stoplight/path" "^1.3.2"
"@stoplight/yaml" "^4.0.2"
call-me-maybe "^1.0.1"
fastestsmallesttextencoderdecoder "^1.0.22"
isomorphic-fetch "^3.0.0"
node-abort-controller "^3.0.1"

"@stoplight/json@^3.17.0":
version "3.20.2"
resolved "https://registry.yarnpkg.com/@stoplight/json/-/json-3.20.2.tgz#466ba5c6381cfd141f1726439442fbd579804c8e"
Expand All @@ -2075,7 +2085,7 @@
lodash "^4.17.21"
safe-stable-stringify "^1.1"

"@stoplight/ordered-object-literal@^1.0.3":
"@stoplight/ordered-object-literal@^1.0.1", "@stoplight/ordered-object-literal@^1.0.3":
version "1.0.4"
resolved "https://registry.yarnpkg.com/@stoplight/ordered-object-literal/-/ordered-object-literal-1.0.4.tgz#c8bb2698ab229f31e31a16dd1852c867c1f2f2ed"
integrity sha512-OF8uib1jjDs5/cCU+iOVy+GJjU3X7vk/qJIkIJFqwmlJKrrtijFmqwbu8XToXrwTYLQTP+Hebws5gtZEmk9jag==
Expand All @@ -2085,14 +2095,29 @@
resolved "https://registry.yarnpkg.com/@stoplight/path/-/path-1.3.2.tgz#96e591496b72fde0f0cdae01a61d64f065bd9ede"
integrity sha512-lyIc6JUlUA8Ve5ELywPC8I2Sdnh1zc1zmbYgVarhXIp9YeAB0ReeqmGEOWNtlHkbP2DAA1AL65Wfn2ncjK/jtQ==

"@stoplight/types@^12.3.0 || ^13.0.0", "@stoplight/types@^13.6.0":
"@stoplight/types@^12.3.0 || ^13.0.0", "@stoplight/types@^13.0.0", "@stoplight/types@^13.6.0":
version "13.15.0"
resolved "https://registry.yarnpkg.com/@stoplight/types/-/types-13.15.0.tgz#d2db6820d92e5085193d03c3057d15c40a70e34f"
integrity sha512-pBLjVRrWGVd+KzTbL3qrmufSKIEp0UfziDBdt/nrTHPKrlrtVwaHdrrQMcpM23yJDU1Wcg4cHvhIuGtKCT5OmA==
dependencies:
"@types/json-schema" "^7.0.4"
utility-types "^3.10.0"

"@stoplight/[email protected]":
version "0.0.48"
resolved "https://registry.yarnpkg.com/@stoplight/yaml-ast-parser/-/yaml-ast-parser-0.0.48.tgz#442b21f419427acaa8a3106ebc5d73351c407002"
integrity sha512-sV+51I7WYnLJnKPn2EMWgS4EUfoP4iWEbrWwbXsj0MZCB/xOK8j6+C9fntIdOM50kpx45ZLC3s6kwKivWuqvyg==

"@stoplight/yaml@^4.0.2":
version "4.2.3"
resolved "https://registry.yarnpkg.com/@stoplight/yaml/-/yaml-4.2.3.tgz#d177664fecd6b2fd0d4f264f1078550c30cfd8d1"
integrity sha512-Mx01wjRAR9C7yLMUyYFTfbUf5DimEpHMkRDQ1PKLe9dfNILbgdxyrncsOXM3vCpsQ1Hfj4bPiGl+u4u6e9Akqw==
dependencies:
"@stoplight/ordered-object-literal" "^1.0.1"
"@stoplight/types" "^13.0.0"
"@stoplight/yaml-ast-parser" "0.0.48"
tslib "^2.2.0"

"@svgr/babel-plugin-add-jsx-attribute@^6.5.1":
version "6.5.1"
resolved "https://registry.yarnpkg.com/@svgr/babel-plugin-add-jsx-attribute/-/babel-plugin-add-jsx-attribute-6.5.1.tgz#74a5d648bd0347bda99d82409d87b8ca80b9a1ba"
Expand Down Expand Up @@ -3223,6 +3248,11 @@ call-bind@^1.0.0, call-bind@^1.0.2:
function-bind "^1.1.1"
get-intrinsic "^1.0.2"

call-me-maybe@^1.0.1:
version "1.0.2"
resolved "https://registry.yarnpkg.com/call-me-maybe/-/call-me-maybe-1.0.2.tgz#03f964f19522ba643b1b0693acb9152fe2074baa"
integrity sha512-HpX65o1Hnr9HH25ojC1YGs7HCQLq0GCOibSaWER0eNpgJ/Z1MZv2mTc7+xh6WOPxbRVcmgbv4hGU+uSQ/2xFZQ==

callsites@^3.0.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/callsites/-/callsites-3.1.0.tgz#b3630abd8943432f54b3f0519238e33cd7df2f73"
Expand Down Expand Up @@ -4392,6 +4422,11 @@ [email protected]:
dependencies:
punycode "^1.3.2"

fastestsmallesttextencoderdecoder@^1.0.22:
version "1.0.22"
resolved "https://registry.yarnpkg.com/fastestsmallesttextencoderdecoder/-/fastestsmallesttextencoderdecoder-1.0.22.tgz#59b47e7b965f45258629cc6c127bf783281c5e93"
integrity sha512-Pb8d48e+oIuY4MaM64Cd7OW1gt4nxCHs7/ddPPZ/Ic3sg8yVGM7O9wDvZ7us6ScaUupzM+pfBolwtYhN1IxBIw==

fastq@^1.6.0:
version "1.15.0"
resolved "https://registry.yarnpkg.com/fastq/-/fastq-1.15.0.tgz#d04d07c6a2a68fe4599fea8d2e103a937fae6b3a"
Expand Down Expand Up @@ -5359,6 +5394,14 @@ isobject@^3.0.1:
resolved "https://registry.yarnpkg.com/isobject/-/isobject-3.0.1.tgz#4e431e92b11a9731636aa1f9c8d1ccbcfdab78df"
integrity sha512-WhB9zCku7EGTj/HQQRz5aUQEUeoQZH2bWcltRErOpymJ4boYE6wL9Tbr23krRPSZ+C5zqNSrSw+Cc7sZZ4b7vg==

isomorphic-fetch@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/isomorphic-fetch/-/isomorphic-fetch-3.0.0.tgz#0267b005049046d2421207215d45d6a262b8b8b4"
integrity sha512-qvUtwJ3j6qwsF3jLxkZ72qCgjMysPzDfeV240JHiGZsANBYd+EEuu35v7dfrJ9Up0Ak07D7GGSkGhCHTqg/5wA==
dependencies:
node-fetch "^2.6.1"
whatwg-fetch "^3.4.1"

istanbul-lib-coverage@^3.0.0, istanbul-lib-coverage@^3.2.0:
version "3.2.0"
resolved "https://registry.yarnpkg.com/istanbul-lib-coverage/-/istanbul-lib-coverage-3.2.0.tgz#189e7909d0a39fa5a3dfad5b03f71947770191d3"
Expand Down Expand Up @@ -6262,6 +6305,11 @@ no-case@^3.0.4:
lower-case "^2.0.2"
tslib "^2.0.3"

node-abort-controller@^3.0.1:
version "3.1.1"
resolved "https://registry.yarnpkg.com/node-abort-controller/-/node-abort-controller-3.1.1.tgz#a94377e964a9a37ac3976d848cb5c765833b8548"
integrity sha512-AGK2yQKIjRuqnc6VkX2Xj5d+QW8xZ87pa1UK6yA6ouUyuxfHuMP6umE5QK7UmTeOAymo+Zx1Fxiuw9rVx8taHQ==

node-emoji@^1.10.0:
version "1.11.0"
resolved "https://registry.yarnpkg.com/node-emoji/-/node-emoji-1.11.0.tgz#69a0150e6946e2f115e9d7ea4df7971e2628301c"
Expand All @@ -6276,7 +6324,7 @@ [email protected]:
dependencies:
whatwg-url "^5.0.0"

node-fetch@^2.6.0:
node-fetch@^2.6.1:
version "2.6.11"
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.11.tgz#cde7fc71deef3131ef80a738919f999e6edfff25"
integrity sha512-4I6pdBY1EthSqDmJkiNk3JIT8cswwR9nfeW/cPdUagJYEQG7R95WRH74wpz7ma8Gh/9dI9FP+OU+0E4FvtA55w==
Expand Down Expand Up @@ -8234,16 +8282,16 @@ ts-node@^10.9.1:
v8-compile-cache-lib "^3.0.1"
yn "3.1.1"

tslib@^1.14.1:
version "1.14.1"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00"
integrity sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==

tslib@^2.0.3, tslib@^2.1.0, tslib@^2.3.1, tslib@^2.4.0:
version "2.5.0"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.5.0.tgz#42bfed86f5787aeb41d031866c8f402429e0fddf"
integrity sha512-336iVw3rtn2BUK7ORdIAHTyxHGRIHVReokCR3XjbckJMK7ms8FysBfhLR8IXnAgy7T0PTPNBWKiH514FOW/WSg==

tslib@^2.2.0:
version "2.5.3"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.5.3.tgz#24944ba2d990940e6e982c4bea147aba80209913"
integrity sha512-mSxlJJwl3BMEQCUNnxXBU9jP4JBktcEGhURcPR6VQVlnP0FdDEsIaz0C35dXNGLyRfrATNofF0F5p2KPxQgB+w==

[email protected]:
version "4.0.8"
resolved "https://registry.yarnpkg.com/type-detect/-/type-detect-4.0.8.tgz#7646fb5f18871cfbb7749e69bd39a6388eb7450c"
Expand Down Expand Up @@ -8742,6 +8790,11 @@ websocket-extensions@>=0.1.1:
resolved "https://registry.yarnpkg.com/websocket-extensions/-/websocket-extensions-0.1.4.tgz#7f8473bc839dfd87608adb95d7eb075211578a42"
integrity sha512-OqedPIGOfsDlo31UNwYbCFMSaO9m9G/0faIHj5/dZFDMFqPTcx6UwqyOy3COEaEOg/9VsGIpdqn62W5KhoKSpg==

whatwg-fetch@^3.4.1:
version "3.6.2"
resolved "https://registry.yarnpkg.com/whatwg-fetch/-/whatwg-fetch-3.6.2.tgz#dced24f37f2624ed0281725d51d0e2e3fe677f8c"
integrity sha512-bJlen0FcuU/0EMLrdbJ7zOnW6ITZLrZMIarMUVmdKtsGvZna8vxKYaexICWPfZ8qwf9fzNq+UEIZrnSaApt6RA==

whatwg-url@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/whatwg-url/-/whatwg-url-5.0.0.tgz#966454e8765462e37644d3626f6742ce8b70965d"
Expand Down