Documentation ¶
Index ¶
- Constants
- Variables
- func Compare(v1 string, comparator Comparator, v2 string) (bool, error)
- func ExtractSchemaAuthorDID(schemaID string) (did.DID, error)
- func ExtractSchemaResourceID(schemaID string) (string, error)
- func IDIsInVersionRange(schemaID string, versionRange string) (bool, error)
- func InRangeInclusive(version string, lower string, upper string) (bool, error)
- func IsJSON(str string) bool
- func Validate(schema, document string) error
- func ValidateCredential(credentialSubjectSchema, documentJSON string) error
- func ValidateJSONSchema(maybeSchema ledger.JSONSchemaMap) error
- func ValidateJSONSchemaString(maybeSchema string) error
- func ValidateLedgerSchemaV1(document interface{}) error
- func ValidateSchemaRequest(document interface{}, version string) error
- func ValidateWithJSONLoader(schemaLoader, documentLoader gojsonschema.JSONLoader) error
- type ArrayType
- type Attribute
- type AttributeType
- type Builder
- type Comparator
- type FormatType
- type IDFormatErr
- type InvalidSchemaError
- type NumberType
- type ObjectType
- type Range
- type RangeBounded
- type StringType
- type UnRecognisedRangeError
- type UnRecognisedVersionError
- type UpdateInput
- type UpdateResult
- type Validator
- type Version
- type VersionInfo
Constants ¶
const ( Draft7 = "http://json-schema.org/draft-07/schema#" Type = "object" )
const ( VersionRxStr = `^[0-9]+\.[0-9]+$` VersionPathResource = "version" ResourceIDPathResource = "id" FragSep = ";" FragAssignment = "=" )
Variables ¶
var Version0 = VersionInfo{ Version: "0.0", ValidRangeLower: "0.0", ValidRangeUpper: "0.0", Description: "Supports JSON Objects for Metadata and Schema Definitions, both validated against JSON schemas", Validator: V0, }
var Version1 = VersionInfo{ Version: "1.0", ValidRangeLower: "1.0", ValidRangeUpper: "1.0", Description: "Supports JSON Objects for Metadata and Schema Definitions, both validated against JSON schemas", Validator: V1, }
Functions ¶
func Compare ¶
func Compare(v1 string, comparator Comparator, v2 string) (bool, error)
Compare allows the comparison of two semantic versions with a given comparator defined by the Comparator enumeration
func ExtractSchemaAuthorDID ¶
ExtractSchemaAuthorDID parses the schema URI (did:work:<authorDID>;id=<uuid>;version=<version>) and returns the author's DID.
func ExtractSchemaResourceID ¶
ExtractSchemaResourceID parses the schema URI (did:work:<authorDID>;id=<uuid>;version=<version>) and returns the resource ID.
func IDIsInVersionRange ¶
IDIsInVersionRange checks if the schema version falls within the given range. Returns an error if either the schema ID or range cannot be parsed.
func InRangeInclusive ¶
InRangeInclusive determines whether the provided version is in the inclusive range of the provided version bounds
func Validate ¶
Validate exists to hide gojsonschema logic within this file it is the entry-point to validation logic, requiring the caller pass in valid json strings for each argument
func ValidateCredential ¶
Validate a credential's data is valid against its schema
func ValidateJSONSchema ¶
func ValidateJSONSchema(maybeSchema ledger.JSONSchemaMap) error
ValidateJSONSchema takes in a map that is purported to be a JSON schema (schema definition) An error is returned if it is not a valid JSON schema, and nil is returned on success
func ValidateJSONSchemaString ¶
ValidateJSONSchema takes in a string that is purported to be a JSON schema (schema definition) An error is returned if it is not a valid JSON schema, and nil is returned on success
func ValidateLedgerSchemaV1 ¶
func ValidateLedgerSchemaV1(document interface{}) error
func ValidateSchemaRequest ¶
Validates a schema by finding the right validation method according to the version It is possible that multiple validation methods would be supported for a given version, so we always choose the validation method created last (heavy assumption here that the versions we track are properly ordered).
func ValidateWithJSONLoader ¶
func ValidateWithJSONLoader(schemaLoader, documentLoader gojsonschema.JSONLoader) error
Validate takes schema and document loaders; the document from the loader is validated against the schema from the loader. Nil if good, error if bad
Types ¶
type ArrayType ¶
type ArrayType struct { AttributeType `json:"type" validate:"required"` *StringType *NumberType }
TODO add support for arrays of objects and arrays
type Attribute ¶
type Attribute struct { Name string `json:"-" validate:"required"` Type AttributeType `json:"type,omitempty" validate:"required"` Required bool `json:"-" validate:"required"` *StringType *NumberType *ObjectType *ArrayType }
type AttributeType ¶
type AttributeType string
const ( String AttributeType = "string" Number AttributeType = "number" Object AttributeType = "object" Array AttributeType = "array" Boolean AttributeType = "boolean" )
type Builder ¶
type Comparator ¶
type Comparator int
const ( LessThan Comparator = iota LessThanOrEqualTo GreaterThan GreaterThanOrEqualTo Equals )
type FormatType ¶
type FormatType string
const ( Date FormatType = "date" Time FormatType = "time" DateTime FormatType = "date-time" Email FormatType = "email" )
type IDFormatErr ¶
type IDFormatErr struct {
// contains filtered or unexported fields
}
IDFormatErr is a formatting error in the Schema ID, which should be in the form <author_did>;id=<uuid>;version=<major.minor>.
func (IDFormatErr) Error ¶
func (e IDFormatErr) Error() string
type InvalidSchemaError ¶
type InvalidSchemaError struct {
Errors []string
}
func (InvalidSchemaError) Error ¶
func (err InvalidSchemaError) Error() string
type NumberType ¶
type ObjectType ¶
type Range ¶
type Range struct { MajorRange RangeBounded MinorRange RangeBounded }
Note uses Prefix range https://docs.gradle.org/current/userguide/single_versions.html
func RangeFromStr ¶
RangeFromStr parses a string into a Range object. Returns an error if the string does not match any of the following:
1) Exact match. This looks like a version string. For example, "1.0" is a range that only matches version "1.0".
2) Major range. This looks like a carrot "^" prefixed to a version. For example, "^2.1" matches everything greater than or equal to a particular version ("2.1") in the same major range ("2.x").
3) Wild minor. This looks like a version string where the minor version has been replaced with either an "x" or an "*". This is equivalent to Major range with minor version "0". For example, "3.x" is includes everything with a major version of "3".
4) Wild. This is either "x" or "*". This matches any version.
func (Range) FallsInRange ¶
FallsInRange returns true if the given version falls within this Range.
type RangeBounded ¶
type StringType ¶
type StringType struct {
Format FormatType `json:"format,omitempty"`
}
type UnRecognisedRangeError ¶
type UnRecognisedRangeError struct {
// contains filtered or unexported fields
}
UnRecognisedRangeError is returned when encountering an invalid range string.
func (UnRecognisedRangeError) Error ¶
func (e UnRecognisedRangeError) Error() string
type UnRecognisedVersionError ¶
type UnRecognisedVersionError struct {
// contains filtered or unexported fields
}
UnRecognisedVersionError is a formatting error in the Schema version, which should be in the form "major.minor".
func (UnRecognisedVersionError) Error ¶
func (e UnRecognisedVersionError) Error() string
type UpdateInput ¶
type UpdateResult ¶
type UpdateResult struct { Valid bool MajorChange bool MinorChange bool DerivedVersion string Message string }
func ValidateSchemaUpdate ¶
func ValidateSchemaUpdate(schemaUpdateInput *UpdateInput) (*UpdateResult, error)
ValidateSchemaUpdate compares two schemas using schemaver rules and returns a summary of the update, which includes whether it's a major or minor change and a proposed version for the schema update.
type Validator ¶
type Validator int
func FindValidatorForVersion ¶
Find the most recently created validator the supports the provided version
type Version ¶
wrapper around modified semantic version where only major and minor numbers are valid
func ExtractSchemaVersionFromID ¶
ExtractSchemaVersionFromID parses the schema URI (did:work:<authorDID>;id=<uuid>;version=<version>) and returns the schema version.
func VersionFromStr ¶
VersionFromStr parses a version string into a Version object. Returns an error if the version string does not match the VersionRxStr regular expression, i.e. "<major>.<minor>", where major and minor are integers.