From f14ae8af4bb5d6494150ae54f5b4a9f3af0c368b Mon Sep 17 00:00:00 2001 From: Muhammad Aaqil Date: Wed, 21 Jun 2023 21:14:50 +0500 Subject: [PATCH] fix: set nullable under jsonSchema in property to true in case of nullable property Signed-off-by: Muhammad Aaqil --- lib/datasource.js | 3 ++- test/discovery.test.js | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/lib/datasource.js b/lib/datasource.js index 0ca42831..39645b45 100644 --- a/lib/datasource.js +++ b/lib/datasource.js @@ -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]; } diff --git a/test/discovery.test.js b/test/discovery.test.js index fadd7d5e..6ce9692f 100644 --- a/test/discovery.test.js +++ b/test/discovery.test.js @@ -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); @@ -211,6 +224,9 @@ describe('Memory connector with mocked discovery', function() { properties: { available: { length: null, + jsonSchema: { + nullable: true, + }, memory: { columnName: 'AVAILABLE', dataLength: null, @@ -228,6 +244,9 @@ describe('Memory connector with mocked discovery', function() { }, locationId: { length: 20, + jsonSchema: { + nullable: false, + }, memory: { columnName: 'LOCATION_ID', dataLength: 20, @@ -245,6 +264,9 @@ describe('Memory connector with mocked discovery', function() { }, productId: { length: 20, + jsonSchema: { + nullable: false, + }, memory: { columnName: 'PRODUCT_ID', dataLength: 20, @@ -262,6 +284,9 @@ describe('Memory connector with mocked discovery', function() { }, total: { length: null, + jsonSchema: { + nullable: true, + }, memory: { columnName: 'TOTAL', dataLength: null,