#Does nestjs/swagger work with plain JavaScript?

5 messages · Page 1 of 1 (latest)

sick lodge
#

Dear friends,
I've trying to use nestjs/swagger module with a plain JavaScript solution (no TyepScript at all) without success.
I've got stuck with the following error wherever there is a route param such @Get(':id'):

D:\Git\nestswaggerbasic\node_modules@nestjs\swagger\dist\services\parameter-metadata-accessor.js:14
type: types[param.index],
^
TypeError: Cannot read properties of undefined (reading '0')
...

You can check these simple repo: https://github.com/julioapm/nestswaggerbasic

My Nest info:

[System Information]
OS Version : Windows 10
NodeJS Version : v20.9.0
NPM Version : 10.2.1

[Nest CLI]
Nest CLI Version : 10.2.1

[Nest Platform Information]
platform-express version : 10.2.8
swagger version : 7.1.15
testing version : 10.2.8
common version : 10.2.8
core version : 10.2.8

Thanks for any help,
Julio

slim wing
#

Decorators are a TypeScript functionality.

simple sand
#

I mean, technically yes, you could make @nestjs/swagger work with just javascript, but you'll need to have a lot of @ApiBody() @ApiQuery(), @ApiParam() etc decorators everywhere because of the need for the metadata that is usually provided by typescript when type metadata is emitted

sick lodge
#

Thanks for the info. The problem with the code sample seems to be the lack of metadata for the string "id" passed in as a route parameter in "@Get('id')". I could not find the correct way of using "@ember oysterParam()" to decorate the missing metadata. Any clue?

simple sand
#

It would probably be something like

@ApiParam({
  schema: {
    type: 'object',
    properties: {
      id: {
        type: 'string',
      }
    }
  }
})