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

Add mixins (extends) feature to work with @nestjs/mapped-types and @nestjs/swagger #550

Open
2 of 9 tasks
ouwais-chaoui opened this issue May 23, 2023 · 3 comments
Open
2 of 9 tasks
Labels
bug Something isn't working

Comments

@ouwais-chaoui
Copy link

ouwais-chaoui commented May 23, 2023

Is there an existing issue for this?

  • I have searched the existing issues

Describe the issue

Hello folks,

I want to create a DTO class that keeps the @Swagger() and @AutoMap() annotations.

import { DictionaryEntryDto } from './dictionary-entry.dto';
import { MapperPickType } from '@automapper/classes/mapped-types';

export class CreateDictionaryEntryDto extends MapperPickType(
  DictionaryEntryDto,
  ['definition', 'name'],
) {}

The problem is that the swagger annotations are not taken ...
image

If I use the PickType of swagger, I loose the @AutoMap() metadata ...

I found an issue that was closed but never got resolved : #271

Is there a solution for that ?

Models/DTOs/VMs

Parent class :

import { ApiProperty } from '@nestjs/swagger';
import { IsString, MaxLength, MinLength } from 'class-validator';
import { DictionaryDto } from 'src/dictionary/dto/dictionary.dto';
import { DictionaryEntry } from '../entities/dictionary-entry.entity';
import { AutoMap } from '@automapper/classes';

export class DictionaryEntryDto implements DictionaryEntry {
  @AutoMap()
  @ApiProperty({
    example: '64f52fdb-7621-454f-a35e-524ee2ab3466',
    type: 'string',
    format: 'uuid',
  })
  @IsString()
  id: string;

  @AutoMap()
  @ApiProperty({
    example: 'test',
  })
  @IsString()
  @MaxLength(28)
  @MinLength(3)
  name: string;

  @AutoMap()
  @ApiProperty({
    example: 'test',
  })
  @IsString()
  definition: string;

  dictionary: DictionaryDto;
}

Subclass DTO :

import { DictionaryEntryDto } from './dictionary-entry.dto';
import { MapperPickType } from '@automapper/classes/mapped-types';

export class CreateDictionaryEntryDto extends MapperPickType(
  DictionaryEntryDto,
  ['definition', 'name'],
) {}

Mapping configuration

No response

Steps to reproduce

No response

Expected behavior

To keep both @AutoMap() and @ApiProperty() metadata

Screenshots

No response

Minimum reproduction code

No response

Package

  • I don't know.
  • @automapper/core
  • @automapper/classes
  • @automapper/nestjs
  • @automapper/pojos
  • @automapper/mikro
  • @automapper/sequelize
  • Other (see below)

Other package and its version

No response

AutoMapper version

8.0.0

Additional context

No response

@ouwais-chaoui ouwais-chaoui added the bug Something isn't working label May 23, 2023
@ouwais-chaoui
Copy link
Author

@micalevisk @nartc Hello folks !

Could you please help me with this problem ? I know you had already the same issue #271

Do you have any work around or did I miss something ?

Thank you in advance guys your library is gold !

@devskar
Copy link

devskar commented Jun 28, 2023

We also would need an update for this issue

@ouwais-chaoui
Copy link
Author

Any updates on this ticket guys ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants