Skip to content
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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

JulianKingman
Copy link

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), or enum.

I'm not 100% sure this is the best way to do it, but it works 🤷

This would fix this issue: #36

@James1x0 James1x0 self-requested a review November 1, 2022 16:57
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;
Copy link
Contributor

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",
Copy link
Contributor

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 🙏

Comment on lines +47 to +48
"prepublish": "npm run build",
"preinstall": "npm run build"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"prepublish": "npm run build",
"preinstall": "npm run build"
"prepublish": "npm run build"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants