davidkel / hlf

0 stars 0 forks source link

Chaincode fails to instantiate when annotations are used #24

Open davidkel opened 4 years ago

davidkel commented 4 years ago

Given the following model definition

@Object()
export class Asset {

    @Property()
    public id: string;

    @Property()
    public params: any = { 
        param1: 'param1',
        param2: 'param2',
    } 
}

The chaincode fails to instantiate with the following cryptic message

[17/09/2019 15:35:57] [INFO] fabricvscodelocalfabric-peer0.org1.example.com-Documents-0.0.8|  --module-path  [string] [default: "/usr/local/src"]
[17/09/2019 15:35:57] [INFO] fabricvscodelocalfabric-peer0.org1.example.com-Documents-0.0.8|
[17/09/2019 15:35:57] [INFO] fabricvscodelocalfabric-peer0.org1.example.com-Documents-0.0.8|{ [Error: can't resolve reference Object from id DaveAsset#]
[17/09/2019 15:35:57] [INFO] fabricvscodelocalfabric-peer0.org1.example.com-Documents-0.0.8|  message: 'can\'t resolve reference Object from id DaveAsset#',
[17/09/2019 15:35:57] [INFO] fabricvscodelocalfabric-peer0.org1.example.com-Documents-0.0.8|  missingRef: 'Object',
[17/09/2019 15:35:57] [INFO] fabricvscodelocalfabric-peer0.org1.example.com-Documents-0.0.8|  missingSchema: 'Object' }

There are 2 issues here

  1. The error message does not help determine the problem
  2. The type definition of any doesn't appear to be allowed

As well as "any", changing the type to "object" also produces the same results meaning that "object" is not allowed either, so it's possible other standard typescript types also cause the same problem.

As a further thought it would be good if unsupported options were picked up at typescript compile time rather than at runtime but don't know if that is possible and may be a limitation of the experimental annotation support in typescript.