MCPcopy Create free account
hub / github.com/comuline/api / buildResponseSchemas

Function buildResponseSchemas

src/utils/response.ts:37–81  ·  view source on GitHub ↗
(
  responses: Array<DataResponseSchema | MetadataResponseSchema>,
)

Source from the content-addressed store, hash-verified

35}
36
37export const buildResponseSchemas = (
38 responses: Array<DataResponseSchema | MetadataResponseSchema>,
39): RouteConfig["responses"] => {
40 let result: RouteConfig["responses"] = {}
41
42 for (const { status, ...rest } of responses) {
43 if (rest.type === "data") {
44 const { schema } = rest
45 result[status] = {
46 content: {
47 "application/json": {
48 schema: z.object({
49 metadata: z.object({
50 success: z.boolean().default(true),
51 }),
52 data: schema,
53 }),
54 },
55 },
56 description: "Success",
57 } satisfies RouteConfig["responses"][string]
58 } else {
59 const { description } = rest
60
61 const defaultDescription =
62 description ?? getDefaultDescription(status as StatusCode)
63
64 result[status] = {
65 content: {
66 "application/json": {
67 schema: z.object({
68 metadata: z.object({
69 success: z.boolean().default(false),
70 message: z.string().min(1).default(defaultDescription),
71 }),
72 }),
73 },
74 },
75 description: defaultDescription,
76 } satisfies RouteConfig["responses"][string]
77 }
78 }
79
80 return result
81}
82
83const getDefaultDescription = (status: StatusCode) => {
84 switch (status) {

Callers 3

Calls 1

getDefaultDescriptionFunction · 0.85

Tested by

no test coverage detected