Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swagger 请求正文未显示在Nest.js+;大摇大摆_Swagger_Swagger Ui_Nestjs_Nestjs Swagger_Nestjs Config - Fatal编程技术网

Swagger 请求正文未显示在Nest.js+;大摇大摆

Swagger 请求正文未显示在Nest.js+;大摇大摆,swagger,swagger-ui,nestjs,nestjs-swagger,nestjs-config,Swagger,Swagger Ui,Nestjs,Nestjs Swagger,Nestjs Config,我的控制器代码是这样的 @Controller('customer') export class CustomerController{ constructor(private readonly customerService: CustomerService){} @Post('lookup') async someMethod(@Body() body:any){ console.log("BEGIN -- CustomerController.

我的控制器代码是这样的

@Controller('customer')
export class CustomerController{

    constructor(private readonly customerService: CustomerService){}

    @Post('lookup')
    async someMethod(@Body() body:any){

        console.log("BEGIN -- CustomerController.someMethod");
我希望在Swagger中看到一个地方,在那里我可以输入一些文本作为请求主体,但我看到的是这个


听起来这里发生了一些事情。Swagger UI是发送请求的辅助工具,但要做到这一点,它需要知道请求主体的形状<代码>任何都不够好。如果你正在寻找一个可以发送任何东西的工具,curl或postman是你最好的选择(至少是免费的)

Nest有一个可以读取您的Typescript代码并相应地修饰您的类型和方法的工具,但您必须选择加入才能启用它。否则,您需要使用
@nestjs/swagger
包中的decorators来告诉swagger在方法中和方法外需要什么类型


只要与
@Body()
相对应的类型具有swagger decorators您启用了swagger插件,并且具有有效的类,则swagger UI应按预期显示,但是使用上面的方法并使用type
any
对您没有任何好处。

我的端点接受未知的键/值数据,我遇到了相同的问题(我尝试了any、unknown、Record、object、{})。最后,
@Body()data:Map
对我有效。

你在使用招摇过市插件吗?在我的package.json中,我有“@nestjs/Swagger”:“^4.4.0”,在你的
nest cli.json
中,你在使用招摇过市插件吗?我不太确定这里的插件是什么意思,但这是我的nest cli中的内容。json{“集合”:“@nestjs schematics/sourceRoot”:“src”}我需要安装Swagger插件吗?如果我的package.json中有这个插件,它是现成的吗?“@nestjs/swagger”:“^4.4.0”在我的回答中指向文档的链接清楚地解释了如何设置插件。我尝试将body type设置为一个接口,但仍然不起作用。最后,在类工作时替换接口。谢谢…接口在运行时不存在,所以没有元数据来反映它们。