Skip to content

Commit

Permalink
fix: dynamic ref schema functions #2182
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilmysliwiec committed Oct 21, 2024
1 parent ec25b63 commit b56ce5a
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/factories/definitions.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@ export class DefinitionsFactory {
) as mongoose.Schema;
}
return schemaDefinition;
} else if (typeof optionsOrType.type === 'function' || Array.isArray(optionsOrType.type)) {
} else if (
typeof optionsOrType.type === 'function' ||
Array.isArray(optionsOrType.type)
) {
optionsOrType.type = this.inspectTypeDefinition(optionsOrType.type);
return optionsOrType;
} else if (Array.isArray(optionsOrType)) {
Expand All @@ -103,7 +106,10 @@ export class DefinitionsFactory {
if (typeof optionsOrType?.ref === 'function') {
try {
const result = (optionsOrType.ref as Function)();
optionsOrType.ref = result?.name ?? result;
if (typeof result?.name === 'string') {
optionsOrType.ref = result.name;
}
optionsOrType.ref = optionsOrType.ref;
} catch (err) {
if (err instanceof TypeError) {
const refClassName = (optionsOrType.ref as Function)?.name;
Expand Down

0 comments on commit b56ce5a

Please sign in to comment.