model

package
v39.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2020 License: MPL-2.0 Imports: 16 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 FormatSourceAndSave

func FormatSourceAndSave(sourceFile string, sourceCode []byte)

func GenerateGodocLinkInReadme

func GenerateGodocLinkInReadme(amqpLinks string, httpLinks string)

func ReferencesServerGet

func ReferencesServerGet(path string) *json.RawMessage

func ReferencesServerUrl

func ReferencesServerUrl(path string) string

func StartReferencesServer

func StartReferencesServer() error

Types

type API

type API struct {
	*APIReferenceFile
	// contains filtered or unexported fields
}

API represents the HTTP interface of a Taskcluster service

func (*API) Name

func (api *API) Name() string

func (*API) String

func (api *API) String() string

type APIDefinition

type APIDefinition struct {
	URL     string `json:"url"`
	DocRoot string `json:"docroot"`
	Data    APIModel

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

APIDefinition represents the definition of an API (currently a REST API or an AMQP 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

type APIDefinitions

type APIDefinitions []*APIDefinition

func LoadAPIs

func LoadAPIs() APIDefinitions

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.

func (APIDefinitions) GenerateCode

func (apiDefs APIDefinitions) GenerateCode(goOutputDir string)

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

type APIEntry

type APIEntry struct {
	*Entry
	MethodName string
	Parent     *API
	InputURL   string
	OutputURL  string
}

APIEntry represents an individual HTTP API call of a Taskcluster service

func (*APIEntry) String

func (entry *APIEntry) String() string

type APIModel

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

APIModel represents an abstract structured model of an API Currently there are two implementations - HTTP APIs and AMQP APIs.

type APIReferenceFile

type APIReferenceFile struct {

	// Link to schema for this reference. That is a link to this very document. Typically used to identify what kind of reference this file is.
	Schema string `json:"$schema"`

	// Version of the API
	//
	// Syntax:     ^v[0-9]+$
	APIVersion string `json:"apiVersion"`

	// API description in markdown
	Description string `json:"description"`

	// Array of methods in this reference
	Entries []APIEntry `json:"entries"`

	// Name of service for automation. Will be consumed by client generators to produce URLs
	//
	// Syntax:     ^[a-z][a-z0-9_-]*$
	// Min length: 1
	// Max length: 22
	ServiceName string `json:"serviceName"`

	// API title in markdown
	Title string `json:"title"`
}

Reference of methods implemented by API

type Blob

type Blob string

Output kind if not JSON matching a specific schema.

Possible values:

  • "blob"

type Conditional

type Conditional struct {

	// One of:
	//   * RequiredScope
	//   * Disjunction
	//   * Conjunction
	//   * Conditional
	//   * ForAll
	Else ScopeExpressionTemplate `json:"else,omitempty"`

	// Syntax:     ^[a-zA-Z][a-zA-Z0-9_]*$
	If string `json:"if"`

	// One of:
	//   * RequiredScope
	//   * Disjunction
	//   * Conjunction
	//   * Conditional
	//   * ForAll
	Then ScopeExpressionTemplate `json:"then"`
}

if/then objects will replace themselves with the contents of then if the `if` is true

func (*Conditional) String

func (ifThen *Conditional) String() string

type Conjunction

type Conjunction struct {

	// Array items:
	// One of:
	//   * RequiredScope
	//   * Disjunction
	//   * Conjunction
	//   * Conditional
	//   * ForAll
	AllOf []ScopeExpressionTemplate `json:"AllOf"`
}

AllOf objects will evaluate to true if all subexpressions are true

func (*Conjunction) String

func (allOf *Conjunction) String() string

type Disjunction

type Disjunction struct {

	// Array items:
	// One of:
	//   * RequiredScope
	//   * Disjunction
	//   * Conjunction
	//   * Conditional
	//   * ForAll
	AnyOf []ScopeExpressionTemplate `json:"AnyOf"`
}

AnyOf objects will evaluate to true if any subexpressions are true

func (*Disjunction) String

func (anyOf *Disjunction) String() string

type Entry

type Entry struct {

	// Arguments from `route` that must be replaced, they'll appear wrapped in brackets inside `route`.
	//
	// Array items:
	// Argument that appears in `route` warpped in angle brackets. It must be replaced to call the function.
	Args []string `json:"args"`

	// Category for the API method
	Category string `json:"category"`

	// Description (ie. documentation) for the API entry
	Description string `json:"description"`

	// JSON schema for input, if input is validated, otherwise not present. The value must be a relative URI, based on the service's schema location; that is, based at `<rootUrl>/schemas/<serviceName`.
	Input string `json:"input,omitempty"`

	// HTTP method (verb) used to access the function
	//
	// Possible values:
	//   * "get"
	//   * "post"
	//   * "put"
	//   * "head"
	//   * "delete"
	//   * "options"
	//   * "trace"
	//   * "copy"
	//   * "lock"
	//   * "mkcol"
	//   * "move"
	//   * "purge"
	//   * "propfind"
	//   * "proppatch"
	//   * "unlock"
	//   * "report"
	//   * "mkactivity"
	//   * "checkout"
	//   * "merge"
	//   * "m-search"
	//   * "notify"
	//   * "subscribe"
	//   * "unsubscribe"
	//   * "patch"
	//   * "search"
	Method string `json:"method"`

	// Name of the `function` this is a stable identifier for use in auto-generated client libraries
	Name string `json:"name"`

	// One of:
	//   * OutputSchema
	//   * Blob
	Output string `json:"output,omitempty"`

	// List of accepted query-string parameters, these are always optional.
	//
	// Array items:
	// Optional query-string parameter
	Query []string `json:"query,omitempty"`

	// Route for the call, note that arguments wrapped with brackets, like `/user/<userId>/` must be replaced.
	Route string `json:"route"`

	// Scope expression template specifying required scopes for a method. Not provided if authentication isn't required.
	//
	// One of:
	//   * RequiredScope
	//   * Disjunction
	//   * Conjunction
	//   * Conditional
	Scopes ScopeExpressionTemplate `json:"scopes,omitempty"`

	// Stability level of the API
	//
	// Possible values:
	//   * "deprecated"
	//   * "experimental"
	//   * "stable"
	Stability string `json:"stability"`

	// Title of API entry
	Title string `json:"title"`

	// Type of entry, currently only `function`.
	//
	// Possible values:
	//   * "function"
	Type string `json:"type"`
}

type Exchange

type Exchange struct {
	Schema         string          `json:"$schema"`
	APIVersion     interface{}     `json:"apiVersion"`
	Description    string          `json:"description"`
	Entries        []ExchangeEntry `json:"entries"`
	ExchangePrefix string          `json:"exchangePrefix"`
	ServiceName    string          `json:"serviceName"`
	Title          string          `json:"title"`
	// contains filtered or unexported fields
}

Exchange represents the set of AMQP interfaces for a Taskcluster service

func (*Exchange) Name

func (exchange *Exchange) Name() string

func (*Exchange) String

func (exchange *Exchange) String() string

type ExchangeEntry

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

	Parent *Exchange
	// contains filtered or unexported fields
}

ExchangeEntry represents a single AMQP interface of a Taskcluster service

func (*ExchangeEntry) String

func (entry *ExchangeEntry) String() string

type ExchangeReferenceFile

type ExchangeReferenceFile struct {

	// Link to schema for this reference. That is a link to this very document. Typically used to identify what kind of reference this file is.
	Schema string `json:"$schema"`

	// Version of the API
	//
	// Syntax:     ^v[0-9]+$
	APIVersion string `json:"apiVersion"`

	// Description of set of exchanges in markdown
	Description string `json:"description"`

	Entries []Var `json:"entries"`

	// Prefix for all exchanges described in this document
	ExchangePrefix string `json:"exchangePrefix"`

	// Name of service for automation. Will be consumed by client generators to produce URLs
	//
	// Syntax:     ^[a-z][a-z0-9_-]*$
	// Min length: 1
	// Max length: 22
	ServiceName string `json:"serviceName"`

	// Title for set of exchanges in markdown
	Title string `json:"title"`
}

Reference of exchanges published

type ForAll

type ForAll struct {

	// Syntax:     ^[\x20-\x7e]*$
	Each string `json:"each"`

	// Syntax:     ^[a-zA-Z][a-zA-Z0-9_]*$
	For string `json:"for"`

	// Syntax:     ^[a-zA-Z][a-zA-Z0-9_]*$
	In string `json:"in"`
}

for/each/in objects will replace themselves with an array of basic scopes. They will be flattened into the array this object is a part of.

func (*ForAll) String

func (forEachIn *ForAll) String() string

type OutputSchema

type OutputSchema string

JSON schema for output, if output is validated, otherwise not present. The value must be a relative URI, based on the service's schema location; that is, based at `<rootUrl>/schemas/<serviceName`.

type ReferencesFile

type ReferencesFile []ReferencesFileEntry

type ReferencesFileEntry

type ReferencesFileEntry struct {
	Content  json.RawMessage `json:"content"`
	Filename string          `json:"filename"`
}

type RequiredScope

type RequiredScope string

The most basic element of a scope expression

Syntax: ^[\x20-\x7e]*$

func (*RequiredScope) String

func (rs *RequiredScope) String() string

type RouteElement

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

RouteElement represents an element of am AMQP routing key

func (*RouteElement) String

func (re *RouteElement) String() string

type ScopeExpressionTemplate

type ScopeExpressionTemplate struct {
	RawMessage json.RawMessage
	// One of:
	//   * "AllOf"
	//   * "AnyOf"
	//   * "ForEachIn"
	//   * "IfThen"
	//   * "RequiredScope"
	Type          string
	AllOf         *Conjunction
	AnyOf         *Disjunction
	ForEachIn     *ForAll
	IfThen        *Conditional
	RequiredScope *RequiredScope
}

See https://schemas.taskcluster.net/base/v1/api-reference.json#/definitions/scopeExpressionTemplate

func (*ScopeExpressionTemplate) MarshalJSON

func (this *ScopeExpressionTemplate) MarshalJSON() ([]byte, error)

MarshalJSON calls json.RawMessage method of the same name. Required since ScopeExpressionTemplate is of type json.RawMessage...

func (*ScopeExpressionTemplate) String

func (scopes *ScopeExpressionTemplate) String() string

func (*ScopeExpressionTemplate) UnmarshalJSON

func (this *ScopeExpressionTemplate) UnmarshalJSON(data []byte) error

UnmarshalJSON identifies the data structure at runtime, and unmarshals in the appropriate type

type SortedAPIDefs

type SortedAPIDefs []*APIDefinition

SortedAPIDefs is a sorted array of APIDefinitions

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)

