aboutsummaryrefslogtreecommitdiffstats
path: root/packages/open-api/lib/assets.ts
blob: e0d0af99fd43b79c94a964fedbd8251056900448 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import {
  extendZodWithOpenApi,
  OpenAPIRegistry,
} from "@asteasolutions/zod-to-openapi";
import { z } from "zod";

import { BearerAuth } from "./common";

export const registry = new OpenAPIRegistry();
extendZodWithOpenApi(z);

export const AssetIdSchema = registry.registerParameter(
  "AssetId",
  z.string().openapi({
    param: {
      name: "assetId",
      in: "path",
    },
    example: "ieidlxygmwj87oxz5hxttoc8",
  }),
);

registry.registerPath({
  method: "post",
  path: "/assets",
  description: "Upload a new asset",
  summary: "Upload a new asset",
  tags: ["Assets"],
  security: [{ [BearerAuth.name]: [] }],
  request: {
    body: {
      description: "The data to create the asset with.",
      content: {
        "multipart/form-data": {
          schema: z.object({
            file: z.instanceof(File).openapi("File to be uploaded"),
          }),
        },
      },
    },
  },
  responses: {
    200: {
      description: "Details about the created asset",
      content: {
        "application/json": {
          schema: z
            .object({
              assetId: z.string(),
              contentType: z.string(),
              size: z.number(),
              fileName: z.string(),
            })
            .openapi("Asset"),
        },
      },
    },
  },
});

registry.registerPath({
  method: "get",
  path: "/assets/{assetId}",
  description: "Get asset by its id",
  summary: "Get a single asset",
  tags: ["Assets"],
  security: [{ [BearerAuth.name]: [] }],
  request: {
    params: z.object({ assetId: AssetIdSchema }),
  },
  responses: {
    200: {
      description:
        "Asset content. Content type is determined by the asset type.",
    },
  },
});