loopback-next icon indicating copy to clipboard operation
loopback-next copied to clipboard

lb4 discover create invalid property in model file (DB2 IBMI)

Open souvrard opened this issue 1 year ago • 1 comments

Describe the bug

Env: DB2 on IBMI whith loopback 4 fresh install

Command:

lb4 discover --models=XXXX

generate XXX.model.ts with invalid @property:

  @property({
    type: 'string',
    required: true,
    jsonSchema: {nullable: false},
    length: 15,
    generated: ,  <====================  INVALID
  })

The "generated" property has a value on "undefined" ...

I don't know if it is the best solution but for me the following correction fixes the problem:

File loopback/cli/lib/model-discoverer.js, line 89:

before:

    // Delete the null properties so the template doesn't spit out `key: ;`
    if (v === null) {
      delete o[k];
    }

after:

    // Delete the null and undefined properties so the template doesn't spit out `key: ;`
    if (v === null || typeof v === 'undefined') {
      delete o[k];
    }

stephane

Logs

src/models/b-2-butilpf.model.ts:211:16 - error TS1109: Expression expected.                                                                                                                                                                                                                   
211     generated: ,                                                                                                                                                                                                
                   ~                                                                                                                                                                                                
src/models/b-2-butilpf.model.ts:223:16 - error TS1109: Expression expected.                                                                                                                                                                                                                     
223     generated: ,                                                                                                                                                                                                
                   ~                                                                                                                                                                                                
src/models/b-2-butilpf.model.ts:233:16 - error TS1109: Expression expected.                                                                                                                                                                                                                     
233     generated: ,                                                                                                                                                                                                
                   ~                                                                                                                                                                                                
src/models/b-2-butilpf.model.ts:243:16 - error TS1109: Expression expected.                                                                                                                                                                                                                     
243     generated: ,                                                                                                                                                                                                
                   ~                                                                                                                                                                                                
src/models/b-2-butilpf.model.ts:253:16 - error TS1109: Expression expected.                                                                                                                                                                                                                     
253     generated: ,                                                                                                                                                                                                
                   ~                                                                                                                                                                                                
src/models/b-2-butilpf.model.ts:263:16 - error TS1109: Expression expected.                                                                                                                                                                                                                     
263     generated: ,

Additional information

package.json dependencies:

"dependencies": { "@loopback/boot": "^6.1.2", "@loopback/core": "^5.1.2", "@loopback/repository": "^6.1.2", "@loopback/rest": "^13.1.2", "@loopback/rest-explorer": "^6.1.2", "loopback-connector-ibmi": "^1.0.1", "odbc": "^2.4.8", "tslib": "^2.0.0" }, "devDependencies": { "@loopback/testlab": "^6.1.2", "@types/mocha": "^10.0.1", "@types/node": "^16.18.40", "mocha": "^10.2.0", "rimraf": "^5.0.1", "source-map-support": "^0.5.21", "typescript": "~5.1.6" }

console output of one column property:

'type: string' 'required: true' 'jsonSchema: [object Object]' 'length: 1' 'precision: null' 'scale: null' 'generated: undefined' <============ undefined 'ibmi: [object Object]'

Reproduction

no AS400 available for reproduction :/

souvrard avatar Aug 28 '23 10:08 souvrard

Hi. This bug is happening after merging this PR of mine. I will make a PR soon to have it fixed.

aaqilniz avatar Dec 01 '23 17:12 aaqilniz

This PR solves the issue. I am closing the issue.

aaqilniz avatar Mar 20 '24 06:03 aaqilniz