Documentation ¶
Index ¶
- Constants
- func GetJSONSchema() ([]byte, error)
- func GetSchema(field reflect.Type, components *ComponentMetadata) (*spec.Schema, error)
- func ValidateAgainstSchema(metadata ContractChaincodeMetadata) error
- type ComponentMetadata
- type ContactMetadata
- type ContractChaincodeMetadata
- type ContractMetadata
- type InfoMetadata
- type LicenseMetadata
- type ObjectMetadata
- type ParameterMetadata
- type ReturnMetadata
- type TransactionMetadata
Constants ¶
const MetadataFile = "metadata.json"
MetadataFile name of file metadata should be written in
const MetadataFolder = "META-INF"
MetadataFolder name of the main folder metadata should be placed in
const MetadataFolderSecondary = "contract-metadata"
MetadataFolderSecondary name of the secondary folder metadata should be placed in
Variables ¶
This section is empty.
Functions ¶
func GetJSONSchema ¶
GetJSONSchema returns the JSON schema used for metadata
func GetSchema ¶
GetSchema returns the open api spec schema for a given type. For struct types the property name used in the generated schema will be the name of the property unless a metadata or json tag exists for the property. Metadata tags take precedence over json tags. Private properties without a metadata tag will be ignored. Json tags are not used for private properties. Components will be added to component metadata if the field is a struct type. The schema will then reference this component
func ValidateAgainstSchema ¶
func ValidateAgainstSchema(metadata ContractChaincodeMetadata) error
ValidateAgainstSchema takes a ContractChaincodeMetadata and runs it against the schema that defines valid metadata structure. If it does not meet the schema it returns an error detailing why
Types ¶
type ComponentMetadata ¶
type ComponentMetadata struct {
Schemas map[string]ObjectMetadata `json:"schemas,omitempty"`
}
ComponentMetadata stores map of schemas of all components
type ContactMetadata ¶
type ContactMetadata struct { Name string `json:"name,omitempty"` URL string `json:"url,omitempty"` Email string `json:"email,omitempty"` }
ContactMetadata contains contact details about an author of a contract/chaincode
type ContractChaincodeMetadata ¶
type ContractChaincodeMetadata struct { Info *InfoMetadata `json:"info,omitempty"` Contracts map[string]ContractMetadata `json:"contracts"` Components ComponentMetadata `json:"components"` }
ContractChaincodeMetadata describes a chaincode made using the contract api
func ReadMetadataFile ¶
func ReadMetadataFile() (ContractChaincodeMetadata, error)
ReadMetadataFile return the contents of metadata file as ContractChaincodeMetadata
func (*ContractChaincodeMetadata) Append ¶
func (ccm *ContractChaincodeMetadata) Append(source ContractChaincodeMetadata)
Append merge two sets of metadata. Source value will override the original values only in fields that are not yet set i.e. when info nil, contracts nil or zero length array, components empty.
func (*ContractChaincodeMetadata) CompileSchemas ¶
func (ccm *ContractChaincodeMetadata) CompileSchemas() error
CompileSchemas compile parameter and return schemas for use by gojsonschema. When validating against the compiled schema you will need to make the comparison json have a key of the parameter name for parameters or return for return values e.g {"param1": "value"}. Compilation process resolves references to components
type ContractMetadata ¶
type ContractMetadata struct { Info *InfoMetadata `json:"info,omitempty"` Name string `json:"name"` Transactions []TransactionMetadata `json:"transactions"` Default bool `json:"default"` }
ContractMetadata contains information about what makes up a contract
type InfoMetadata ¶
type InfoMetadata struct { Description string `json:"description,omitempty"` Title string `json:"title,omitempty"` Contact *ContactMetadata `json:"contact,omitempty"` License *LicenseMetadata `json:"license,omitempty"` Version string `json:"version,omitempty"` }
InfoMetadata contains additional information to clarify use of contract/chaincode
type LicenseMetadata ¶
type LicenseMetadata struct { Name string `json:"name,omitempty"` URL string `json:"url,omitempty"` }
LicenseMetadata contains licensing information for contract/chaincode
type ObjectMetadata ¶
type ObjectMetadata struct { ID string `json:"$id"` Properties map[string]spec.Schema `json:"properties"` Required []string `json:"required"` AdditionalProperties bool `json:"additionalProperties"` }
ObjectMetadata description of a component
type ParameterMetadata ¶
type ParameterMetadata struct { Description string `json:"description,omitempty"` Name string `json:"name"` Schema *spec.Schema `json:"schema"` CompiledSchema *gojsonschema.Schema `json:"-"` }
ParameterMetadata details about a parameter used for a transaction.
type ReturnMetadata ¶
type ReturnMetadata struct { Schema *spec.Schema CompiledSchema *gojsonschema.Schema }
ReturnMetadata details about the return type for a transaction
type TransactionMetadata ¶
type TransactionMetadata struct { Parameters []ParameterMetadata `json:"parameters,omitempty"` Returns ReturnMetadata `json:"-"` Tag []string `json:"tag,omitempty"` Name string `json:"name"` }
TransactionMetadata contains information on what makes up a transaction When JSON serialized the Returns object is flattened to contain the schema
func (*TransactionMetadata) MarshalJSON ¶
func (tm *TransactionMetadata) MarshalJSON() ([]byte, error)
MarshalJSON handles converting TransactionMetadata to JSON since returns is flattened in swagger
func (*TransactionMetadata) UnmarshalJSON ¶
func (tm *TransactionMetadata) UnmarshalJSON(data []byte) error
UnmarshalJSON handles converting JSON to TransactionMetadata since returns is flattened in swagger