aboutsummaryrefslogtreecommitdiffstats
path: root/packages/open-api
diff options
context:
space:
mode:
Diffstat (limited to 'packages/open-api')
-rw-r--r--packages/open-api/hoarder-openapi-spec.json247
-rw-r--r--packages/open-api/lib/bookmarks.ts118
-rw-r--r--packages/open-api/lib/lists.ts5
3 files changed, 365 insertions, 5 deletions
diff --git a/packages/open-api/hoarder-openapi-spec.json b/packages/open-api/hoarder-openapi-spec.json
index 4cfbfe63..7b2b9436 100644
--- a/packages/open-api/hoarder-openapi-spec.json
+++ b/packages/open-api/hoarder-openapi-spec.json
@@ -25,6 +25,10 @@
}
},
"schemas": {
+ "AssetId": {
+ "type": "string",
+ "example": "ieidlxygmwj87oxz5hxttoc8"
+ },
"BookmarkId": {
"type": "string",
"example": "ieidlxygmwj87oxz5hxttoc8"
@@ -362,6 +366,18 @@
"parentId": {
"type": "string",
"nullable": true
+ },
+ "type": {
+ "type": "string",
+ "enum": [
+ "manual",
+ "smart"
+ ],
+ "default": "manual"
+ },
+ "query": {
+ "type": "string",
+ "nullable": true
}
},
"required": [
@@ -423,6 +439,14 @@
}
},
"parameters": {
+ "AssetId": {
+ "schema": {
+ "$ref": "#/components/schemas/AssetId"
+ },
+ "required": true,
+ "name": "assetId",
+ "in": "path"
+ },
"BookmarkId": {
"schema": {
"$ref": "#/components/schemas/BookmarkId"
@@ -655,6 +679,58 @@
}
}
},
+ "/bookmarks/search": {
+ "get": {
+ "description": "Search bookmarks",
+ "summary": "Search bookmarks",
+ "tags": [
+ "Bookmarks"
+ ],
+ "security": [
+ {
+ "bearerAuth": []
+ }
+ ],
+ "parameters": [
+ {
+ "schema": {
+ "type": "string"
+ },
+ "required": true,
+ "name": "q",
+ "in": "query"
+ },
+ {
+ "schema": {
+ "type": "number"
+ },
+ "required": false,
+ "name": "limit",
+ "in": "query"
+ },
+ {
+ "schema": {
+ "$ref": "#/components/schemas/Cursor"
+ },
+ "required": false,
+ "name": "cursor",
+ "in": "query"
+ }
+ ],
+ "responses": {
+ "200": {
+ "description": "Object with the search results.",
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/PaginatedBookmarks"
+ }
+ }
+ }
+ }
+ }
+ }
+ },
"/bookmarks/{bookmarkId}": {
"get": {
"description": "Get bookmark by its id",
@@ -996,6 +1072,157 @@
}
}
},
+ "/bookmarks/{bookmarkId}/assets": {
+ "post": {
+ "description": "Attach a new asset to a bookmark",
+ "summary": "Attach asset",
+ "tags": [
+ "Bookmarks"
+ ],
+ "security": [
+ {
+ "bearerAuth": []
+ }
+ ],
+ "parameters": [
+ {
+ "$ref": "#/components/parameters/BookmarkId"
+ }
+ ],
+ "requestBody": {
+ "description": "The asset to attach",
+ "content": {
+ "application/json": {
+ "schema": {
+ "type": "object",
+ "properties": {
+ "id": {
+ "type": "string"
+ },
+ "assetType": {
+ "type": "string",
+ "enum": [
+ "screenshot",
+ "bannerImage",
+ "fullPageArchive",
+ "video",
+ "bookmarkAsset",
+ "unknown"
+ ]
+ }
+ },
+ "required": [
+ "id",
+ "assetType"
+ ]
+ }
+ }
+ }
+ },
+ "responses": {
+ "201": {
+ "description": "The attached asset",
+ "content": {
+ "application/json": {
+ "schema": {
+ "type": "object",
+ "properties": {
+ "id": {
+ "type": "string"
+ },
+ "assetType": {
+ "type": "string",
+ "enum": [
+ "screenshot",
+ "bannerImage",
+ "fullPageArchive",
+ "video",
+ "bookmarkAsset",
+ "unknown"
+ ]
+ }
+ },
+ "required": [
+ "id",
+ "assetType"
+ ]
+ }
+ }
+ }
+ }
+ }
+ }
+ },
+ "/bookmarks/{bookmarkId}/assets/{assetId}": {
+ "put": {
+ "description": "Replace an existing asset with a new one",
+ "summary": "Replace asset",
+ "tags": [
+ "Bookmarks"
+ ],
+ "security": [
+ {
+ "bearerAuth": []
+ }
+ ],
+ "parameters": [
+ {
+ "$ref": "#/components/parameters/BookmarkId"
+ },
+ {
+ "$ref": "#/components/parameters/AssetId"
+ }
+ ],
+ "requestBody": {
+ "description": "The new asset to replace with",
+ "content": {
+ "application/json": {
+ "schema": {
+ "type": "object",
+ "properties": {
+ "assetId": {
+ "type": "string"
+ }
+ },
+ "required": [
+ "assetId"
+ ]
+ }
+ }
+ }
+ },
+ "responses": {
+ "204": {
+ "description": "No content - asset was replaced successfully"
+ }
+ }
+ },
+ "delete": {
+ "description": "Detach an asset from a bookmark",
+ "summary": "Detach asset",
+ "tags": [
+ "Bookmarks"
+ ],
+ "security": [
+ {
+ "bearerAuth": []
+ }
+ ],
+ "parameters": [
+ {
+ "$ref": "#/components/parameters/BookmarkId"
+ },
+ {
+ "$ref": "#/components/parameters/AssetId"
+ }
+ ],
+ "responses": {
+ "204": {
+ "description": "No content - asset was detached successfully"
+ }
+ }
+ }
+ },
"/lists": {
"get": {
"description": "Get all lists",
@@ -1058,6 +1285,18 @@
"icon": {
"type": "string"
},
+ "type": {
+ "type": "string",
+ "enum": [
+ "manual",
+ "smart"
+ ],
+ "default": "manual"
+ },
+ "query": {
+ "type": "string",
+ "minLength": 1
+ },
"parentId": {
"type": "string",
"nullable": true
@@ -1136,9 +1375,7 @@
"description": "No content - the bookmark was deleted"
}
}
- }
- },
- "/list/{listId}": {
+ },
"patch": {
"description": "Update list by its id",
"summary": "Update a list",
@@ -1173,6 +1410,10 @@
"parentId": {
"type": "string",
"nullable": true
+ },
+ "query": {
+ "type": "string",
+ "minLength": 1
}
}
}
diff --git a/packages/open-api/lib/bookmarks.ts b/packages/open-api/lib/bookmarks.ts
index 12a122fa..c7c05256 100644
--- a/packages/open-api/lib/bookmarks.ts
+++ b/packages/open-api/lib/bookmarks.ts
@@ -5,6 +5,7 @@ import {
import { z } from "zod";
import {
+ zAssetSchema,
zBareBookmarkSchema,
zManipulatedTagSchema,
zNewBookmarkRequestSchema,
@@ -23,6 +24,17 @@ import { TagIdSchema } from "./tags";
export const registry = new OpenAPIRegistry();
extendZodWithOpenApi(z);
+export const AssetIdSchema = registry.registerParameter(
+ "AssetId",
+ z.string().openapi({
+ param: {
+ name: "assetId",
+ in: "path",
+ },
+ example: "ieidlxygmwj87oxz5hxttoc8",
+ }),
+);
+
export const BookmarkIdSchema = registry.registerParameter(
"BookmarkId",
z.string().openapi({
@@ -62,6 +74,32 @@ registry.registerPath({
});
registry.registerPath({
+ method: "get",
+ path: "/bookmarks/search",
+ description: "Search bookmarks",
+ summary: "Search bookmarks",
+ tags: ["Bookmarks"],
+ security: [{ [BearerAuth.name]: [] }],
+ request: {
+ query: z
+ .object({
+ q: z.string(),
+ })
+ .merge(PaginationSchema),
+ },
+ responses: {
+ 200: {
+ description: "Object with the search results.",
+ content: {
+ "application/json": {
+ schema: PaginatedBookmarksSchema,
+ },
+ },
+ },
+ },
+});
+
+registry.registerPath({
method: "post",
path: "/bookmarks",
description: "Create a new bookmark",
@@ -240,3 +278,83 @@ registry.registerPath({
},
},
});
+
+registry.registerPath({
+ method: "post",
+ path: "/bookmarks/{bookmarkId}/assets",
+ description: "Attach a new asset to a bookmark",
+ summary: "Attach asset",
+ tags: ["Bookmarks"],
+ security: [{ [BearerAuth.name]: [] }],
+ request: {
+ params: z.object({ bookmarkId: BookmarkIdSchema }),
+ body: {
+ description: "The asset to attach",
+ content: {
+ "application/json": {
+ schema: zAssetSchema,
+ },
+ },
+ },
+ },
+ responses: {
+ 201: {
+ description: "The attached asset",
+ content: {
+ "application/json": {
+ schema: zAssetSchema,
+ },
+ },
+ },
+ },
+});
+
+registry.registerPath({
+ method: "put",
+ path: "/bookmarks/{bookmarkId}/assets/{assetId}",
+ description: "Replace an existing asset with a new one",
+ summary: "Replace asset",
+ tags: ["Bookmarks"],
+ security: [{ [BearerAuth.name]: [] }],
+ request: {
+ params: z.object({
+ bookmarkId: BookmarkIdSchema,
+ assetId: AssetIdSchema,
+ }),
+ body: {
+ description: "The new asset to replace with",
+ content: {
+ "application/json": {
+ schema: z.object({
+ assetId: z.string(),
+ }),
+ },
+ },
+ },
+ },
+ responses: {
+ 204: {
+ description: "No content - asset was replaced successfully",
+ },
+ },
+});
+
+registry.registerPath({
+ method: "delete",
+ path: "/bookmarks/{bookmarkId}/assets/{assetId}",
+ description: "Detach an asset from a bookmark",
+ summary: "Detach asset",
+ tags: ["Bookmarks"],
+ security: [{ [BearerAuth.name]: [] }],
+ request: {
+ params: z.object({
+ bookmarkId: BookmarkIdSchema,
+ assetId: AssetIdSchema,
+ }),
+ },
+ responses: {
+ 204: {
+ description: "No content - asset was detached successfully",
+ },
+ },
+});
diff --git a/packages/open-api/lib/lists.ts b/packages/open-api/lib/lists.ts
index aa5d57f3..4b728a1e 100644
--- a/packages/open-api/lib/lists.ts
+++ b/packages/open-api/lib/lists.ts
@@ -6,6 +6,7 @@ import { z } from "zod";
import {
zBookmarkListSchema,
+ zEditBookmarkListSchema,
zNewBookmarkListSchema,
} from "@hoarder/shared/types/lists";
@@ -120,7 +121,7 @@ registry.registerPath({
registry.registerPath({
method: "patch",
- path: "/list/{listId}",
+ path: "/lists/{listId}",
description: "Update list by its id",
summary: "Update a list",
tags: ["Lists"],
@@ -132,7 +133,7 @@ registry.registerPath({
"The data to update. Only the fields you want to update need to be provided.",
content: {
"application/json": {
- schema: zNewBookmarkListSchema.partial(),
+ schema: zEditBookmarkListSchema.omit({ listId: true }),
},
},
},