Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Any way to work with mapped types from @nestjs/swagger #173

Closed
micalevisk opened this issue Jul 27, 2020 · 4 comments
Closed

Any way to work with mapped types from @nestjs/swagger #173

micalevisk opened this issue Jul 27, 2020 · 4 comments
Labels
backlog enhancement New feature or request

Comments

@micalevisk
Copy link
Contributor

micalevisk commented Jul 27, 2020

I want to use utility functions like OmitType (provided by @nestjs/swagger lib) to do something like this:

import { ApiPropertyOptional, OmitType } from '@nestjs/swagger';

class UserVm { // assuming that each prop can have some kind of ApiProperty decorator
  @AutoMap()
  firstName: string;
  @AutoMap()
  lastName: string;
  @AutoMap()
  about: string;
  @AutoMap()
  @ApiPropertyOptional({ type: String, format: 'date-time' })
  deletedAt?: Date
  @AutoMap()
  deletedBy?: number;
  // ...
}

class NonDeletableUserVm extends OmitType(UserVm, ['deletedAt', 'deletedBy']) {}
// ^ this class will be a swagger schema/model as well

but the annotations generated by @AutoMap() decorator are not inherited when using these helpers functions, so all props annotated with @AutoMap() will not be auto mapped by the mapper (since they're aren't identified).

Maybe this is a limitation of @nestjs/swagger (or TS?) but I'm not sure.

Any thoughts?

Great lib btw 🥰


minimal reproduction

https://codesandbox.io/s/nartcautomapper-issue-173-wv1s0

@nartc
Copy link
Owner

nartc commented Jul 27, 2020

Interesting. I'll have to take a look and will let you know ASAP if it's a go or no-go. Thanks for the issue

@nartc nartc added enhancement New feature or request question Further information is requested labels Jul 27, 2020
@nartc
Copy link
Owner

nartc commented Aug 5, 2020

Not sure if I have time this weekend to look into this. I'm going to put this in the backlog for now.

@nartc nartc added backlog and removed question Further information is requested labels Aug 5, 2020
@micalevisk
Copy link
Contributor Author

Not sure if I have time this weekend to look into this. I'm going to put this in the backlog for now.

It's fine 👍

You can download a minimal reproduction here later: https://codesandbox.io/s/nartcautomapper-issue-173-wv1s0
See src/app.profile.ts and the response at http://localhost:3030/docs using the Try it out button.

@nartc
Copy link
Owner

nartc commented Aug 10, 2020

@micalevisk Looking at nestjs/mapped-types, it seems that the mapped types only inherit Validation and Transform metadata (class-transformer and class-validation). What I can do is to add some mixins to nestjsx-automapper (instead of this package) to extend the functionality of the mapped-types but with the addition of @AutoMap() decorator. Hence, I'm going to open an issue over at nestjsx/automapper and close this one. Please track this issue here: nestjsx/automapper#254

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backlog enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants