Validation is not performed on config loaded with custom loader
sergey-shablenko opened this issue · comments
Is there an existing issue for this?
- I have searched the existing issues
Current behavior
we load and validate config outside of nestjs and just provide already parsed config to the module like this
ConfigModule.forRoot({
isGlobal: true,
ignoreEnvFile: true,
ignoreEnvVars: true,
expandVariables: false,
// no validation needed, it is validated during load
validate: (config) => config,
load: [get],
})
when we try to use config service
configService: ConfigService<EnvironmentVariables, true>
typings are correct, it recognises numbers, booleans, e.t.c, but returns raw string value from _cache causing broken types
Minimum reproduction code
aint nobody got time for that (sorry)
Steps to reproduce
No response
Expected behavior
validate logic should be called on objects loaded from custom loaders to have consistent logic and safe types
Package version
3.1.1
NestJS version
10.2.6
Node.js version
18.16.0
In which operating systems have you tested?
- macOS
- Windows
- Linux
Other
Sorry that I did not provide reproduction code, but it is easy to track down without it. Either trust loaded config and add it to validated cache, or run validation logic to add it there
I bumped into this as well and would benefit from the behaviour being changed :D
EDIT: As a workaround, I just manually validated each slice before returning it from registerAs
and ended up not having it on the main configuration object.