Swagger: Use decorator 'ApiImplicitBody' compile error.

Created on 23 Jan 2018  路  11Comments  路  Source: nestjs/swagger

Hi,
I used decorator ApiImplicitBody from ''@nestjs/swagge" in controller like this:

@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.

Most helpful comment

Hi @kamilmysliwiec you can reopen this issue?

All 11 comments

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 instead type: Any then does not works!

  })
  @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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

cdiaz picture cdiaz  路  4Comments

alisherks picture alisherks  路  4Comments

KatSick picture KatSick  路  3Comments

taipoxin picture taipoxin  路  4Comments

patilrevansidh picture patilrevansidh  路  4Comments