gpt4 book ai didi

javascript - @ApiImplicitQuery swagger - 无法配置 'enum'

转载 作者:行者123 更新时间:2023-11-29 10:28:47 25 4
gpt4 key购买 nike

你可以在nest swagger documentation中看到如何配置枚举,但它不起作用。

import {SwaggerEnumType} from '../types/swagger-enum.type';

export declare const ApiImplicitQuery: (metadata: {
name: string;
description?: string;
required?: boolean;
type?: 'String' | 'Number' | 'Boolean' | any;
enum?: SwaggerEnumType;
isArray?: boolean;
collectionFormat?: "csv" | "ssv" | "tsv" | "pipes" | "multi";
}) => MethodDecorator;

在上面你可以看到我在 swagger 模块的代码中所做的更改。下面你可以看到我的代码。

 @ApiImplicitQuery({name: "orderBy", enum: ['Admin', 'Moderator', 'User']})
@ApiResponse({status: 200, description: "Successful getting registration list for admin"})
@Get('registrations/list')
public async getAdmin(@Req() req, @Res() res: Response,
@Query('page') page: number,
@Query('perPage') perPage: number,
@Query('orderBy') orderBy: UserRole = UserRole.User,
@Query('orderDir') orderDir: number
) {
try {
let token = await getCompaignIdFromAdminToken(req.headers['authorization']);
let helper: HelperClass = new HelperClass();
await helper.isUserAdmin(token);
let users = await this.adminFacade.getAllUsersList(orderBy, orderDir);
let entity = await this.adminFacade.parseRegistrationUsersList(users);
let pagePar = (page) ? page : 0;
let perPagePar = (perPage) ? perPage : users.length;
let response = await returnResponseByPageAndPerPageValues(entity, pagePar, perPagePar);
res.status(HttpStatus.OK).json({response: response, entries: users.length});
} catch (err) {
errorResponse(res, err.message, HttpStatus.BAD_REQUEST);
}
}

export enum UserRole {
Admin = 'Admin',
Moderator = 'Moderator',
User = 'User'
}

在下方您可以看到生成的 swagger 文档: Sample Image

我做错了什么?

最佳答案

8 月 18 日更新

拉取请求刚刚合并并在版本 v5.2.0 中可用。

原帖

pull request引入对 ApiImplicitQueryenum 支持尚未合并,因此该功能尚不可用。不幸的是,文档更新得太早了:

The doc is already update but not the code.

关注拉取请求以在该功能可用时获得通知。然后你可以更新 @nestjs/swagger 包。

关于javascript - @ApiImplicitQuery swagger - 无法配置 'enum',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51651493/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com