regolithe: go.aporeto.io/regolithe/spec Index | Files

package spec

import "go.aporeto.io/regolithe/spec"

Package spec contains the Go representation of an Regolithe Specification Set as well as various functions to handle reading and writing them.

Index

Package Files

api_info.go attribute.go config.go doc.go helpers.go interfaces.go model.go parameter.go parameter_mapping.go relation.go relationship.go relationship_action.go set.go specification.go type_mapping.go validation_mapping.go yaml.go

func Pluralize Uses

func Pluralize(word string) string

Pluralize pluralizes the given word.

type APIInfo Uses

type APIInfo struct {
    Prefix  string `yaml:"prefix,omitempty"     json:"prefix,omitempty"`
    Root    string `yaml:"root,omitempty"       json:"root,omitempty"`
    Version int    `yaml:"version,omitempty"    json:"version,omitempty"`
}

An APIInfo holds general information about the API.

func LoadAPIInfo Uses

func LoadAPIInfo(path string) (*APIInfo, error)

LoadAPIInfo loads an APIInfo from the given file.

func NewAPIInfo Uses

func NewAPIInfo() *APIInfo

NewAPIInfo returns a new APIInfo.

func (*APIInfo) Validate Uses

func (a *APIInfo) Validate() []error

Validate validates the api info against the schema.

type Attribute Uses

type Attribute struct {
    Name                string                 `yaml:"name,omitempty"                   json:"name,omitempty"`
    ExposedName         string                 `yaml:"exposed_name,omitempty"           json:"exposed_name,omitempty"`
    Description         string                 `yaml:"description,omitempty"            json:"description,omitempty"`
    Type                AttributeType          `yaml:"type,omitempty"                   json:"type,omitempty"`
    Exposed             bool                   `yaml:"exposed,omitempty"                json:"exposed,omitempty"`
    SubType             string                 `yaml:"subtype,omitempty"                json:"subtype,omitempty"`
    Stored              bool                   `yaml:"stored,omitempty"                 json:"stored,omitempty"`
    Required            bool                   `yaml:"required,omitempty"               json:"required,omitempty"`
    ReadOnly            bool                   `yaml:"read_only,omitempty"              json:"read_only,omitempty"`
    CreationOnly        bool                   `yaml:"creation_only,omitempty"          json:"creation_only,omitempty"`
    AllowedChars        string                 `yaml:"allowed_chars,omitempty"          json:"allowed_chars,omitempty"`
    AllowedCharsMessage string                 `yaml:"allowed_chars_message,omitempty"  json:"allowed_chars_message,omitempty"`
    AllowedChoices      []string               `yaml:"allowed_choices,omitempty"        json:"allowed_choices,omitempty"`
    Autogenerated       bool                   `yaml:"autogenerated,omitempty"          json:"autogenerated,omitempty"`
    DefaultOrder        bool                   `yaml:"default_order,omitempty"          json:"default_order,omitempty"`
    DefaultValue        interface{}            `yaml:"default_value,omitempty"          json:"default_value,omitempty"`
    Deprecated          bool                   `yaml:"deprecated,omitempty"             json:"deprecated,omitempty"`
    ExampleValue        interface{}            `yaml:"example_value,omitempty"          json:"example_value,omitempty"`
    Filterable          bool                   `yaml:"filterable,omitempty"             json:"filterable,omitempty"`
    ForeignKey          bool                   `yaml:"foreign_key,omitempty"            json:"foreign_key,omitempty"`
    Getter              bool                   `yaml:"getter,omitempty"                 json:"getter,omitempty"`
    Setter              bool                   `yaml:"setter,omitempty"                 json:"setter,omitempty"`
    Identifier          bool                   `yaml:"identifier,omitempty"             json:"identifier,omitempty"`
    MaxLength           uint16                 `yaml:"max_length,omitempty"             json:"max_length,omitempty"`
    MinLength           uint16                 `yaml:"min_length,omitempty"             json:"min_length,omitempty"`
    MaxValue            float64                `yaml:"max_value,omitempty"              json:"max_value,omitempty"`
    MinValue            float64                `yaml:"min_value,omitempty"              json:"min_value,omitempty"`
    Orderable           bool                   `yaml:"orderable,omitempty"              json:"orderable,omitempty"`
    PrimaryKey          bool                   `yaml:"primary_key,omitempty"            json:"primary_key,omitempty"`
    Secret              bool                   `yaml:"secret,omitempty"                 json:"secret,omitempty"`
    Transient           bool                   `yaml:"transient,omitempty"              json:"transient,omitempty"`
    OmitEmpty           bool                   `yaml:"omit_empty,omitempty"             json:"omit_empty,omitempty"`
    Encrypted           bool                   `yaml:"encrypted,omitempty"              json:"encrypted,omitempty"`
    Validations         []string               `yaml:"validations,omitempty"            json:"validations,omitempty"`
    Extensions          map[string]interface{} `yaml:"extensions,omitempty"             json:"extensions,omitempty"`

    ConvertedName       string                    `yaml:"-" json:"-"`
    ConvertedType       string                    `yaml:"-" json:"-"`
    TypeProvider        string                    `yaml:"-" json:"-"`
    Initializer         string                    `yaml:"-" json:"-"`
    ValidationProviders map[string]*ValidationMap `yaml:"-" json:"-"`
    // contains filtered or unexported fields
}

