-
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
Allow required, description, and enum to be regular fields if their types are wrong #51
base: master
Are you sure you want to change the base?
Conversation
…names (enum, required, description)
const metaValue = value[metaProp]; | ||
const isValidEnum = metaProps === 'enum' ? Array.isArray(metaValue) : true; | ||
const isValidRequired = metaProps === 'required' ? Array.isArray(metaValue) || typeof metaValue === 'boolean' : true; | ||
const isValidDescription = metaProps === 'description' ? typeof metaValue === 'string' : true; |
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.
@JulianKingman Wouldn't a more succinct way to address validity of meta props be to check the non-existence of { type }? This is how mongoose requires overrides of meta props in schema definitions.
enum: '' // meta
enum: { type: something } // your field
@@ -1,6 +1,6 @@ | |||
{ | |||
"name": "mongoose-to-swagger", | |||
"version": "1.5.0", | |||
"version": "1.5.1", |
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.
Don't bump patch versions for lib maintainers 🙏
"prepublish": "npm run build", | ||
"preinstall": "npm run build" |
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.
"prepublish": "npm run build", | |
"preinstall": "npm run build" | |
"prepublish": "npm run build" |
Would you accept this PR if I added some tests and removed the preinstall step?
The idea here is to not set the meta fields unless they're of a type that it's expecting, effectively allowing mongoose fields called
required
,description
(quite common), orenum
.I'm not 100% sure this is the best way to do it, but it works 🤷
This would fix this issue: #36