From 2b0b434855fb05b45b9a71db9f48d17c49d37d04 Mon Sep 17 00:00:00 2001 From: Joni Gear Date: Tue, 14 Jun 2022 11:53:11 +1000 Subject: [PATCH 1/2] Version bump: upgrade sequelize peer dependency --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index aa4151e..3ff83ae 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "sequelize-to-json-schema", - "version": "0.3.0", + "version": "1.0.0", "description": "Flexible json-schema generator from sequelize models", "main": "lib/index.js", "scripts": { @@ -45,6 +45,6 @@ "mocha": "^5.1.0" }, "peerDependencies": { - "sequelize": "^3.31.2" + "sequelize": "^6.19.2" } } From 2cc8ed51e530ba7cc1171c60eed0e97a23c0cace Mon Sep 17 00:00:00 2001 From: Joni Gear Date: Tue, 14 Jun 2022 12:02:47 +1000 Subject: [PATCH 2/2] Model now has rawAttributes --- lib/sequelizeSchema.js | 8 ++++---- test/mockModel.js | 4 ++-- test/schema.test.js | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/sequelizeSchema.js b/lib/sequelizeSchema.js index 8151b7a..f8beb38 100644 --- a/lib/sequelizeSchema.js +++ b/lib/sequelizeSchema.js @@ -80,7 +80,7 @@ class JsonSchema { selectAttributes() { let attributes = this.options.selectAttributes ? this.options.selectAttributes(this.model) : - Object.keys(this.model.attributes); + Object.keys(this.model.rawAttributes); attributes = attributes.concat(this.selectAssociations()); @@ -206,7 +206,7 @@ class JsonSchema { }); if (this.getDbType(modelAttr) === 'ENUM') { - property.enum = this.model.attributes[modelAttr].type.values; + property.enum = this.model.rawAttributes[modelAttr].type.values; } return [jsonKey, property]; @@ -279,10 +279,10 @@ class JsonSchema { return 'STRING'; } - if (!this.model.attributes[modelAttr]) { + if (!this.model.rawAttributes[modelAttr]) { throw new Error(`Unknown model attribute ${this.model.name}.${modelAttr}`); } - const dbType = this.model.attributes[modelAttr].type.key; + const dbType = this.model.rawAttributes[modelAttr].type.key; return dbType; } diff --git a/test/mockModel.js b/test/mockModel.js index a418202..27b227c 100644 --- a/test/mockModel.js +++ b/test/mockModel.js @@ -7,13 +7,13 @@ function modelFactory(name, attributes) { associate, name, tableName: name, - attributes: {}, + rawAttributes: {}, associations: {}, }; _.forEach(attributes, (value, attr) => { const attribute = _.isString(value) ? { key: value } : value; - model.attributes[attr] = { type: attribute }; + model.rawAttributes[attr] = { type: attribute }; }); models[name] = model; diff --git a/test/schema.test.js b/test/schema.test.js index 7dd2b64..16a06b2 100644 --- a/test/schema.test.js +++ b/test/schema.test.js @@ -16,7 +16,7 @@ function selectAttributes(model) { return ['full_name', 'address', 'profile', 'status', 'name']; } - return Object.keys(model.attributes); + return Object.keys(model.rawAttributes); } function jsonAttributeMapper(model, name) {