Hi,
I used decorator ApiImplicitBody from ''@nestjs/swagge
@ApiImplicitBody({ name: 'username', description: 'some', required: true, type: 'string' })
@Post('login')
@Bind(Body())
login(body) {}
But when I want to start the project throw compile error:
(node:18200) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError
(node:18200) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
I have no idea why this hanppend. Other decorator works well.
Hi @soulmate2015 try with type: String instead of 'string' and it'll work.
Hi @ericzon
// works well
@ApiImplicitQuery({ name: 'username', description: 'some', required: true, type: 'String' })
@Get('login')
but
// compile error
@ApiImplicitBody({ name: 'username', description: 'some', required: true, type: 'String' })
@Post('login')
I'm try nest/examples/11-swagger has the same problem.
@soulmate2015
Try:
@ApiImplicitBody({ name: 'username', description: 'some', required: true, type: String })
(without the quote characters)
@ericzon: I faced the same issue some moments ago.
Although, the type parameter is optional, but using:
@ApiImplicitBody({ name: 'email', description: 'the users emaile', required: true })
without the "type", i'll receive the same error:
UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError: Cannot destructure property 'prototype' of 'undefined' or 'null'.
Using: @nestjs/swagger@^1.1.2
When I skip the other optional parameters "description" or "required" it works - just providing "name" and "type".
I suggest making "type" required (since it doesn't work without anyway) and document the values one need to pass here properly (String but not 'String' nor 'string').
An unhandled exception should disappear in the incoming release.
Hi @kamilmysliwiec I麓m trying with version 5.0.0-rc.3 and this error still happens. Any news about that?
And in 5.0.0-rc.4 same problem...
If you have something like:
@ApiProduces('application/json')
export abstract class BaseController<D, S extends BaseService<D>> {
abstract protected S getService();
@ApiOperation(LIST_OP)
@ApiResponse(LIST_OK)
@ApiResponse(ERROR_ACCESS)
@ApiImplicitBody({
name: 'filter',
required: false,
type: Any,
// If you use type: RequestModel
})
@Post('list')
async postList(
@Body() filter: RequestModel <D>,
): Promise<ResponseModel <D, D>> {
Logger.log('postList': + filter);
return await this.getService().pagedList(filter);
}
}
@ApiBearerAuth()
@ApiUseTags('people')
@Controller('people')
export class PeopleController extends BaseController<Person, PersonService>{
constructor(private readonly service: PersonService) {
super();
}
getService(): PersonService {
return this.service;
}
}
Hi @kamilmysliwiec you can reopen this issue?
I have the same problem here
(node:80047) UnhandledPromiseRejectionWarning: TypeError:
I figured out it is working with something like this:
class PostData {
@ApiModelProperty()
user: string;
@ApiModelProperty()
password: string;
}
@ApiImplicitBody({ name: 'body', required: true, type: PostData })
Doesn't work. Same error.
I just updated to latest release
Please, create a separate issue with repository that reproduces your problems.
Most helpful comment
Hi @kamilmysliwiec you can reopen this issue?