An Attribute represents a regolithe specification attribute.

func (*Attribute) Validate Uses

func (a *Attribute) Validate() []error

Validate validates the attribute definition.

type AttributeNameConverterFunc Uses

type AttributeNameConverterFunc func(name string) string

AttributeNameConverterFunc is the type of a attribute name conveter.

type AttributeType Uses

type AttributeType string

AttributeType represents the various type for an attribute.

const (
    AttributeTypeString  AttributeType = "string"
    AttributeTypeInt     AttributeType = "integer"
    AttributeTypeFloat   AttributeType = "float"
    AttributeTypeBool    AttributeType = "boolean"
    AttributeTypeEnum    AttributeType = "enum"
    AttributeTypeList    AttributeType = "list"
    AttributeTypeObject  AttributeType = "object"
    AttributeTypeTime    AttributeType = "time"
    AttributeTypeExt     AttributeType = "external"
    AttributeTypeRef     AttributeType = "ref"
    AttributeTypeRefList AttributeType = "refList"
    AttributeTypeRefMap  AttributeType = "refMap"
)

Various values for AttributeType.

type AttributeTypeConverterFunc Uses

type AttributeTypeConverterFunc func(typ AttributeType, subtype string) (converted string, provider string)

AttributeTypeConverterFunc is the type of a attribute type conveter.

type Config Uses

type Config struct {
    Author      string
    Copyright   string
    Description string
    Email       string
    Name        string
    ProductName string
    URL         string
    Version     string
    // contains filtered or unexported fields
}

Config holds the Specification Config.

func LoadConfig Uses

func LoadConfig(path string) (*Config, error)

LoadConfig loads the config from an ini file.

func NewConfig Uses

func NewConfig() *Config

NewConfig returns a new APIInfo.

func (*Config) Key Uses

func (c *Config) Key(section, key string) string

Key returns the value of the given key in the given section.

type Model Uses

type Model struct {
    RestName      string                 `yaml:"rest_name,omitempty"       json:"rest_name,omitempty"`
    ResourceName  string                 `yaml:"resource_name,omitempty"   json:"resource_name,omitempty"`
    EntityName    string                 `yaml:"entity_name,omitempty"     json:"entity_name,omitempty"`
    Package       string                 `yaml:"package,omitempty"         json:"package,omitempty"`
    Group         string                 `yaml:"group,omitempty"           json:"group,omitempty"`
    Description   string                 `yaml:"description,omitempty"     json:"description,omitempty"`
    Documentation string                 `yaml:"documentation,omitempty"   json:"documentation,omitempty"`
    Aliases       []string               `yaml:"aliases,omitempty"         json:"aliases,omitempty"`
    Private       bool                   `yaml:"private,omitempty"         json:"private,omitempty"`
    Get           *RelationAction        `yaml:"get,omitempty"             json:"get,omitempty"`
    Update        *RelationAction        `yaml:"update,omitempty"          json:"update,omitempty"`
    Delete        *RelationAction        `yaml:"delete,omitempty"          json:"delete,omitempty"`
    Extends       []string               `yaml:"extends,omitempty"         json:"extends,omitempty"`
    IsRoot        bool                   `yaml:"root,omitempty"            json:"root,omitempty"`
    Detached      bool                   `yaml:"detached,omitempty"        json:"detached,omitempty"`
    Validations   []string               `yaml:"validations,omitempty"     json:"validations,omitempty"`
    Extensions    map[string]interface{} `yaml:"extensions,omitempty"      json:"extensions,omitempty"`

    EntityNamePlural string `yaml:"-" json:"-"`
}

