-
Notifications
You must be signed in to change notification settings - Fork 82
/
Copy pathdemo.ts
35 lines (34 loc) · 887 Bytes
/
demo.ts
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
import { ItemMeta, z } from "../../lib";
import { middlewares, responses, routeConfig } from "../../lib/decorator";
import { Context } from "koa";
import { AUTH_KEY } from "../schemas/extra";
export class DemoController {
@routeConfig({
path: "/demo",
method: "get",
security: [{ [AUTH_KEY]: [] }],
tags: ["DEMO"],
request: {
query: z.object({
xxx: z.string().nullable().openapi({
example: "110",
}),
}),
},
})
@middlewares([
async (ctx, next) => {
const x = ctx._swagger_decorator_meta as ItemMeta; // get swagger decorator meta info through ctx
console.log("biz mid", x.routeConfig);
await next();
},
])
@responses(
z.object({
msg: z.string().openapi({ example: "gg" }),
})
)
async getDemo(ctx: Context) {
ctx.body = { random: "ggg", ...ctx.request.query };
}
}