Closed Pt-11111 closed 2 years ago
@Post('/create1', { summary: 'test' }) @Validate() @ApiQuery({ name: 'test' }) async create1(@Body() userInfo: UserDTO, @Query() userInfo1: UserDTO): Promise<object> { console.log(this.ctx.request.query, userInfo1) return { success: true, message: 'OK', data: { userInfo, test: this.ctx.request.query } }; }
@Post('/create1_1', { summary: 'test' }) @Validate() @ApiQuery({ name: 'test' }) async create1_1(@Param() id: number, @Body() userInfo: UserDTO, @Query() userInfo1: UserDTO): Promise<object> { console.log(this.ctx.request.query, userInfo1) return { success: true, message: 'OK', data: { userInfo, test: this.ctx.request.query } }; }
@Post('/create2', { summary: 'test' }) @Validate() @ApiQuery({ name: 'test' }) async create2(@Query() userInfo1: UserDTO, @Body() userInfo: UserDTO): Promise<object> { console.log(this.ctx.request.query, userInfo1) return { success: true, message: 'OK', data: { userInfo, test: this.ctx.request.query } }; } @Post('/create3', { summary: 'test' }) @Validate() async create3(@Body() userInfo: UserDTO): Promise<object> { return { success: true, message: 'OK', data: { userInfo } }; } @Post('/create4', { summary: 'test' }) @Validate() @ApiQuery({ name: 'test' }) async create4(@Query() userInfo1: UserDTO,): Promise<object> { console.log(this.ctx.request.query, userInfo1) return { success: true, message: 'OK', data: { test: this.ctx.request.query } }; }
import { ApiProperty } from "@midwayjs/swagger"; import { Rule, RuleType } from "@midwayjs/validate"; export class UserDTO { @ApiProperty({ example: 123, description: '用户ID' }) @Rule(RuleType.number().required()) id: number; @ApiProperty({ example: "Bo", description: '姓' }) @Rule(RuleType.string().required()) firstName: string; @ApiProperty({ example: "Pang", description: '名' }) @Rule(RuleType.string().max(10)) lastName: string; @ApiProperty({ example: 20, description: '年龄' }) @Rule(RuleType.number().max(60)) age: number; }
// configuration.ts @Configuration({ imports: [ koa, validate, { component: info, enabledEnvironment: ['local'], }, { component: swagger, enabledEnvironment: ['local'] } ], importConfigs: [join(__dirname, './config')] }) //config.default.ts export default { // use for cookie sign key, should change to your own and keep security keys: '1647590420920_4786', koa: { port: 7001, globalPrefix: '/dev-api/agriculture-iot' }, swagger: { title: 'xxx' } } as MidwayConfig;
装饰器是按照顺序匹配对应的参数的,顺序不对,或者少了,都是不对的。
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
示例
示例一:@Body()在@Query()前面,Body无法正常显示,Query多了参数
示例二:参数顺序为@Param(),@Body(),@Query(),Param无法正常显示,Query自定义名字参数消失,多的参数和示例一一样,Body正常显示
其他 @Query() 在第一个参数位置均能正常识别
UserDTO