A Model holds generic information about a specification.

func (*Model) Validate Uses

func (m *Model) Validate() []error

Validate validates the Model.

type Parameter Uses

type Parameter struct {
    Name           string        `yaml:"name,omitempty"              json:"name,omitempty"`
    Description    string        `yaml:"description,omitempty"       json:"description,omitempty"`
    Type           ParameterType `yaml:"type,omitempty"              json:"type,omitempty"`
    Multiple       bool          `yaml:"multiple,omitempty"          json:"multiple,omitempty"`
    AllowedChoices []string      `yaml:"allowed_choices,omitempty"   json:"allowed_choices,omitempty"`
    DefaultValue   interface{}   `yaml:"default_value,omitempty"     json:"default_value,omitempty"`
    ExampleValue   interface{}   `yaml:"example_value,omitempty"     json:"example_value,omitempty"`
}

A Parameter represent one parameter that can be sent with a query

func (*Parameter) Validate Uses

func (p *Parameter) Validate(relatedReSTName string) []error

Validate validates the parameter definition.

type ParameterDefinition Uses

type ParameterDefinition struct {
    Required [][][]string `yaml:"required,omitempty"    json:"required,omitempty"`
    Entries  []*Parameter `yaml:"entries,omitempty"     json:"entries,omitempty"`
}

ParameterDefinition represents a parameter definition.

func (*ParameterDefinition) Validate Uses

func (p *ParameterDefinition) Validate(relatedReSTName string) []error

Validate validates the parameter definition.

type ParameterMapping Uses

type ParameterMapping map[string]*ParameterDefinition

A ParameterMapping is a list parameter mapping

func LoadGlobalParameters Uses

func LoadGlobalParameters(path string) (ParameterMapping, error)

LoadGlobalParameters loads the global parameters file.

func NewParameterMapping Uses

func NewParameterMapping() ParameterMapping

NewParameterMapping returns a new ParameterMapping.

func (ParameterMapping) Read Uses

func (p ParameterMapping) Read(reader io.Reader, validate bool) (err error)

Read loads a validation mapping from the given io.Reader

func (ParameterMapping) Validate Uses

func (p ParameterMapping) Validate() []error

Validate the ParameterMapping

func (ParameterMapping) Write Uses

func (p ParameterMapping) Write(writer io.Writer) error

Write dumps the specification into a []byte.

type ParameterType Uses

type ParameterType string

ParameterType represents the various type for a parameter.

const (
    ParameterTypeString   ParameterType = "string"
    ParameterTypeInt      ParameterType = "integer"
    ParameterTypeFloat    ParameterType = "float"
    ParameterTypeBool     ParameterType = "boolean"
    ParameterTypeTime     ParameterType = "time"
    ParameterTypeEnum     ParameterType = "enum"
    ParameterTypeDuration ParameterType = "duration"
)

Various values for ParameterType.

type Relation Uses

type Relation struct {
    RestName string          `yaml:"rest_name,omitempty"    json:"rest_name,omitempty"`
    Get      *RelationAction `yaml:"get,omitempty"          json:"get,omitempty"`
    Create   *RelationAction `yaml:"create,omitempty"       json:"create,omitempty"`
    Update   *RelationAction `yaml:"update,omitempty"       json:"update,omitempty"`
    Delete   *RelationAction `yaml:"delete,omitempty"       json:"delete,omitempty"`
    // contains filtered or unexported fields
}

An Relation represents a specification Relation.

func (*Relation) Specification Uses

func (r *Relation) Specification() Specification

Specification returns the Specification the API links to.

func (*Relation) Validate Uses

func (r *Relation) Validate() []error

Validate validates the relationship

type RelationAction Uses

type RelationAction struct {
    Description         string               `yaml:"description,omitempty"           json:"description,omitempty"`
    Deprecated          bool                 `yaml:"deprecated,omitempty"            json:"deprecated,omitempty"`
    ParameterReferences []string             `yaml:"global_parameters,omitempty"     json:"global_parameters,omitempty"`
    ParameterDefinition *ParameterDefinition `yaml:"parameters,omitempty"            json:"parameters,omitempty"`
}

A RelationAction represents one the the possible action

func (*RelationAction) Validate Uses

func (ra *RelationAction) Validate(currentRestName string, remoteRestName string, k string) []error

Validate validates the relation action.

type Relationship Uses

type Relationship struct {
    Create  map[string]*RelationAction
    Delete  map[string]*RelationAction
    Get     map[string]*RelationAction
    GetMany map[string]*RelationAction
    Update  map[string]*RelationAction
}

A Relationship describes the hierarchical relationship of the models.

func NewRelationship Uses

func NewRelationship() *Relationship

NewRelationship returns a new Relationship.

func (*Relationship) Set Uses

func (r *Relationship) Set(action string, name string, ra *RelationAction)

Set sets the names that are allows to do the given action.

type Specification Uses

type Specification interface {

    // Read reads and load the given reader containing a specification.
    // If validates is true, validations will be done.
    Read(reader io.Reader, validate bool) error

    // Writes write the current state of the Specification in the given
    // writer.
    Write(writer io.Writer) error

    // Validate validates the specification content.
    Validate() []error

    // ApplyBaseSpecifications applyes the given abstract specification to
    // the specification.
    ApplyBaseSpecifications(specs ...Specification) error

    // Model returns the Specification model.
    Model() *Model

    // Attribute returns the attribute with the given name in the given version.
    Attribute(name string, version string) *Attribute

    // Attributes returns all attributes for the given version.
    Attributes(version string) []*Attribute

    // ExposedAttributes returns only the exposed attributes in the given version.
    ExposedAttributes(version string) []*Attribute

    // OrderingAttributes returns the list of attributes used for ordering.
    OrderingAttributes(version string) []*Attribute

    // AttributeVersions returns all the versions of attributes.
    AttributeVersions() []string

    // LatestAttributesVersion returns the latest version of the attributes.
    LatestAttributesVersion() string

    // Relations returns the Specification relations.
    Relations() []*Relation

    // Relation returns the relation to the given restName.
    Relation(restName string) *Relation

    // Identitier returns the Attribute used as an identifier.
    Identifier() *Attribute
}

A Specification is the interface representing a Regolithe Specification.

func LoadSpecification Uses

func LoadSpecification(specPath string, validate bool) (Specification, error)

LoadSpecification returns a new specification using the given file path.

func NewSpecification Uses

func NewSpecification() Specification

NewSpecification returns a new specification.

type SpecificationSet Uses

type SpecificationSet interface {

    // Specification returns the Specification with the given name.
    Specification(name string) Specification

    // SpecificationGroup returns the Specifications in the given group name.
    SpecificationGroup(groupName string) []Specification

    // Specifications returns all Specifications.
    Specifications() (specs []Specification)

    // Len returns the number of specifications in the set.
    Len() int

    // Relationships is better
    Relationships() map[string]*Relationship

    // RelationshipsByRestName returns the relationships indexed by rest name.
    RelationshipsByRestName() map[string]*Relationship

    // RelationshipsByResourceName returns the relationships indexed by resource name.
    RelationshipsByResourceName() map[string]*Relationship

    // Configuration returns the specification set Config.
    Configuration() *Config

    // TypeMapping returns the specification set TypeMapping.
    TypeMapping() TypeMapping

    // ValidationMapping returns the specification set ValidationMapping.
    ValidationMapping() ValidationMapping

    // APIInfo returns the specification set APIInfo.
    APIInfo() *APIInfo

    // Groups returns the list of group names.
    Groups() []string
}

SpecificationSet represents an entire set of specification.

func LoadSpecificationSet Uses

func LoadSpecificationSet(
    dirname string,
    nameConvertFunc AttributeNameConverterFunc,
    typeConvertFunc AttributeTypeConverterFunc,
    typeMappingName string,
) (SpecificationSet, error)

LoadSpecificationSet loads and parses all specification in a folder.

func LoadSpecificationSetFromGithub Uses

func LoadSpecificationSetFromGithub(
    token string,
    repoURL string,
    refName string,
    internalPath string,
    nameConvertFunc AttributeNameConverterFunc,
    typeConvertFunc AttributeTypeConverterFunc,
    typeMappingName string,
) (SpecificationSet, error)

LoadSpecificationSetFromGithub loads a set of specs from github.

type TypeMap Uses

type TypeMap struct {
    Type        string `yaml:"type,omitempty"           json:"type,omitempty"`
    Initializer string `yaml:"init,omitempty"           json:"init,omitempty"`
    Import      string `yaml:"import,omitempty"         json:"import,omitempty"`
    Description string `yaml:"description,omitempty"    json:"description,omitempty"`
}

A TypeMap represent a single Type Map.

type TypeMapping Uses

type TypeMapping map[string]map[string]*TypeMap

TypeMapping holds the mapping of the external types.

func LoadTypeMapping Uses

func LoadTypeMapping(path string) (TypeMapping, error)

LoadTypeMapping loads a TypeMapping from the given ini file.

func NewTypeMapping Uses

func NewTypeMapping() TypeMapping

NewTypeMapping returns a new TypeMapping.

func (TypeMapping) All Uses

func (t TypeMapping) All(mode string) (mapping []*TypeMap)

All returns the all the TypeMap for the given mode.

func (TypeMapping) Mapping Uses

func (t TypeMapping) Mapping(mode string, externalType string) (mapping *TypeMap, err error)

Mapping returns the TypeMap for the given external type.

func (TypeMapping) Read Uses

func (t TypeMapping) Read(reader io.Reader, validate bool) (err error)

Read loads a type mapping from the given io.Reader

func (TypeMapping) Validate Uses

func (t TypeMapping) Validate() []error

Validate validates the type mappings against the schema.

func (TypeMapping) Write Uses

func (t TypeMapping) Write(writer io.Writer) error

Write dumps the specification into a []byte.

type ValidationMap Uses

type ValidationMap struct {
    Name   string `yaml:"name,omitempty"           json:"name,omitempty"`
    Import string `yaml:"import,omitempty"         json:"import,omitempty"`
}

A ValidationMap represent a single ValidationMap.

type ValidationMapping Uses

type ValidationMapping map[string]map[string]*ValidationMap

ValidationMapping holds the mapping of the validation function.

func LoadValidationMapping Uses

func LoadValidationMapping(path string) (ValidationMapping, error)

LoadValidationMapping loads a ValidationMapping from the given ini file.

func NewValidationMapping Uses

func NewValidationMapping() ValidationMapping

NewValidationMapping returns a new ValidationMapping.

func (ValidationMapping) Mapping Uses

func (v ValidationMapping) Mapping(mode string, functionName string) (mapping *ValidationMap, err error)

Mapping returns the ValidationMap for the given external type.

func (ValidationMapping) Read Uses

func (v ValidationMapping) Read(reader io.Reader, validate bool) (err error)

Read loads a validation mapping from the given io.Reader

func (ValidationMapping) Validate Uses

func (v ValidationMapping) Validate() []error

Validate validates the type mappings against the schema.

func (ValidationMapping) Write Uses

func (v ValidationMapping) Write(writer io.Writer) error

Write dumps the specification into a []byte.

Package spec imports 23 packages (graph) and is imported by 1 packages. Updated 2019-08-24. Refresh now. Tools for package owners.