aboutsummaryrefslogtreecommitdiffstats
path: root/packages/open-api
diff options
context:
space:
mode:
authorMohamed Bassem <me@mbassem.com>2025-03-11 20:09:32 +0000
committerMohamed Bassem <me@mbassem.com>2025-03-11 20:09:32 +0000
commitb8c587e3c3e717263da84522d59c7904715ae22a (patch)
treea26a67162118b4a629d33a833dd25be67d344855 /packages/open-api
parent59c444a503c0124988608c190342acc53c797107 (diff)
downloadkarakeep-b8c587e3c3e717263da84522d59c7904715ae22a.tar.zst
feat: Add endpoints for whoami and user stats. Fixes #1113
Diffstat (limited to 'packages/open-api')
-rw-r--r--packages/open-api/hoarder-openapi-spec.json96
-rw-r--r--packages/open-api/index.ts2
-rw-r--r--packages/open-api/lib/users.ts55
3 files changed, 153 insertions, 0 deletions
diff --git a/packages/open-api/hoarder-openapi-spec.json b/packages/open-api/hoarder-openapi-spec.json
index 7e1911cb..56dad7a7 100644
--- a/packages/open-api/hoarder-openapi-spec.json
+++ b/packages/open-api/hoarder-openapi-spec.json
@@ -2040,6 +2040,102 @@
}
}
}
+ },
+ "/users/me": {
+ "get": {
+ "description": "Returns info about the current user",
+ "summary": "Get current user info",
+ "tags": [
+ "Users"
+ ],
+ "security": [
+ {
+ "bearerAuth": []
+ }
+ ],
+ "responses": {
+ "200": {
+ "description": "Object with user data.",
+ "content": {
+ "application/json": {
+ "schema": {
+ "type": "object",
+ "properties": {
+ "id": {
+ "type": "string"
+ },
+ "name": {
+ "type": "string",
+ "nullable": true
+ },
+ "email": {
+ "type": "string",
+ "nullable": true
+ }
+ },
+ "required": [
+ "id"
+ ]
+ }
+ }
+ }
+ }
+ }
+ }
+ },
+ "/users/me/stats": {
+ "get": {
+ "description": "Returns stats about the current user",
+ "summary": "Get current user stats",
+ "tags": [
+ "Users"
+ ],
+ "security": [
+ {
+ "bearerAuth": []
+ }
+ ],
+ "responses": {
+ "200": {
+ "description": "Object with user stats.",
+ "content": {
+ "application/json": {
+ "schema": {
+ "type": "object",
+ "properties": {
+ "numBookmarks": {
+ "type": "number"
+ },
+ "numFavorites": {
+ "type": "number"
+ },
+ "numArchived": {
+ "type": "number"
+ },
+ "numTags": {
+ "type": "number"
+ },
+ "numLists": {
+ "type": "number"
+ },
+ "numHighlights": {
+ "type": "number"
+ }
+ },
+ "required": [
+ "numBookmarks",
+ "numFavorites",
+ "numArchived",
+ "numTags",
+ "numLists",
+ "numHighlights"
+ ]
+ }
+ }
+ }
+ }
+ }
+ }
}
}
} \ No newline at end of file
diff --git a/packages/open-api/index.ts b/packages/open-api/index.ts
index 75850e5a..d96cb5ca 100644
--- a/packages/open-api/index.ts
+++ b/packages/open-api/index.ts
@@ -9,6 +9,7 @@ import { registry as commonRegistry } from "./lib/common";
import { registry as highlightsRegistry } from "./lib/highlights";
import { registry as listsRegistry } from "./lib/lists";
import { registry as tagsRegistry } from "./lib/tags";
+import { registry as userRegistry } from "./lib/users";
function getOpenApiDocumentation() {
const registry = new OpenAPIRegistry([
@@ -17,6 +18,7 @@ function getOpenApiDocumentation() {
listsRegistry,
tagsRegistry,
highlightsRegistry,
+ userRegistry,
]);
const generator = new OpenApiGeneratorV3(registry.definitions);
diff --git a/packages/open-api/lib/users.ts b/packages/open-api/lib/users.ts
new file mode 100644
index 00000000..657fcdc8
--- /dev/null
+++ b/packages/open-api/lib/users.ts
@@ -0,0 +1,55 @@
+import {
+ extendZodWithOpenApi,
+ OpenAPIRegistry,
+} from "@asteasolutions/zod-to-openapi";
+import { z } from "zod";
+
+import {
+ zUserStatsResponseSchema,
+ zWhoAmIResponseSchema,
+} from "@hoarder/shared/types/users";
+
+import { BearerAuth } from "./common";
+
+export const registry = new OpenAPIRegistry();
+extendZodWithOpenApi(z);
+
+registry.registerPath({
+ method: "get",
+ path: "/users/me",
+ description: "Returns info about the current user",
+ summary: "Get current user info",
+ tags: ["Users"],
+ security: [{ [BearerAuth.name]: [] }],
+ request: {},
+ responses: {
+ 200: {
+ description: "Object with user data.",
+ content: {
+ "application/json": {
+ schema: zWhoAmIResponseSchema,
+ },
+ },
+ },
+ },
+});
+
+registry.registerPath({
+ method: "get",
+ path: "/users/me/stats",
+ description: "Returns stats about the current user",
+ summary: "Get current user stats",
+ tags: ["Users"],
+ security: [{ [BearerAuth.name]: [] }],
+ request: {},
+ responses: {
+ 200: {
+ description: "Object with user stats.",
+ content: {
+ "application/json": {
+ schema: zUserStatsResponseSchema,
+ },
+ },
+ },
+ },
+});