diff --git a/.gitignore b/.gitignore index 5b912745..a312a7f9 100644 --- a/.gitignore +++ b/.gitignore @@ -84,3 +84,4 @@ npm-audit.txt .vscode/ config-errors.txt +/config-schema.json diff --git a/backend/package-lock.json b/backend/package-lock.json index 1f2f5992..12d2473a 100644 --- a/backend/package-lock.json +++ b/backend/package-lock.json @@ -75,7 +75,8 @@ "@types/uuid": "^9.0.2", "ava": "^5.3.1", "rimraf": "^2.6.2", - "source-map-support": "^0.5.16" + "source-map-support": "^0.5.16", + "zod-to-json-schema": "^3.22.3" } }, "node_modules/@assemblyscript/loader": { @@ -10192,12 +10193,21 @@ } }, "node_modules/zod": { - "version": "3.21.4", - "resolved": "https://registry.npmjs.org/zod/-/zod-3.21.4.tgz", - "integrity": "sha512-m46AKbrzKVzOzs/DZgVnG5H55N1sv1M8qZU3A8RIKbs3mrACDNeIOeilDymVb2HdmP8uwshOCF4uJ8uM9rCqJw==", + "version": "3.22.4", + "resolved": "https://registry.npmjs.org/zod/-/zod-3.22.4.tgz", + "integrity": "sha512-iC+8Io04lddc+mVqQ9AZ7OQ2MrUKGN+oIQyq1vemgt46jwCwLfhq7/pwnBnNXXXZb8VTVLKwp9EDkx+ryxIWmg==", "funding": { "url": "https://github.com/sponsors/colinhacks" } + }, + "node_modules/zod-to-json-schema": { + "version": "3.22.3", + "resolved": "https://registry.npmjs.org/zod-to-json-schema/-/zod-to-json-schema-3.22.3.tgz", + "integrity": "sha512-9isG8SqRe07p+Aio2ruBZmLm2Q6Sq4EqmXOiNpDxp+7f0LV6Q/LX65fs5Nn+FV/CzfF3NLBoksXbS2jNYIfpKw==", + "dev": true, + "peerDependencies": { + "zod": "^3.22.4" + } } } } diff --git a/backend/package.json b/backend/package.json index 0ac26264..8a0c0e8f 100644 --- a/backend/package.json +++ b/backend/package.json @@ -25,6 +25,7 @@ "migrate-rollback-prod": "cross-env NODE_ENV=production npm run migrate", "migrate-rollback-dev": "cross-env NODE_ENV=development npm run build && npm run migrate", "validate-active-configs": "cross-env NODE_ENV=development node -r ./register-tsconfig-paths.js --unhandled-rejections=strict --enable-source-maps dist/backend/src/validateActiveConfigs.js > ../config-errors.txt", + "export-config-json-schema": "cross-env NODE_ENV=development node -r ./register-tsconfig-paths.js --unhandled-rejections=strict --enable-source-maps dist/backend/src/exportSchemas.js > ../config-schema.json", "test": "npm run build && npm run run-tests", "run-tests": "ava", "test-watch": "tsc-watch --onSuccess \"npx ava\"" @@ -97,7 +98,8 @@ "@types/uuid": "^9.0.2", "ava": "^5.3.1", "rimraf": "^2.6.2", - "source-map-support": "^0.5.16" + "source-map-support": "^0.5.16", + "zod-to-json-schema": "^3.22.3" }, "ava": { "files": [ diff --git a/backend/src/exportSchemas.ts b/backend/src/exportSchemas.ts new file mode 100644 index 00000000..9fa5c3a5 --- /dev/null +++ b/backend/src/exportSchemas.ts @@ -0,0 +1,24 @@ +import { z } from "zod"; +import { guildPlugins } from "./plugins/availablePlugins"; +import zodToJsonSchema from "zod-to-json-schema"; +import { zZeppelinGuildConfig } from "./types"; + +const pluginSchemaMap = guildPlugins.reduce((map, plugin) => { + if (! plugin.info) { + return map; + } + map[plugin.name] = plugin.info.configSchema; + return map; +}, {}); + +const fullSchema = zZeppelinGuildConfig + .omit({ plugins: true }) + .merge(z.strictObject({ + plugins: z.strictObject(pluginSchemaMap).partial(), + })); + +const jsonSchema = zodToJsonSchema(fullSchema); + +console.log(JSON.stringify(jsonSchema, null, 2)); + +process.exit(0);