summary refs log tree commit diff
path: root/api/scripts/generate_openapi_schema.ts
diff options
context:
space:
mode:
Diffstat (limited to 'api/scripts/generate_openapi_schema.ts')
-rw-r--r--api/scripts/generate_openapi_schema.ts99
1 files changed, 0 insertions, 99 deletions
diff --git a/api/scripts/generate_openapi_schema.ts b/api/scripts/generate_openapi_schema.ts
deleted file mode 100644
index 329aeaf4..00000000
--- a/api/scripts/generate_openapi_schema.ts
+++ /dev/null
@@ -1,99 +0,0 @@
-// https://mermade.github.io/openapi-gui/#
-// https://editor.swagger.io/
-import path from "path";
-import fs from "fs";
-import * as TJS from "typescript-json-schema";
-import "missing-native-js-functions";
-
-const settings: TJS.PartialArgs = {
-	required: true,
-	ignoreErrors: true,
-	excludePrivate: true,
-	defaultNumberType: "integer",
-	noExtraProps: true,
-	defaultProps: false
-};
-const compilerOptions: TJS.CompilerOptions = {
-	strictNullChecks: false
-};
-const openapiPath = path.join(__dirname, "..", "assets", "openapi.json");
-var specification = JSON.parse(fs.readFileSync(openapiPath, { encoding: "utf8" }));
-
-async function utilSchemas() {
-	const program = TJS.getProgramFromFiles([path.join(__dirname, "..", "..", "util", "src", "index.ts")], compilerOptions);
-	const generator = TJS.buildGenerator(program, settings);
-
-	const schemas = ["UserPublic", "UserPrivate", "PublicConnectedAccount"];
-
-	// @ts-ignore
-	combineSchemas({ schemas, generator, program });
-}
-
-function combineSchemas(opts: { program: TJS.Program; generator: TJS.JsonSchemaGenerator; schemas: string[] }) {
-	var definitions: any = {};
-
-	for (const name of opts.schemas) {
-		const part = TJS.generateSchema(opts.program, name, settings, [], opts.generator as TJS.JsonSchemaGenerator);
-		if (!part) continue;
-
-		definitions = { ...definitions, [name]: { ...part, definitions: undefined, $schema: undefined } };
-	}
-
-	for (const key in definitions) {
-		specification.components.schemas[key] = definitions[key];
-		delete definitions[key].additionalProperties;
-		delete definitions[key].$schema;
-	}
-
-	return definitions;
-}
-
-function apiSchemas() {
-	const program = TJS.getProgramFromFiles([path.join(__dirname, "..", "src", "schema", "index.ts")], compilerOptions);
-	const generator = TJS.buildGenerator(program, settings);
-
-	const schemas = [
-		"BanCreateSchema",
-		"DmChannelCreateSchema",
-		"ChannelModifySchema",
-		"ChannelGuildPositionUpdateSchema",
-		"ChannelGuildPositionUpdateSchema",
-		"EmojiCreateSchema",
-		"GuildCreateSchema",
-		"GuildUpdateSchema",
-		"GuildTemplateCreateSchema",
-		"GuildUpdateWelcomeScreenSchema",
-		"InviteCreateSchema",
-		"MemberCreateSchema",
-		"MemberNickChangeSchema",
-		"MemberChangeSchema",
-		"MessageCreateSchema",
-		"RoleModifySchema",
-		"TemplateCreateSchema",
-		"TemplateModifySchema",
-		"UserModifySchema",
-		"UserSettingsSchema",
-		"WidgetModifySchema",
-		""
-	];
-
-	// @ts-ignore
-	combineSchemas({ schemas, generator, program });
-}
-
-function addDefaultResponses() {
-	Object.values(specification.paths).forEach((path: any) => Object.values(path).forEach((request: any) => {}));
-}
-
-function main() {
-	addDefaultResponses();
-	utilSchemas();
-	apiSchemas();
-
-	fs.writeFileSync(
-		openapiPath,
-		JSON.stringify(specification, null, 4).replaceAll("#/definitions", "#/components/schemas").replaceAll("bigint", "number")
-	);
-}
-
-main();