Skip to content

Commit

Permalink
workaround for classValidator defaultStorage
Browse files Browse the repository at this point in the history
  • Loading branch information
paulwer committed Nov 8, 2024
1 parent b91fe48 commit 8662b2b
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions packages/framework/src/validators/class-validator.validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,23 @@ export class ClassValidatorValidator implements Validator<ClassType> {

async transformToJsonSchema(schema: ClassType): Promise<JsonSchema> {
try {
// eslint-disable-next-line global-require
const { defaultMetadataStorage } = require('class-transformer/cjs/storage');
// @ts-ignore
const { defaultMetadataStorage: defaultMetadataStorageCjs } = await import('class-transformer/cjs/storage');
// @ts-ignore
const { defaultMetadataStorage: defaultMetadataStorageEsm2015 } = await import(
// @ts-ignore
'class-transformer/esm2015/storage'
);
// @ts-ignore
const { defaultMetadataStorage: defaultMetadataStorageEsm5 } = await import('class-transformer/esm5/storage');
// @ts-ignore
const defaultMetadataStorage = defaultMetadataStorageCjs._typeMetadatas.size
? defaultMetadataStorageCjs
: defaultMetadataStorageEsm2015._typeMetadatas.size
? defaultMetadataStorageEsm2015
: defaultMetadataStorageEsm5._typeMetadatas.size
? defaultMetadataStorageEsm5
: undefined;
const { getMetadataStorage } = await import('class-validator');
const { targetConstructorToSchema, validationMetadatasToSchemas } = await import('class-validator-jsonschema');

Expand Down

0 comments on commit 8662b2b

Please sign in to comment.