42 lines
1.0 KiB
TypeScript
42 lines
1.0 KiB
TypeScript
|
import { createRoute, z } from '@hono/zod-openapi';
|
||
|
|
||
|
import {
|
||
|
createHonoApp,
|
||
|
createServerErrorResponse,
|
||
|
createSuccessResponse,
|
||
|
createValidatorErrorResponse,
|
||
|
} from '../common/utils';
|
||
|
|
||
|
const app = createHonoApp();
|
||
|
export const testApi = app.openapi(
|
||
|
createRoute({
|
||
|
tags: ['test'],
|
||
|
method: 'get',
|
||
|
summary: '文章分页查询',
|
||
|
path: '/id',
|
||
|
request: {
|
||
|
query: z.object({
|
||
|
page: z.string(),
|
||
|
}),
|
||
|
},
|
||
|
responses: {
|
||
|
...createSuccessResponse(
|
||
|
'文章分页查询数据',
|
||
|
z.object({
|
||
|
title: z.string(),
|
||
|
}),
|
||
|
),
|
||
|
...createValidatorErrorResponse(),
|
||
|
...createServerErrorResponse('查询文章分页数据失败'),
|
||
|
},
|
||
|
}),
|
||
|
|
||
|
async (c) => {
|
||
|
const { page } = c.req.query();
|
||
|
|
||
|
console.log('page:', typeof page);
|
||
|
const data = { message: '文章1' };
|
||
|
return c.json(data, 400);
|
||
|
},
|
||
|
);
|