elifTech / cpd-ocpp

Open Charge Point Protocol
https://www.eliftech.com/blog/48-a-diy-charging-point-for-an-electric-car-perspective-protocol-and-prototype
MIT License
64 stars 49 forks source link

AssertionError [ERR_ASSERTION]: you must provide a joi schema #11

Open minnat opened 4 years ago

minnat commented 4 years ago

I am writing a simple chargePoint that sends a websocket to the centralSystem. I took the code from the examples and this is where I am facing issues with:

    const boot = new OCPPCommands.BootNotification({
      chargePointVendor: 'BrandX',
      chargeBoxSerialNumber: 'SR' + Math.round(Math.random() * 100000),
      chargePointSerialNumber: '123',
      chargePointModel: '12'
    });

    let answer = await client.send(boot);

OCPPCommands.BootNotification tries to validate the payload with applyPropertiesValidators and it failed to validate with Joi, specifically on this line:

// node_modules/ocpp-eliftech/node_modules/joi/lib/index.js
Hoek.assert(schema && schema instanceof Any, 'you must provide a joi schema');

This is what schema looks like before it fails the schema instanceof Any validation:

{ isJoi: true,
  _currentJoi:
   { isJoi: true,
     _currentJoi:
      { isJoi: true,
        _currentJoi: [Circular],
        _type: 'any',
        _settings: null,
        _baseType: undefined,
        _valids: [InternalSet],
        _invalids: [InternalSet],
        _tests: [],
        _refs: [],
        _flags: {},
        _description: null,
        _unit: null,
        _notes: [],
        _tags: [],
        _examples: [],
        _meta: [],
        _inner: {},
        any: [Function],
        alt: [Function],
        alternatives: [Function],
        array: [Function],
        bool: [Function],
        boolean: [Function],
        binary: [Function],
        date: [Function],
        func: [Function],
        number: [Function],
        object: [Function],
        string: [Function],
        symbol: [Function],
        ref: [Function],
        isRef: [Function],
        validate: [Function],
        describe: [Function],
        compile: [Function],
        assert: [Function],
        attempt: [Function],
        reach: [Function],
        lazy: [Function],
        defaults: [Function],
        extend: [Function],
        extensionSchema: [Object],
        extensionsSchema: [Object],
        version: '13.7.0' },
     _type: 'any',
     _settings: null,
     _baseType: undefined,
     _valids: InternalSet { _set: Set {}, _hasRef: false },
     _invalids: InternalSet { _set: Set {}, _hasRef: false },
     _tests: [],
     _refs: [],
     _flags: {},
     _description: null,
     _unit: null,
     _notes: [],
     _tags: [],
     _examples: [],
     _meta: [],
     _inner: {},
     any: [Function],
     alt: [Function],
     alternatives: [Function],
     array: [Function],
     bool: [Function],
     boolean: [Function],
     binary: [Function],
     date: [Function],
     func: [Function],
     number: [Function],
     object: [Function],
     string: [Function],
     symbol: [Function],
     ref: [Function],
     isRef: [Function],
     validate: [Function],
     describe: [Function],
     compile: [Function],
     assert: [Function],
     attempt: [Function],
     reach: [Function],
     lazy: [Function],
     defaults: [Function],
     extend: [Function],
     extensionSchema:
      { isJoi: true,
        _currentJoi: [Object],
        _type: 'object',
        _settings: [Object],
        _baseType: undefined,
        _valids: [InternalSet],
        _invalids: [InternalSet],
        _tests: [],
        _refs: [],
        _flags: {},
        _description: null,
        _unit: null,
        _notes: [],
        _tags: [],
        _examples: [],
        _meta: [],
        _inner: [Object] },
     extensionsSchema:
      { isJoi: true,
        _currentJoi: [Object],
        _type: 'array',
        _settings: [Object],
        _baseType: undefined,
        _valids: [InternalSet],
        _invalids: [InternalSet],
        _tests: [],
        _refs: [],
        _flags: [Object],
        _description: null,
        _unit: null,
        _notes: [],
        _tags: [],
        _examples: [],
        _meta: [],
        _inner: [Object] },
     version: '13.7.0' },
  _type: 'object',
  _settings: { convert: true },
  _baseType: undefined,
  _valids: InternalSet { _set: Set {}, _hasRef: false },
  _invalids: InternalSet { _set: Set {}, _hasRef: false },
  _tests: [],
  _refs: [],
  _flags: { label: 'BootNotificationRequest' },
  _description: null,
  _unit: null,
  _notes: [],
  _tags: [],
  _examples: [],
  _meta: [],
  _inner:
   { children:
      [ [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object] ],
     renames: [],
     dependencies: [],
     patterns: [] } }

I am not sure if this is a dependency issue or there is something missing on my side. Any help would be appreciated.