Input Specification File
The Blockchain App Builder initialization command reads the input specification file and generates the scaffolded project with several tools to assist in the chaincode development process.
With the specification file you can specify multiple asset definitions and behavior, CRUD and non-CRUD method declaration, custom methods, validation of arguments, auto marshalling/unmarshalling, transparent persistence capability, and invoking rich data queries using SQL SELECTs or CouchDB Query Language. These features will be generated for you.
yaml
or json
. You can see sample specification files in both formats in the Blockchain App Builder package download:
Fabcar-Typescript.yml
Marbles-Go.yml
Note:
As per Go conventions, exported names begin with a capital letter. Therefore all the asset properties and methods must have names starting with capital letters in the specification file.Structure of the Specification File
Typically, you structure a specification file in the following way:
assets:
name:
type:
properties:
name:
type:
id:
derived:
strategy:
algorithm:
format:
mandatory:
default:
validate:
methods:
crud:
others:
customMethods:
Blockchain App Builder supports two special asset types, embedded assets and token
assets, in addition to generic assets with no specified type. The special assets are
defined as type: embedded
or type: token
under the
assets:
section of the specification file.
Table 7-2 Specification File Parameter Descriptions and Examples
Entry | Description | Examples |
---|---|---|
assets: |
This property takes the definition and behavior of the asset. You can give multiple asset definitions here. |
|
name: |
The name of the asset. The following names are reserved. Do not use these names for
assets.
|
|
type: |
Asset types The following special asset types are supported:
If you do not specify a |
|
type: type: embedded |
If this property is set to In the example, the property
Embedded assets do not support circular references.
For instance, in the previous example the
|
Asset:
employee
Asset:
address
|
properties: |
Describe all the properties of an asset. |
|
name: |
The name of the property. |
|
id: |
This specifies the identifier of this asset. This property is mandatory. |
|
type: |
Property types The following basic property types are supported:
For Go chaincodes,
number is mapped
to int and float is mapped to
float64 . Other types are not currently
supported, including the following types:
|
|
derived: |
This property specifies that the id property is derived from other keys. Dependent properties should be This property has two mandatory parameters:
Example 1:
Example 2:
|
Example 1
Example 2
|
mandatory: |
The corresponding property is mandatory and cannot be skipped while creating an asset. |
|
default: |
This gives you the default value of this property. |
|
validate: |
The given property is validated against some of the out-of-box validations provided by Blockchain App Builder. You can chain validations if you ensure that the chain is valid. If the |
|
validate:
type: number |
These validations can be chained together separated by commas. |
|
validate:
type: string |
For Go chaincodes, regular expressions which contain certain reserved characters or whitespace characters should be properly escaped. |
|
validate:
type: boolean |
In the example, the validation of property |
|
validate:
type: array |
By type itself, in the form of You can enter limits to the array in the format |
|
validate:
type: date |
Date should be one of these formats:
|
|
methods: |
Use this to state which of the CRUD (Create/Read/Update/Delete) or additional methods are to be generated. By default, if nothing is entered, all CRUD and other methods are generated. |
|
crud: |
If this array is left empty, no CRUD methods will be created. If the The |
|
others: |
If this array is left empty, no other methods will be created. If the The |
|
customMethods: |
This property creates invokable custom method templates in the main controller file. It takes the method signature and creates the function declaration in the controller file. You can provide language specific function declarations here. We provide a custom method named |
TypeScript
Go
|