#How to use both @nestjs/swagger and @nestjs/mapped-types

2 messages · Page 1 of 1 (latest)

shell dagger
#

Hi guy, I'm using NestJS for my project
When make a Dto A, B, ... for validation body request and generate an Open Api for document,
I'm using @nestjs/swagger to generate an open Api.

The code look like

import { ApiProperty, PickType } from '@nestjs/swagger';
class User  {
@ApiProperty({ example: 'xxxx'})
  public id: string;

  @ApiProperty({ example: 'wind blade'})
  public fullName: string;
  ....
}

class CreateUserDto extends PickType(User, ['fullName'])   {
    ....
}

So The Open API is working well,
**----
And in service I using

  create(createUserDto: CreateUserDto) {
      ...
    return functionCreateUser ({
        fullName: createUserDto.fullName
    })
  }

But createUserDto.fullName showing an error **Unresolved variable ** with fullName
**--
I've change

    import {PartialType}  from **@nestjs/swagger 
    ```
to
```javascript
    import {PartialType}  from **@nestjs/mapped-types 

The service stop show the error, but property fullName in CreateUserDto had been lost in Open API
**So, Could you tell me any solution to keep fullName in CreateUserDto, also make the service stop show the error?
Thanks 😄

strong garden
#

@nestjs/swagger's mapped-type functions use @nestjs/mapped-types so it should work as expected. Can you provide a minimum reproduction that shows it not working as intended?