From 58926bc6feecdacff716b25fab20286592b8309b Mon Sep 17 00:00:00 2001 From: Julian Kingman Date: Thu, 27 Oct 2022 08:39:37 -0500 Subject: [PATCH 1/6] check type of default meta props to allow mongoose fields with those names (enum, required, description) --- lib/index.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/index.ts b/lib/index.ts index 25c1a6c..d92ec7c 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -123,7 +123,13 @@ const mapSchemaTypeToFieldSchema = ({ const meta: any = {}; for (const metaProp of props) { - if (value && value[metaProp] != null) { + const isValidEnum = metaProp === 'enum' ? Array.isArray(metaProp) : true; + const isValidRequired = metaProp === 'required' + ? Array.isArray(metaProp) || typeof metaProp === 'boolean' + : true; + const isValidDescription = metaProp === 'enum' ? typeof metaProp === 'string' : true; + const defaultSupportedMetaPropsAreValid = isValidDescription && isValidEnum && isValidRequired; + if (value && value[metaProp] != null && defaultSupportedMetaPropsAreValid) { meta[metaProp] = value[metaProp]; } } From 0b5e7fdad71ed9048b97ae02b39584199ff6bb04 Mon Sep 17 00:00:00 2001 From: Julian Kingman Date: Thu, 27 Oct 2022 08:44:09 -0500 Subject: [PATCH 2/6] 1.5.1 --- package-lock.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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..283d719 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": { From 4a11068ef926dafcb9acd03b3fb9fcce673c5ba0 Mon Sep 17 00:00:00 2001 From: Julian Kingman Date: Thu, 27 Oct 2022 09:01:44 -0500 Subject: [PATCH 3/6] fix typecheck --- lib/index.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/lib/index.ts b/lib/index.ts index d92ec7c..69420c5 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -123,14 +123,13 @@ const mapSchemaTypeToFieldSchema = ({ const meta: any = {}; for (const metaProp of props) { - const isValidEnum = metaProp === 'enum' ? Array.isArray(metaProp) : true; - const isValidRequired = metaProp === 'required' - ? Array.isArray(metaProp) || typeof metaProp === 'boolean' - : true; - const isValidDescription = metaProp === 'enum' ? typeof metaProp === 'string' : true; + const metaValue = value[metaProp]; + const isValidEnum = metaValue === 'enum' ? Array.isArray(metaValue) : true; + const isValidRequired = metaValue === 'required' ? Array.isArray(metaValue) || typeof metaValue === 'boolean' : true; + const isValidDescription = metaValue === 'enum' ? typeof metaValue === 'string' : true; const defaultSupportedMetaPropsAreValid = isValidDescription && isValidEnum && isValidRequired; - if (value && value[metaProp] != null && defaultSupportedMetaPropsAreValid) { - meta[metaProp] = value[metaProp]; + if (value && metaValue != null && defaultSupportedMetaPropsAreValid) { + meta[metaProp] = metaValue; } } From 755f07d5716495918f791f769e01308c75daa87f Mon Sep 17 00:00:00 2001 From: Julian Kingman Date: Thu, 27 Oct 2022 09:02:57 -0500 Subject: [PATCH 4/6] add preinstall hook --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 283d719..97af912 100644 --- a/package.json +++ b/package.json @@ -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", From dd6ff0ac7cd09175f6dbcf7873084e27c8e7ec7a Mon Sep 17 00:00:00 2001 From: Julian Kingman Date: Thu, 27 Oct 2022 09:10:08 -0500 Subject: [PATCH 5/6] oops --- lib/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/index.ts b/lib/index.ts index 69420c5..4133d63 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -126,7 +126,7 @@ const mapSchemaTypeToFieldSchema = ({ const metaValue = value[metaProp]; const isValidEnum = metaValue === 'enum' ? Array.isArray(metaValue) : true; const isValidRequired = metaValue === 'required' ? Array.isArray(metaValue) || typeof metaValue === 'boolean' : true; - const isValidDescription = metaValue === 'enum' ? typeof metaValue === 'string' : true; + const isValidDescription = metaValue === 'description' ? typeof metaValue === 'string' : true; const defaultSupportedMetaPropsAreValid = isValidDescription && isValidEnum && isValidRequired; if (value && metaValue != null && defaultSupportedMetaPropsAreValid) { meta[metaProp] = metaValue; From 6eb0da4c7c97bf929918f8b08cd8dda5934e3c47 Mon Sep 17 00:00:00 2001 From: Julian Kingman Date: Thu, 27 Oct 2022 09:15:10 -0500 Subject: [PATCH 6/6] oops --- lib/index.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/index.ts b/lib/index.ts index 4133d63..504a875 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -124,9 +124,9 @@ const mapSchemaTypeToFieldSchema = ({ for (const metaProp of props) { const metaValue = value[metaProp]; - const isValidEnum = metaValue === 'enum' ? Array.isArray(metaValue) : true; - const isValidRequired = metaValue === 'required' ? Array.isArray(metaValue) || typeof metaValue === 'boolean' : true; - const isValidDescription = metaValue === 'description' ? typeof metaValue === 'string' : true; + 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;