-
Notifications
You must be signed in to change notification settings - Fork 29
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
Add option for omitting custom fields #23
Conversation
lib/index.ts
Outdated
} = options; | ||
props = [...defaultSupportedMetaProps, ...props]; | ||
omitted = new Set(options.omitId ? ['__v', '_id'] : ['__v']); | ||
omitted = new Set(omitId ? ['__v', '_id'] : ['__v']); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there a reason you're creating a new set instead of just adding the keys to the existing set?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes.
omitted
variable is in the outer scope, so if we change it, the new value will be used in next function calls.
By making a new set we drop it back to default every function call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah good catch -
the omitted variable in the root scope is in use by the function removeOmitted
also in the root scope.
assigning the new Set to the root level omitted
variable still globally mutates the root scope.
since removeOmitted
is only used once within the scope of documentModel
you could just move that function declaration to be in scope of documentModel and set it once as a fn of defaults + input omitFields
mongoose-to-swagger/lib/index.ts
Line 218 in 3d06ca2
const removeOmitted = (swaggerFieldSchema: { |
mongoose-to-swagger/lib/index.ts
Line 228 in 3d06ca2
return swaggerFieldSchema.type != null && !omitted.has(swaggerFieldSchema.field); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add documentation for the new feature to the readme.
published @ [email protected] |
#19