typestack / class-validator

Decorator-based property validation for classes.
MIT License
10.89k stars 786 forks source link

question: receiving an unknown value was passed error #1514

Closed phhoef closed 1 year ago

phhoef commented 2 years ago

I was trying to...

I am using `nest-typed-config` to load multiple yml config files into my nestjs application. For simplicity, my examples here are only with 1 file. The config file looks like this: ```yml - name: test1 storage: s3 signatureEnabled: true - name: test2 storage: fs signatureEnabled: true - name: test3 storage: ftp signatureEnabled: true ``` I've created a class, that holds all the configuration files. ```ts export class RootConfig { @IsNotEmpty() @IsArray() @ValidateNested({ each: true, message: 'blabla'}) @Type(() => HttpConfig) public readonly http!: HttpConfig[] }; ``` The nested type is defined: ```ts export class HttpConfig { @IsString() @IsNotEmpty() name: string @IsString() @IsNotEmpty() storage: string @IsBoolean() signatureEnabled: boolean = true }; ``` The `nest-typed-config` module is imported in my `app.module.ts` class ```ts TypedConfigModule.forRoot({ schema: RootConfig, load: directoryLoader({ directory: BASE_PATH }) }), ``` **The problem:**

The validation fails always with the following error message:

Error: Configuration is not valid:
 - config http.0.undefined does not match the following rules:
  - unknownValue: an unknown value was passed to the validate function, current config is `undefined`
  - config http.1.undefined does not match the following rules:
  - unknownValue: an unknown value was passed to the validate function, current config is `undefined`
  - config http.2.undefined does not match the following rules:
  - unknownValue: an unknown value was passed to the validate function, current config is `undefined`

There are as many errors as entries in the array of my yml config file. I've attached the debugger and I see that the file is loaded properly.

NoNameProvided commented 1 year ago

I don't provide support about how to use class-validator with other packages.

If you think this is a bug please open a bug report with a minimal reproduction case without any external dependencies.

If the issue still persists, you may open a new Q&A in the discussions tab and maybe someone from the community may be able to help.

github-actions[bot] commented 1 year ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.