Skip to content

Commit

Permalink
fix: set nullable under jsonSchema in property to true in case of nul…
Browse files Browse the repository at this point in the history
…lable property

Signed-off-by: Muhammad Aaqil <aaqilniz@yahoo.com>
  • Loading branch information
aaqilniz committed Jun 26, 2023
1 parent 025b22a commit f14ae8a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/datasource.js
Original file line number Diff line number Diff line change
Expand Up @@ -1668,12 +1668,13 @@ DataSource.prototype.discoverSchemas = function(tableName, options, cb) {
type: item.type,
required: !item.generated && (item.nullable === 'N' || item.nullable === 'NO' ||
item.nullable === 0 || item.nullable === false),
jsonSchema: {nullable: item.nullable === 'Y' || item.nullable === 'YES' ||
item.nullable === 1 || item.nullable === true},
length: item.dataLength,
precision: item.dataPrecision,
scale: item.dataScale,
generated: item.generated,
};

if (pks[item.columnName]) {
schema.properties[propName].id = pks[item.columnName];
}
Expand Down
25 changes: 25 additions & 0 deletions test/discovery.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,19 @@ describe('Memory connector with mocked discovery', function() {
});
});

it('should have jsonSchema: {nullable: true} in property for `available`', function(done) {
ds.discoverSchemas('INVENTORY', {}, function(err, schemas) {
if (err) return done(err);
schemas.should.have.property('STRONGLOOP.INVENTORY');
const s = schemas['STRONGLOOP.INVENTORY'];
s.name.should.be.eql('Inventory');
s.properties.available.should.have.property('jsonSchema');
s.properties.available.jsonSchema.should.have.property('nullable');
s.properties.available.jsonSchema.nullable.should.be.eql(true);
done();
});
});

it('should keep the column names the same as database', function(done) {
ds.discoverSchemas('INVENTORY', {disableCamelCase: true}, function(err, schemas) {
if (err) return done(err);
Expand Down Expand Up @@ -211,6 +224,9 @@ describe('Memory connector with mocked discovery', function() {
properties: {
available: {
length: null,
jsonSchema: {
nullable: true,
},
memory: {
columnName: 'AVAILABLE',
dataLength: null,
Expand All @@ -228,6 +244,9 @@ describe('Memory connector with mocked discovery', function() {
},
locationId: {
length: 20,
jsonSchema: {
nullable: false,
},
memory: {
columnName: 'LOCATION_ID',
dataLength: 20,
Expand All @@ -245,6 +264,9 @@ describe('Memory connector with mocked discovery', function() {
},
productId: {
length: 20,
jsonSchema: {
nullable: false,
},
memory: {
columnName: 'PRODUCT_ID',
dataLength: 20,
Expand All @@ -262,6 +284,9 @@ describe('Memory connector with mocked discovery', function() {
},
total: {
length: null,
jsonSchema: {
nullable: true,
},
memory: {
columnName: 'TOTAL',
dataLength: null,
Expand Down

0 comments on commit f14ae8a

Please sign in to comment.