diff --git a/api/scripts/generate_openapi_schema.ts b/api/scripts/generate_openapi_schema.ts
index c45a43eb..329aeaf4 100644
--- a/api/scripts/generate_openapi_schema.ts
+++ b/api/scripts/generate_openapi_schema.ts
@@ -19,41 +19,14 @@ const compilerOptions: TJS.CompilerOptions = {
const openapiPath = path.join(__dirname, "..", "assets", "openapi.json");
var specification = JSON.parse(fs.readFileSync(openapiPath, { encoding: "utf8" }));
-async function generateSchemas() {
+async function utilSchemas() {
const program = TJS.getProgramFromFiles([path.join(__dirname, "..", "..", "util", "src", "index.ts")], compilerOptions);
const generator = TJS.buildGenerator(program, settings);
- const schemas = [
- "Application",
- "Attachment",
- "Message",
- "AuditLog",
- "Ban",
- "Channel",
- "Emoji",
- "Guild",
- "Invite",
- "ReadState",
- "Recipient",
- "Relationship",
- "Role",
- "Sticker",
- "Team",
- "TeamMember",
- "Template",
- "VoiceState",
- "Webhook",
- "User",
- "UserPublic"
- ];
+ const schemas = ["UserPublic", "UserPrivate", "PublicConnectedAccount"];
// @ts-ignore
- const definitions = combineSchemas({ schemas, generator, program });
-
- for (const key in definitions) {
- specification.components.schemas[key] = definitions[key];
- delete definitions[key].additionalProperties;
- }
+ combineSchemas({ schemas, generator, program });
}
function combineSchemas(opts: { program: TJS.Program; generator: TJS.JsonSchemaGenerator; schemas: string[] }) {
@@ -63,13 +36,19 @@ function combineSchemas(opts: { program: TJS.Program; generator: TJS.JsonSchemaG
const part = TJS.generateSchema(opts.program, name, settings, [], opts.generator as TJS.JsonSchemaGenerator);
if (!part) continue;
- definitions = { ...definitions, ...part.definitions, [name]: { ...part, definitions: undefined, $schema: undefined } };
+ 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 generateBodies() {
+function apiSchemas() {
const program = TJS.getProgramFromFiles([path.join(__dirname, "..", "src", "schema", "index.ts")], compilerOptions);
const generator = TJS.buildGenerator(program, settings);
@@ -94,97 +73,26 @@ function generateBodies() {
"TemplateModifySchema",
"UserModifySchema",
"UserSettingsSchema",
- "WidgetModifySchema"
+ "WidgetModifySchema",
+ ""
];
// @ts-ignore
- const definitions = combineSchemas({ schemas, generator, program });
-
- for (const key in definitions) {
- specification.components.requestBodies[key] = {
- content: {
- "application/json": { schema: definitions[key] }
- },
- description: ""
- };
-
- delete definitions[key].additionalProperties;
- delete definitions[key].$schema;
- }
+ combineSchemas({ schemas, generator, program });
}
function addDefaultResponses() {
- Object.values(specification.paths).forEach((path: any) =>
- Object.values(path).forEach((request: any) => {
- if (!request.responses?.["401"]) {
- request.responses["401"] = {
- description: "Unauthorized",
- content: { "application/json": { schema: { $ref: "#/components/schemas/Error" } } }
- };
- }
- if (!request.responses?.["429"]) {
- request.responses["429"] = {
- description: "Rate limit exceeded",
- content: { "application/json": { schema: { $ref: "#/components/schemas/Error" } } },
- headers: {
- "X-RateLimit-Bucket": {
- description:
- "A unique string denoting the rate limit being encountered (non-inclusive of major parameters in the route path)",
- schema: { type: "string" }
- },
- "X-Rate-Limit-Limit": {
- description: "The number of allowed requests in the current period",
- schema: {
- type: "integer"
- }
- },
- "X-Rate-Limit-Remaining": {
- description: "The number of remaining requests in the current period",
- schema: {
- type: "integer"
- }
- },
- "X-Rate-Limit-Reset": {
- description: "Date when current period is over in seconds since the Unix epoch",
- schema: {
- type: "integer"
- }
- },
- "X-Rate-Limit-Reset-After": {
- description: "Number of seconds when current period will reset (can have decimal)",
- schema: {
- type: "number"
- }
- },
- "Retry-After": {
- description: "Same as X-Rate-Limit-Reset-After but an integer",
- schema: {
- type: "integer"
- }
- },
- "X-RateLimit-Global": {
- description: "Indicates whether or not all requests from your ip are rate limited",
- schema: {
- type: "boolean"
- }
- }
- }
- };
- }
- })
- );
+ Object.values(specification.paths).forEach((path: any) => Object.values(path).forEach((request: any) => {}));
}
function main() {
addDefaultResponses();
- generateSchemas();
- specification = JSON.parse(JSON.stringify(specification).replaceAll("#/definitions", "#/components/schemas"));
-
- generateBodies();
+ utilSchemas();
+ apiSchemas();
fs.writeFileSync(
openapiPath,
- JSON.stringify(specification, null, 4).replaceAll("#/definitions", "#/components/requestBodies").replaceAll("bigint", "number")
+ JSON.stringify(specification, null, 4).replaceAll("#/definitions", "#/components/schemas").replaceAll("bigint", "number")
);
}
|