diff --git a/api/assets/schemas.json b/api/assets/schemas.json
index f102f9d0..9286b804 100644
--- a/api/assets/schemas.json
+++ b/api/assets/schemas.json
@@ -98,175 +98,27 @@
],
"$schema": "http://json-schema.org/draft-07/schema#"
},
- "ActivitySchema": {
+ "RouteResponse": {
"type": "object",
"properties": {
- "afk": {
- "type": "boolean"
- },
"status": {
- "$ref": "#/definitions/Status"
+ "type": "integer"
},
- "activities": {
+ "body": {
"type": "array",
"items": {
- "$ref": "#/definitions/Activity"
+ "type": "string"
}
},
- "since": {
- "type": "integer"
+ "headers": {
+ "$ref": "#/definitions/Record<string,string>"
}
},
"additionalProperties": false,
- "required": [
- "afk",
- "status"
- ],
"definitions": {
- "Status": {
- "enum": [
- "dnd",
- "idle",
- "invisible",
- "offline",
- "online"
- ],
- "type": "string"
- },
- "Activity": {
+ "Record<string,string>": {
"type": "object",
- "properties": {
- "name": {
- "type": "string"
- },
- "type": {
- "$ref": "#/definitions/ActivityType"
- },
- "url": {
- "type": "string"
- },
- "created_at": {
- "type": "integer"
- },
- "timestamps": {
- "type": "object",
- "properties": {
- "start": {
- "type": "integer"
- },
- "end": {
- "type": "integer"
- }
- },
- "additionalProperties": false,
- "required": [
- "end",
- "start"
- ]
- },
- "application_id": {
- "type": "string"
- },
- "details": {
- "type": "string"
- },
- "state": {
- "type": "string"
- },
- "emoji": {
- "type": "object",
- "properties": {
- "name": {
- "type": "string"
- },
- "id": {
- "type": "string"
- },
- "animated": {
- "type": "boolean"
- }
- },
- "additionalProperties": false,
- "required": [
- "animated",
- "name"
- ]
- },
- "party": {
- "type": "object",
- "properties": {
- "id": {
- "type": "string"
- },
- "size": {
- "type": "array",
- "items": [
- {
- "type": "integer"
- }
- ],
- "minItems": 1,
- "maxItems": 1
- }
- },
- "additionalProperties": false
- },
- "assets": {
- "type": "object",
- "properties": {
- "large_image": {
- "type": "string"
- },
- "large_text": {
- "type": "string"
- },
- "small_image": {
- "type": "string"
- },
- "small_text": {
- "type": "string"
- }
- },
- "additionalProperties": false
- },
- "secrets": {
- "type": "object",
- "properties": {
- "join": {
- "type": "string"
- },
- "spectate": {
- "type": "string"
- },
- "match": {
- "type": "string"
- }
- },
- "additionalProperties": false
- },
- "instance": {
- "type": "boolean"
- },
- "flags": {
- "type": "string"
- }
- },
- "additionalProperties": false,
- "required": [
- "flags",
- "name",
- "type"
- ]
- },
- "ActivityType": {
- "enum": [
- 0,
- 1,
- 2,
- 4,
- 5
- ],
- "type": "number"
+ "additionalProperties": false
}
},
"$schema": "http://json-schema.org/draft-07/schema#"
@@ -510,6 +362,31 @@
},
"$schema": "http://json-schema.org/draft-07/schema#"
},
+ "ChannelReorderSchema": {
+ "type": "array",
+ "items": {
+ "type": "object",
+ "properties": {
+ "id": {
+ "type": "string"
+ },
+ "position": {
+ "type": "integer"
+ },
+ "lock_permissions": {
+ "type": "boolean"
+ },
+ "parent_id": {
+ "type": "string"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "id"
+ ]
+ },
+ "$schema": "http://json-schema.org/draft-07/schema#"
+ },
"DmChannelCreateSchema": {
"type": "object",
"properties": {
@@ -1678,6 +1555,26 @@
"additionalProperties": false,
"$schema": "http://json-schema.org/draft-07/schema#"
},
+ "RolePositionUpdateSchema": {
+ "type": "array",
+ "items": {
+ "type": "object",
+ "properties": {
+ "id": {
+ "type": "string"
+ },
+ "position": {
+ "type": "integer"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "id",
+ "position"
+ ]
+ },
+ "$schema": "http://json-schema.org/draft-07/schema#"
+ },
"TemplateCreateSchema": {
"type": "object",
"properties": {
@@ -2111,253 +2008,177 @@
],
"$schema": "http://json-schema.org/draft-07/schema#"
},
- "RouteResponse": {
+ "ActivitySchema": {
"type": "object",
"properties": {
+ "afk": {
+ "type": "boolean"
+ },
"status": {
- "type": "integer"
+ "$ref": "#/definitions/Status"
},
- "body": {
+ "activities": {
"type": "array",
"items": {
- "type": "string"
+ "$ref": "#/definitions/Activity"
}
},
- "headers": {
- "$ref": "#/definitions/Record<string,string>"
- }
- },
- "additionalProperties": false,
- "definitions": {
- "Record<string,string>": {
- "type": "object",
- "additionalProperties": false
- }
- },
- "$schema": "http://json-schema.org/draft-07/schema#"
- },
- "GatewayBotResponse": {
- "type": "object",
- "properties": {
- "url": {
- "type": "string"
- },
- "shards": {
+ "since": {
"type": "integer"
- },
- "session_start_limit": {
- "type": "object",
- "properties": {
- "total": {
- "type": "integer"
- },
- "remaining": {
- "type": "integer"
- },
- "reset_after": {
- "type": "integer"
- },
- "max_concurrency": {
- "type": "integer"
- }
- },
- "additionalProperties": false,
- "required": [
- "max_concurrency",
- "remaining",
- "reset_after",
- "total"
- ]
}
},
"additionalProperties": false,
"required": [
- "session_start_limit",
- "shards",
- "url"
+ "afk",
+ "status"
],
- "$schema": "http://json-schema.org/draft-07/schema#"
- },
- "GatewayResponse": {
- "type": "object",
- "properties": {
- "url": {
+ "definitions": {
+ "Status": {
+ "enum": [
+ "dnd",
+ "idle",
+ "invisible",
+ "offline",
+ "online"
+ ],
"type": "string"
- }
- },
- "additionalProperties": false,
- "required": [
- "url"
- ],
- "$schema": "http://json-schema.org/draft-07/schema#"
- },
- "ChannelReorderSchema": {
- "type": "array",
- "items": {
- "type": "object",
- "properties": {
- "id": {
- "type": "string"
- },
- "position": {
- "type": "integer"
- },
- "lock_permissions": {
- "type": "boolean"
- },
- "parent_id": {
- "type": "string"
- }
- },
- "additionalProperties": false,
- "required": [
- "id"
- ]
- },
- "$schema": "http://json-schema.org/draft-07/schema#"
- },
- "RolePositionUpdateSchema": {
- "type": "array",
- "items": {
- "type": "object",
- "properties": {
- "id": {
- "type": "string"
- },
- "position": {
- "type": "integer"
- }
},
- "additionalProperties": false,
- "required": [
- "id",
- "position"
- ]
- },
- "$schema": "http://json-schema.org/draft-07/schema#"
- },
- "UserProfileResponse": {
- "type": "object",
- "properties": {
- "user": {
- "$ref": "#/definitions/UserPublic"
- },
- "connected_accounts": {
- "$ref": "#/definitions/PublicConnectedAccount"
- },
- "premium_guild_since": {
- "type": "string",
- "format": "date-time"
- },
- "premium_since": {
- "type": "string",
- "format": "date-time"
- }
- },
- "additionalProperties": false,
- "required": [
- "connected_accounts",
- "user"
- ],
- "definitions": {
- "UserPublic": {
+ "Activity": {
"type": "object",
"properties": {
- "username": {
+ "name": {
"type": "string"
},
- "discriminator": {
- "type": "string"
+ "type": {
+ "$ref": "#/definitions/ActivityType"
},
- "id": {
+ "url": {
"type": "string"
},
- "public_flags": {
+ "created_at": {
"type": "integer"
},
- "avatar": {
- "type": "string"
+ "timestamps": {
+ "type": "object",
+ "properties": {
+ "start": {
+ "type": "integer"
+ },
+ "end": {
+ "type": "integer"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "end",
+ "start"
+ ]
},
- "accent_color": {
- "type": "integer"
+ "application_id": {
+ "type": "string"
},
- "banner": {
+ "details": {
"type": "string"
},
- "bio": {
+ "state": {
"type": "string"
},
- "bot": {
- "type": "boolean"
+ "emoji": {
+ "type": "object",
+ "properties": {
+ "name": {
+ "type": "string"
+ },
+ "id": {
+ "type": "string"
+ },
+ "animated": {
+ "type": "boolean"
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "animated",
+ "name"
+ ]
},
- "premium_since": {
- "type": "string",
- "format": "date-time"
- }
- },
- "additionalProperties": false,
- "required": [
- "bio",
- "bot",
- "discriminator",
- "id",
- "premium_since",
- "public_flags",
- "username"
- ]
- },
- "PublicConnectedAccount": {
- "type": "object",
- "properties": {
- "name": {
- "type": "string"
+ "party": {
+ "type": "object",
+ "properties": {
+ "id": {
+ "type": "string"
+ },
+ "size": {
+ "type": "array",
+ "items": [
+ {
+ "type": "integer"
+ }
+ ],
+ "minItems": 1,
+ "maxItems": 1
+ }
+ },
+ "additionalProperties": false
},
- "type": {
- "type": "string"
+ "assets": {
+ "type": "object",
+ "properties": {
+ "large_image": {
+ "type": "string"
+ },
+ "large_text": {
+ "type": "string"
+ },
+ "small_image": {
+ "type": "string"
+ },
+ "small_text": {
+ "type": "string"
+ }
+ },
+ "additionalProperties": false
+ },
+ "secrets": {
+ "type": "object",
+ "properties": {
+ "join": {
+ "type": "string"
+ },
+ "spectate": {
+ "type": "string"
+ },
+ "match": {
+ "type": "string"
+ }
+ },
+ "additionalProperties": false
},
- "verified": {
+ "instance": {
"type": "boolean"
+ },
+ "flags": {
+ "type": "string"
}
},
"additionalProperties": false,
"required": [
+ "flags",
"name",
- "type",
- "verified"
+ "type"
]
+ },
+ "ActivityType": {
+ "enum": [
+ 0,
+ 1,
+ 2,
+ 4,
+ 5
+ ],
+ "type": "number"
}
},
"$schema": "http://json-schema.org/draft-07/schema#"
- },
- "UserRelationsResponse": {
- "type": "object",
- "properties": {
- "object": {
- "type": "object",
- "properties": {
- "id": {
- "type": "string"
- },
- "username": {
- "type": "string"
- },
- "avatar": {
- "type": "string"
- },
- "discriminator": {
- "type": "string"
- },
- "public_flags": {
- "type": "integer"
- }
- },
- "additionalProperties": false
- }
- },
- "additionalProperties": false,
- "required": [
- "object"
- ],
- "$schema": "http://json-schema.org/draft-07/schema#"
}
}
\ No newline at end of file
diff --git a/api/scripts/generate_schema.js b/api/scripts/generate_schema.js
index 7a498ad6..1badfd32 100644
--- a/api/scripts/generate_schema.js
+++ b/api/scripts/generate_schema.js
@@ -48,9 +48,8 @@ function modify(obj) {
}
function main() {
- const files = [
- ...walk(path.join(__dirname, "..", "src", "routes")),
- ...walk(path.join(__dirname, "..", "..", "util", "src")),
+ const files = [
+ ...walk(path.join(__dirname, "..", "..", "util", "src", "schemas")),
];
const program = TJS.getProgramFromFiles(
files,
diff --git a/api/src/routes/guilds/#guild_id/channels.ts b/api/src/routes/guilds/#guild_id/channels.ts
index df1b7924..8f2d3643 100644
--- a/api/src/routes/guilds/#guild_id/channels.ts
+++ b/api/src/routes/guilds/#guild_id/channels.ts
@@ -1,5 +1,5 @@
import { Router, Response, Request } from "express";
-import { Channel, ChannelUpdateEvent, getPermission, emitEvent, ChannelModifySchema } from "@fosscord/util";
+import { Channel, ChannelUpdateEvent, getPermission, emitEvent, ChannelModifySchema, ChannelReorderSchema } from "@fosscord/util";
import { HTTPError } from "@fosscord/util";
import { route } from "@fosscord/api";
const router = Router();
@@ -21,8 +21,6 @@ router.post("/", route({ body: "ChannelModifySchema", permission: "MANAGE_CHANNE
res.status(201).json(channel);
});
-export type ChannelReorderSchema = { id: string; position?: number; lock_permissions?: boolean; parent_id?: string }[];
-
router.patch("/", route({ body: "ChannelReorderSchema", permission: "MANAGE_CHANNELS" }), async (req: Request, res: Response) => {
// changes guild channel position
const { guild_id } = req.params;
diff --git a/api/src/routes/guilds/#guild_id/roles/index.ts b/api/src/routes/guilds/#guild_id/roles/index.ts
index effa4fcd..17f0b5e9 100644
--- a/api/src/routes/guilds/#guild_id/roles/index.ts
+++ b/api/src/routes/guilds/#guild_id/roles/index.ts
@@ -10,7 +10,8 @@ import {
Config,
DiscordApiErrors,
handleFile,
- RoleModifySchema
+ RoleModifySchema,
+ RolePositionUpdateSchema
} from "@fosscord/util";
import { HTTPError } from "@fosscord/util";
import { route } from "@fosscord/api";
@@ -18,11 +19,6 @@ import { OrmUtils } from "@fosscord/util";
const router: Router = Router();
-export type RolePositionUpdateSchema = {
- id: string;
- position: number;
-}[];
-
router.get("/", route({}), async (req: Request, res: Response) => {
const guild_id = req.params.guild_id;
|