model

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2015 License: MPL-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package model contains the core logic of the code generation process.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateCode

func GenerateCode(goOutputDir, modelData string)

GenerateCode takes the objects loaded into memory in LoadAPIs and writes them out as go code.

Types

type API

type API struct {
	Version     interface{} `json:"version"`
	Title       string      `json:"title"`
	Description string      `json:"description"`
	BaseURL     string      `json:"baseUrl"`
	Entries     []APIEntry  `json:"entries"`
	// contains filtered or unexported fields
}

func (*API) String

func (api *API) String() string

type APIDefinition

type APIDefinition struct {
	URL       string `json:"url"`
	SchemaURL string `json:"schema"`
	Name      string `json:"name"`
	DocRoot   string `json:"docroot"`
	Data      APIModel

	PackageName string
	PackagePath string
	// contains filtered or unexported fields
}

APIDefinition represents the definition of a REST API, comprising of the URL to the defintion of the API in json format, together with a URL to a json schema to validate the definition

func LoadAPIs

func LoadAPIs(apiManifestUrl, supplementaryDataFile string) []APIDefinition

LoadAPIs takes care of reading all json files and performing elementary processing of the data, such as assigning unique type names to entities which will be translated to go types.

Data is unmarshaled into objects (or instances of go types) and then postPopulate is called on the objects. This in turn triggers further reading of json files and unmarshalling where schemas refer to other schemas.

When LoadAPIs returns, all json schemas and sub schemas should have been read and unmarhsalled into go objects.

type APIEntry

type APIEntry struct {
	Type        string     `json:"type"`
	Method      string     `json:"method"`
	Route       string     `json:"route"`
	Args        []string   `json:"args"`
	Name        string     `json:"name"`
	Scopes      [][]string `json:"scopes"`
	Input       string     `json:"input"`
	Output      string     `json:"output"`
	Title       string     `json:"title"`
	Description string     `json:"description"`

	MethodName string
	Parent     *API
}

func (*APIEntry) String

func (entry *APIEntry) String() string

type APIModel

type APIModel interface {
	String() string
	// contains filtered or unexported methods
}

type AdditionalProperties

type AdditionalProperties struct {
	Boolean    *bool
	Properties *JsonSubSchema
}

func (AdditionalProperties) String

func (aP AdditionalProperties) String() string

func (*AdditionalProperties) UnmarshalJSON

func (aP *AdditionalProperties) UnmarshalJSON(bytes []byte) (err error)

type CanPopulate

type CanPopulate interface {
	// contains filtered or unexported methods
}

type Exchange

type Exchange struct {
	Version        interface{}     `json:"version"`
	Title          string          `json:"title"`
	Description    string          `json:"description"`
	ExchangePrefix string          `json:"exchangePrefix"`
	Entries        []ExchangeEntry `json:"entries"`
	// contains filtered or unexported fields
}

func (*Exchange) String

func (exchange *Exchange) String() string

type ExchangeEntry

type ExchangeEntry struct {
	Type        string         `json:"type"`
	Exchange    string         `json:"exchange"`
	Name        string         `json:"name"`
	Title       string         `json:"title"`
	Description string         `json:"description"`
	RoutingKey  []RouteElement `json:"routingKey"`
	Schema      string         `json:"schema"`

	Parent  *Exchange
	Payload *JsonSubSchema
}

func (*ExchangeEntry) String

func (entry *ExchangeEntry) String() string

type Items

type Items []JsonSubSchema

func (Items) String

func (items Items) String() string

type JsonSubSchema

type JsonSubSchema struct {
	AdditionalItems      *bool                 `json:"additionalItems"`
	AdditionalProperties *AdditionalProperties `json:"additionalProperties"`
	AllOf                Items                 `json:"allOf"`
	AnyOf                Items                 `json:"anyOf"`
	Default              interface{}           `json:"default"`
	Description          *string               `json:"description"`
	Enum                 interface{}           `json:"enum"`
	Format               *string               `json:"format"`
	ID                   *string               `json:"id"`
	Items                *JsonSubSchema        `json:"items"`
	Maximum              *int                  `json:"maximum"`
	MaxLength            *int                  `json:"maxLength"`
	Minimum              *int                  `json:"minimum"`
	MinLength            *int                  `json:"minLength"`
	OneOf                Items                 `json:"oneOf"`
	Pattern              *string               `json:"pattern"`
	Properties           *Properties           `json:"properties"`
	Ref                  *string               `json:"$ref"`
	Required             []string              `json:"required"`
	Schema               *string               `json:"$schema"`
	Title                *string               `json:"title"`
	Type                 *string               `json:"type"`

	// non-json fields used for sorting/tracking
	TypeName       string
	IsInputSchema  bool
	IsOutputSchema bool
	SourceURL      string
	RefSubSchema   *JsonSubSchema
	APIDefinition  *APIDefinition
}

Note that all members are backed by pointers, so that nil value can signify non-existence. Otherwise we could not differentiate whether a zero value is non-existence or actually the zero value. For example, if a bool is false, we don't know if it was explictly set to false in the json we read, or whether it was not given. Unmarshaling into a pointer means pointer will be nil pointer if it wasn't read, or a pointer to true/false if it was read from json.

func (JsonSubSchema) String

func (subSchema JsonSubSchema) String() string

func (*JsonSubSchema) TypeDefinition

func (jsonSubSchema *JsonSubSchema) TypeDefinition(level int, fromArray bool, extraPackages map[string]bool) (string, map[string]bool, string)

type Properties

type Properties struct {
	Properties          map[string]*JsonSubSchema
	SortedPropertyNames []string
}

func (Properties) String

func (p Properties) String() string

func (*Properties) UnmarshalJSON

func (p *Properties) UnmarshalJSON(bytes []byte) (err error)

type RouteElement

type RouteElement struct {
	Name          string `json:"name"`
	Summary       string `json:"summary"`
	Constant      string `json:"constant"`
	MultipleWords bool   `json:"multipleWords"`
	Required      bool   `json:"required"`
}

func (*RouteElement) String

func (re *RouteElement) String() string

type SortedAPIDefs

type SortedAPIDefs []APIDefinition

func (SortedAPIDefs) Len

func (a SortedAPIDefs) Len() int

needed so that SortedAPIDefs can implement sort.Interface

func (SortedAPIDefs) Less

func (a SortedAPIDefs) Less(i, j int) bool

func (SortedAPIDefs) Swap

func (a SortedAPIDefs) Swap(i, j int)

Jump to

Keyboard shortcuts

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