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

Regular expression in Matches decorator of class-validator throws exception #1982

Closed
2 tasks done
RaiMX opened this issue Jul 13, 2022 · 1 comment
Closed
2 tasks done

Comments

@RaiMX
Copy link

RaiMX commented Jul 13, 2022

Did you read the migration guide?

  • I have read the whole migration guide

Is there an existing issue that is already proposing this?

  • I have searched the existing issues

Potential Commit/PR that introduced the regression

No response

Versions

No response

Describe the regression

When using regular expression in @matches decorator from class-validator swagger throws exception

/app/node_modules/js-yaml/lib/dumper.js:868
      throw new YAMLException('unacceptable kind of an object to dump ' + type);
            ^
YAMLException: unacceptable kind of an object to dump [object RegExp]
    at writeNode (/app/node_modules/js-yaml/lib/dumper.js:868:13)
    at writeBlockMapping (/app/node_modules/js-yaml/lib/dumper.js:731:10)
    at writeNode (/app/node_modules/js-yaml/lib/dumper.js:834:9)
    at writeBlockMapping (/app/node_modules/js-yaml/lib/dumper.js:731:10)
    at writeNode (/app/node_modules/js-yaml/lib/dumper.js:834:9)
    at writeBlockMapping (/app/node_modules/js-yaml/lib/dumper.js:731:10)
    at writeNode (/app/node_modules/js-yaml/lib/dumper.js:834:9)
    at writeBlockMapping (/app/node_modules/js-yaml/lib/dumper.js:731:10)
    at writeNode (/app/node_modules/js-yaml/lib/dumper.js:834:9)
    at writeBlockMapping (/app/node_modules/js-yaml/lib/dumper.js:731:10)

Minimum reproduction code

Have typeorm entity like this

import { Transform } from 'class-transformer';
import {
    IsAlphanumeric,
    IsNotEmpty,
    IsOptional,
    Matches,
} from 'class-validator';

@Entity()
export class DocPropTypes {
    @IsOptional({ groups: [CREATE] })
    @IsNotEmpty({ groups: [UPDATE] })
    @PrimaryGeneratedColumn()
    id: number;

    @IsNotEmpty({ groups: [CREATE] })
    @IsOptional({ groups: [UPDATE] })
    @IsAlphanumeric()
    @Matches(/[^ ]+/)  // <============== This line gives errors. Removing this line and exception is gone
    @Transform((transform) => transform.value?.trim())
    @Column({ comment: 'Code' })
    code: string;
}

Expected behavior

With old swagger (nestjs 8) there was no error

Other

No response

@kamilmysliwiec
Copy link
Member

We're tracking this here #1980

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants