diff --git a/lib/index.ts b/lib/index.ts index 25c1a6c..504a875 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -123,8 +123,13 @@ const mapSchemaTypeToFieldSchema = ({ const meta: any = {}; for (const metaProp of props) { - if (value && value[metaProp] != null) { - meta[metaProp] = value[metaProp]; + 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; + const defaultSupportedMetaPropsAreValid = isValidDescription && isValidEnum && isValidRequired; + if (value && metaValue != null && defaultSupportedMetaPropsAreValid) { + meta[metaProp] = metaValue; } } diff --git a/package-lock.json b/package-lock.json index 154e18e..beab527 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "mongoose-to-swagger", - "version": "1.5.0", + "version": "1.5.1", "lockfileVersion": 2, "requires": true, "packages": { diff --git a/package.json b/package.json index 9213acf..97af912 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mongoose-to-swagger", - "version": "1.5.0", + "version": "1.5.1", "description": "Conversion library for transforming Mongoose schema objects into Swagger schema definitions.", "homepage": "", "author": { @@ -44,7 +44,8 @@ "test:watch": "mocha lib/*.test.js --watch", "test": "mocha lib/*.test.ts", "build": "tsc", - "prepublish": "npm run build" + "prepublish": "npm run build", + "preinstall": "npm run build" }, "dependencies": {}, "license": "MIT",