Skip to content

Commit a98f023

Browse files
committed
docs: Add asset APIs to the openapi spec
1 parent 4e481f4 commit a98f023

File tree

4 files changed

+182
-24
lines changed

4 files changed

+182
-24
lines changed

packages/open-api/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
OpenAPIRegistry,
55
} from "@asteasolutions/zod-to-openapi";
66

7+
import { registry as assetsRegistry } from "./lib/assets";
78
import { registry as bookmarksRegistry } from "./lib/bookmarks";
89
import { registry as commonRegistry } from "./lib/common";
910
import { registry as highlightsRegistry } from "./lib/highlights";
@@ -19,6 +20,7 @@ function getOpenApiDocumentation() {
1920
tagsRegistry,
2021
highlightsRegistry,
2122
userRegistry,
23+
assetsRegistry,
2224
]);
2325

2426
const generator = new OpenApiGeneratorV3(registry.definitions);

packages/open-api/karakeep-openapi-spec.json

Lines changed: 102 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,6 @@
2525
}
2626
},
2727
"schemas": {
28-
"AssetId": {
29-
"type": "string",
30-
"example": "ieidlxygmwj87oxz5hxttoc8"
31-
},
3228
"BookmarkId": {
3329
"type": "string",
3430
"example": "ieidlxygmwj87oxz5hxttoc8"
@@ -45,6 +41,10 @@
4541
"type": "string",
4642
"example": "ieidlxygmwj87oxz5hxttoc8"
4743
},
44+
"AssetId": {
45+
"type": "string",
46+
"example": "ieidlxygmwj87oxz5hxttoc8"
47+
},
4848
"Bookmark": {
4949
"type": "object",
5050
"properties": {
@@ -488,17 +488,33 @@
488488
"highlights",
489489
"nextCursor"
490490
]
491-
}
492-
},
493-
"parameters": {
494-
"AssetId": {
495-
"schema": {
496-
"$ref": "#/components/schemas/AssetId"
491+
},
492+
"Asset": {
493+
"type": "object",
494+
"properties": {
495+
"assetId": {
496+
"type": "string"
497+
},
498+
"contentType": {
499+
"type": "string"
500+
},
501+
"size": {
502+
"type": "number"
503+
},
504+
"fileName": {
505+
"type": "string"
506+
}
497507
},
498-
"required": true,
499-
"name": "assetId",
500-
"in": "path"
508+
"required": [
509+
"assetId",
510+
"contentType",
511+
"size",
512+
"fileName"
513+
]
501514
},
515+
"File to be uploaded": {}
516+
},
517+
"parameters": {
502518
"BookmarkId": {
503519
"schema": {
504520
"$ref": "#/components/schemas/BookmarkId"
@@ -530,6 +546,14 @@
530546
"required": true,
531547
"name": "highlightId",
532548
"in": "path"
549+
},
550+
"AssetId": {
551+
"schema": {
552+
"$ref": "#/components/schemas/AssetId"
553+
},
554+
"required": true,
555+
"name": "assetId",
556+
"in": "path"
533557
}
534558
}
535559
},
@@ -3031,6 +3055,71 @@
30313055
}
30323056
}
30333057
}
3058+
},
3059+
"/assets": {
3060+
"post": {
3061+
"description": "Upload a new asset",
3062+
"summary": "Upload a new asset",
3063+
"tags": [
3064+
"Assets"
3065+
],
3066+
"security": [
3067+
{
3068+
"bearerAuth": []
3069+
}
3070+
],
3071+
"requestBody": {
3072+
"description": "The data to create the asset with.",
3073+
"content": {
3074+
"multipart/form-data": {
3075+
"schema": {
3076+
"type": "object",
3077+
"properties": {
3078+
"file": {
3079+
"$ref": "#/components/schemas/File to be uploaded"
3080+
}
3081+
}
3082+
}
3083+
}
3084+
}
3085+
},
3086+
"responses": {
3087+
"200": {
3088+
"description": "Details about the created asset",
3089+
"content": {
3090+
"application/json": {
3091+
"schema": {
3092+
"$ref": "#/components/schemas/Asset"
3093+
}
3094+
}
3095+
}
3096+
}
3097+
}
3098+
}
3099+
},
3100+
"/assets/{assetId}": {
3101+
"get": {
3102+
"description": "Get asset by its id",
3103+
"summary": "Get a single asset",
3104+
"tags": [
3105+
"Assets"
3106+
],
3107+
"security": [
3108+
{
3109+
"bearerAuth": []
3110+
}
3111+
],
3112+
"parameters": [
3113+
{
3114+
"$ref": "#/components/parameters/AssetId"
3115+
}
3116+
],
3117+
"responses": {
3118+
"200": {
3119+
"description": "Asset content. Content type is determined by the asset type."
3120+
}
3121+
}
3122+
}
30343123
}
30353124
}
30363125
}

