metadata

package
v1.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 11, 2020 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const MetadataFile = "metadata.json"

MetadataFile name of file metadata should be written in

View Source
const MetadataFolder = "contract-metadata"

MetadataFolder name of folder metadata should be placed in

Variables

This section is empty.

Functions

func GetJSONSchema

func GetJSONSchema() ([]byte, error)

GetJSONSchema returns the JSON schema used for metadata

func GetSchema

func GetSchema(field reflect.Type, components *ComponentMetadata) (*spec.Schema, error)

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

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL