Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/sequelizeSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down Expand Up @@ -45,6 +45,6 @@
"mocha": "^5.1.0"
},
"peerDependencies": {
"sequelize": "^3.31.2"
"sequelize": "^6.19.2"
}
}
4 changes: 2 additions & 2 deletions test/mockModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion test/schema.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down