Я пытаюсь добавить swagger в мое приложение nestjs, и это ошибка, которую я получаю.
(node:78477) UnhandledPromiseRejectionWarning: TypeError: Cannot read property '0' of undefined
at lodash_1.mapValues.param (/Users/anna/SoFetch/node_modules/@nestjs/swagger/dist/explorers/api-parameters.explorer.js:34:20)
at /Users/anna/SoFetch/node_modules/@nestjs/swagger/node_modules/lodash/lodash.js:13401:38
at /Users/anna/SoFetch/node_modules/@nestjs/swagger/node_modules/lodash/lodash.js:4905:15
at baseForOwn (/Users/anna/SoFetch/node_modules/@nestjs/swagger/node_modules/lodash/lodash.js:2990:24)
at Function.mapValues (/Users/anna/SoFetch/node_modules/@nestjs/swagger/node_modules/lodash/lodash.js:13400:7)
at exploreApiReflectedParametersMetadata (/Users/anna/SoFetch/node_modules/@nestjs/swagger/dist/explorers/api-parameters.explorer.js:33:41)
at exports.exploreApiParametersMetadata (/Users/anna/SoFetch/node_modules/@nestjs/swagger/dist/explorers/api-parameters.explorer.js:11:33)
at explorers.reduce (/Users/anna/SoFetch/node_modules/@nestjs/swagger/dist/swagger-explorer.js:55:45)
at Array.reduce (<anonymous>)
at lodash_1.mapValues (/Users/anna/SoFetch/node_modules/@nestjs/swagger/dist/swagger-explorer.js:54:97)
at /Users/anna/SoFetch/node_modules/@nestjs/swagger/node_modules/lodash/lodash.js:13401:38
at /Users/anna/SoFetch/node_modules/@nestjs/swagger/node_modules/lodash/lodash.js:4905:15
at baseForOwn (/Users/anna/SoFetch/node_modules/@nestjs/swagger/node_modules/lodash/lodash.js:2990:24)
at Function.mapValues (/Users/anna/SoFetch/node_modules/@nestjs/swagger/node_modules/lodash/lodash.js:13400:7)
at MapIterator.denormalizedPaths.metadataScanner.scanFromPrototype.name [as iteratee] (/Users/anna/SoFetch/node_modules/@nestjs/swagger/dist/swagger-explorer.js:54:45)
at MapIterator.next (/Users/anna/SoFetch/node_modules/iterare/lib/map.js:13:39)
at FilterIterator.next (/Users/anna/SoFetch/node_modules/iterare/lib/filter.js:12:34)
at IteratorWithOperators.next (/Users/anna/SoFetch/node_modules/iterare/lib/iterate.js:21:28)
at Function.from (<anonymous>)
at IteratorWithOperators.toArray (/Users/anna/SoFetch/node_modules/iterare/lib/iterate.js:180:22)
at MetadataScanner.scanFromPrototype (/Users/anna/SoFetch/node_modules/@nestjs/core/metadata-scanner.js:11:14)
at SwaggerExplorer.generateDenormalizedDocument (/Users/anna/SoFetch/node_modules/@nestjs/swagger/dist/swagger-explorer.js:48:56)
(node:78477) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:78477) [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.
Я сузил проблему до контроллера. Вот он:
constructor(@Inject('UserService') private readonly userService: UserService) {}
@Post('login')
async login(@Body() login: LoginModel): Promise<any> {
return this.userService.login(login.username, login.password);
}
@Post('register/customer')
async registerCustomer(@Body() customer: CustomerRegisterModel): Promise<any> {
if(customer.password !== customer.confirmPassword) {
throw new NotAcceptableException();
}
return this.userService.createCustomer(customer.name, customer.username, customer.email, customer.password);
}
@Post('register/technician')
async registerTechnician(@Body() technician: TechnicianRegistrationModel): Promise<any> {
return this.userService.createTechnician(technician.name, technician.username, technician.email, technician.password, technician.location);
}
этот контроллер не работает, но когда я добавляю простой метод, подобный этому:
@Get()
Hello(login: string):string{
return "helloworld"
}
, он работает.
Кажется, что яесть проблема с атрибутами @Body @Query. Но мне не удается его найти.
У кого-нибудь еще была такая же проблема?