type TaskclusterServiceManifest

type TaskclusterServiceManifest struct {

	// Array of URLs of reference documents
	//
	// Array items:
	References []string `json:"references"`
}

Manifest of taskcluster service definitions available in a taskcluster service deployment. These manifests are served from `$ROOT_URL/references/manifest.json`.

type Var

type Var struct {

	// Description (ie. documentation) for the exchange
	Description string `json:"description"`

	// Exchange name on AMQP server, must be prefixed with `exchangePrefix` from this document.
	Exchange string `json:"exchange"`

	// Name of exchange, this is a stable identifier for use in auto-generated client libraries
	Name string `json:"name"`

	RoutingKey []Var1 `json:"routingKey"`

	// JSON schema for messages on this exchange. The value must be a relative URI, based on the service's schema location; that is, based at `<rootUrl>/schemas/<serviceName>`.
	Schema string `json:"schema"`

	// Title of exchange entry
	Title string `json:"title"`

	// Type of entry, currently only `topic-exchange`.
	//
	// Constant value: "topic-exchange"
	Type string `json:"type"`
}

type Var1

type Var1 struct {

	// Constant to be used for this field, cannot be overwritten, only present if applicable.
	Constant string `json:"constant,omitempty"`

	// True, if key may contain dots, which AMQP will consider as words. This determines if `#` or `*` should be used in client libraries
	MultipleWords bool `json:"multipleWords"`

	// Identifier usable in client libraries
	Name string `json:"name"`

	// True, if the key is always present, if `false` the value `_` will be used in place when no appropriate value is available for the key.
	Required bool `json:"required"`

	// Short description of key in markdown
	Summary string `json:"summary"`
}

Jump to

Keyboard shortcuts

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