packages/open-api/lib/assets.ts

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import {
2+
extendZodWithOpenApi,
3+
OpenAPIRegistry,
4+
} from "@asteasolutions/zod-to-openapi";
5+
import { z } from "zod";
6+
7+
import { BearerAuth } from "./common";
8+
9+
export const registry = new OpenAPIRegistry();
10+
extendZodWithOpenApi(z);
11+
12+
export const AssetIdSchema = registry.registerParameter(
13+
"AssetId",
14+
z.string().openapi({
15+
param: {
16+
name: "assetId",
17+
in: "path",
18+
},
19+
example: "ieidlxygmwj87oxz5hxttoc8",
20+
}),
21+
);
22+
23+
registry.registerPath({
24+
method: "post",
25+
path: "/assets",
26+
description: "Upload a new asset",
27+
summary: "Upload a new asset",
28+
tags: ["Assets"],
29+
security: [{ [BearerAuth.name]: [] }],
30+
request: {
31+
body: {
32+
description: "The data to create the asset with.",
33+
content: {
34+
"multipart/form-data": {
35+
schema: z.object({
36+
file: z.instanceof(File).openapi("File to be uploaded"),
37+
}),
38+
},
39+
},
40+
},
41+
},
42+
responses: {
43+
200: {
44+
description: "Details about the created asset",
45+
content: {
46+
"application/json": {
47+
schema: z
48+
.object({
49+
assetId: z.string(),
50+
contentType: z.string(),
51+
size: z.number(),
52+
fileName: z.string(),
53+
})
54+
.openapi("Asset"),
55+
},
56+
},
57+
},
58+
},
59+
});
60+
61+
registry.registerPath({
62+
method: "get",
63+
path: "/assets/{assetId}",
64+
description: "Get asset by its id",
65+
summary: "Get a single asset",
66+
tags: ["Assets"],
67+
security: [{ [BearerAuth.name]: [] }],
68+
request: {
69+
params: z.object({ assetId: AssetIdSchema }),
70+
},
71+
responses: {
72+
200: {
73+
description:
74+
"Asset content. Content type is determined by the asset type.",
75+
},
76+
},
77+
});

packages/open-api/lib/bookmarks.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
zUpdateBookmarksRequestSchema,
1414
} from "@karakeep/shared/types/bookmarks";
1515

16+
import { AssetIdSchema } from "./assets";
1617
import { BearerAuth } from "./common";
1718
import { ErrorSchema } from "./errors";
1819
import { HighlightSchema } from "./highlights";
@@ -27,17 +28,6 @@ import { TagIdSchema } from "./tags";
2728
export const registry = new OpenAPIRegistry();
2829
extendZodWithOpenApi(z);
2930

30-
export const AssetIdSchema = registry.registerParameter(
31-
"AssetId",
32-
z.string().openapi({
33-
param: {
34-
name: "assetId",
35-
in: "path",
36-
},
37-
example: "ieidlxygmwj87oxz5hxttoc8",
38-
}),
39-
);
40-
4131
export const BookmarkIdSchema = registry.registerParameter(
4232
"BookmarkId",
4333
z.string().openapi({

0 commit comments

Comments
 (0)