Documentation ¶
Overview ¶
Package model contains the core logic of the code generation process.
Index ¶
- func FormatSourceAndSave(sourceFile string, sourceCode []byte)
- type API
- type APIDefinition
- type APIDefinitions
- type APIEntry
- type APIModel
- type APIReferenceFile
- type Blob
- type Conditional
- type Conjunction
- type Disjunction
- type Entry
- type Exchange
- type ExchangeEntry
- type ExchangeReferenceFile
- type ForAll
- type OutputSchema
- type RequiredScope
- type RouteElement
- type ScopeExpressionTemplate
- type SortedAPIDefs
- type TaskclusterServiceManifest
- type Var
- type Var1
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FormatSourceAndSave ¶
Types ¶
type API ¶
type API struct { *APIReferenceFile // contains filtered or unexported fields }
API represents the HTTP interface of a Taskcluster service
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(rootURL string) 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, modelData string, downloaded time.Time)
GenerateCode takes the objects loaded into memory in LoadAPIs and writes them out as go code.
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. // // See https://taskcluster-staging.net/schemas/common/api-reference-v0.json#/properties/$schema Schema string `json:"$schema"` // Version of the API // // Syntax: ^v[0-9]+$ // // See https://taskcluster-staging.net/schemas/common/api-reference-v0.json#/properties/apiVersion APIVersion string `json:"apiVersion"` // API description in markdown // // See https://taskcluster-staging.net/schemas/common/api-reference-v0.json#/properties/description Description string `json:"description"` // Array of methods in this reference // // See https://taskcluster-staging.net/schemas/common/api-reference-v0.json#/properties/entries 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 // // See https://taskcluster-staging.net/schemas/common/api-reference-v0.json#/properties/serviceName ServiceName string `json:"serviceName"` // API title in markdown // // See https://taskcluster-staging.net/schemas/common/api-reference-v0.json#/properties/title Title string `json:"title"` }
Reference of methods implemented by API
See https://taskcluster-staging.net/schemas/common/api-reference-v0.json#
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 // // See https://taskcluster-staging.net/schemas/common/api-reference-v0.json#/definitions/scopeExpressionTemplate Else ScopeExpressionTemplate `json:"else,omitempty"` // Syntax: ^[a-zA-Z][a-zA-Z0-9_]*$ // // See https://taskcluster-staging.net/schemas/common/api-reference-v0.json#/definitions/scopeExpressionTemplateIf/properties/if If string `json:"if"` // One of: // * RequiredScope // * Disjunction // * Conjunction // * Conditional // * ForAll // // See https://taskcluster-staging.net/schemas/common/api-reference-v0.json#/definitions/scopeExpressionTemplate 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 // // See https://taskcluster-staging.net/schemas/common/api-reference-v0.json#/definitions/scopeExpressionTemplate // // See https://taskcluster-staging.net/schemas/common/api-reference-v0.json#/definitions/scopeExpressionTemplateAllOf/properties/AllOf 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 // // See https://taskcluster-staging.net/schemas/common/api-reference-v0.json#/definitions/scopeExpressionTemplate // // See https://taskcluster-staging.net/schemas/common/api-reference-v0.json#/definitions/scopeExpressionTemplateAnyOf/properties/AnyOf 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. // // See https://taskcluster-staging.net/schemas/common/api-reference-v0.json#/properties/entries/items/properties/args/items // // See https://taskcluster-staging.net/schemas/common/api-reference-v0.json#/properties/entries/items/properties/args Args []string `json:"args"` // Description (ie. documentation) for the API entry // // See https://taskcluster-staging.net/schemas/common/api-reference-v0.json#/properties/entries/items/properties/description 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`. // // See https://taskcluster-staging.net/schemas/common/api-reference-v0.json#/properties/entries/items/properties/input 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" // // See https://taskcluster-staging.net/schemas/common/api-reference-v0.json#/properties/entries/items/properties/method Method string `json:"method"` // Name of the `function` this is a stable identifier for use in auto-generated client libraries // // See https://taskcluster-staging.net/schemas/common/api-reference-v0.json#/properties/entries/items/properties/name Name string `json:"name"` // One of: // * OutputSchema // * Blob // // See https://taskcluster-staging.net/schemas/common/api-reference-v0.json#/properties/entries/items/properties/output Output string `json:"output,omitempty"` // List of accepted query-string parameters, these are always optional. // // Array items: // Optional query-string parameter // // See https://taskcluster-staging.net/schemas/common/api-reference-v0.json#/properties/entries/items/properties/query/items // // See https://taskcluster-staging.net/schemas/common/api-reference-v0.json#/properties/entries/items/properties/query Query []string `json:"query,omitempty"` // Route for the call, note that arguments wrapped with brackets, like `/user/<userId>/` must be replaced. // // See https://taskcluster-staging.net/schemas/common/api-reference-v0.json#/properties/entries/items/properties/route 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 // // See https://taskcluster-staging.net/schemas/common/api-reference-v0.json#/properties/entries/items/properties/scopes Scopes ScopeExpressionTemplate `json:"scopes,omitempty"` // Stability level of the API // // Possible values: // * "deprecated" // * "experimental" // * "stable" // // See https://taskcluster-staging.net/schemas/common/api-reference-v0.json#/properties/entries/items/properties/stability Stability string `json:"stability"` // Title of API entry // // See https://taskcluster-staging.net/schemas/common/api-reference-v0.json#/properties/entries/items/properties/title Title string `json:"title"` // Type of entry, currently only `function`. // // Possible values: // * "function" // // See https://taskcluster-staging.net/schemas/common/api-reference-v0.json#/properties/entries/items/properties/type Type string `json:"type"` }
See https://taskcluster-staging.net/schemas/common/api-reference-v0.json#/properties/entries/items
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
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. // // See https://taskcluster-staging.net/schemas/common/exchanges-reference-v0.json#/properties/$schema Schema string `json:"$schema"` // Version of the API // // Syntax: ^v[0-9]+$ // // See https://taskcluster-staging.net/schemas/common/exchanges-reference-v0.json#/properties/apiVersion APIVersion string `json:"apiVersion"` // Description of set of exchanges in markdown // // See https://taskcluster-staging.net/schemas/common/exchanges-reference-v0.json#/properties/description Description string `json:"description"` // See https://taskcluster-staging.net/schemas/common/exchanges-reference-v0.json#/properties/entries Entries []Var `json:"entries"` // Prefix for all exchanges described in this document // // See https://taskcluster-staging.net/schemas/common/exchanges-reference-v0.json#/properties/exchangePrefix 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 // // See https://taskcluster-staging.net/schemas/common/exchanges-reference-v0.json#/properties/serviceName ServiceName string `json:"serviceName"` // Title for set of exchanges in markdown // // See https://taskcluster-staging.net/schemas/common/exchanges-reference-v0.json#/properties/title Title string `json:"title"` }
Reference of exchanges published
See https://taskcluster-staging.net/schemas/common/exchanges-reference-v0.json#
type ForAll ¶
type ForAll struct { // Syntax: ^[\x20-\x7e]*$ // // See https://taskcluster-staging.net/schemas/common/api-reference-v0.json#/definitions/scopeExpressionTemplate/oneOf[4]/properties/each Each string `json:"each"` // Syntax: ^[a-zA-Z][a-zA-Z0-9_]*$ // // See https://taskcluster-staging.net/schemas/common/api-reference-v0.json#/definitions/scopeExpressionTemplate/oneOf[4]/properties/for For string `json:"for"` // Syntax: ^[a-zA-Z][a-zA-Z0-9_]*$ // // See https://taskcluster-staging.net/schemas/common/api-reference-v0.json#/definitions/scopeExpressionTemplate/oneOf[4]/properties/in 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.
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 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: // See https://taskcluster-staging.net/schemas/common/manifest-v3.json#/properties/references/items // // See https://taskcluster-staging.net/schemas/common/manifest-v3.json#/properties/references 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`.
See https://taskcluster-staging.net/schemas/common/manifest-v3.json#
type Var ¶
type Var struct { // Description (ie. documentation) for the exchange // // See https://taskcluster-staging.net/schemas/common/exchanges-reference-v0.json#/properties/entries/items/properties/description Description string `json:"description"` // Exchange name on AMQP server, must be prefixed with `exchangePrefix` from this document. // // See https://taskcluster-staging.net/schemas/common/exchanges-reference-v0.json#/properties/entries/items/properties/exchange Exchange string `json:"exchange"` // Name of exchange, this is a stable identifier for use in auto-generated client libraries // // See https://taskcluster-staging.net/schemas/common/exchanges-reference-v0.json#/properties/entries/items/properties/name Name string `json:"name"` // See https://taskcluster-staging.net/schemas/common/exchanges-reference-v0.json#/properties/entries/items/properties/routingKey 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>`. // // See https://taskcluster-staging.net/schemas/common/exchanges-reference-v0.json#/properties/entries/items/properties/schema Schema string `json:"schema"` // Title of exchange entry // // See https://taskcluster-staging.net/schemas/common/exchanges-reference-v0.json#/properties/entries/items/properties/title Title string `json:"title"` // Type of entry, currently only `topic-exchange`. // // Constant value: "topic-exchange" // // See https://taskcluster-staging.net/schemas/common/exchanges-reference-v0.json#/properties/entries/items/properties/type Type string `json:"type"` }
See https://taskcluster-staging.net/schemas/common/exchanges-reference-v0.json#/properties/entries/items
type Var1 ¶
type Var1 struct { // Constant to be used for this field, cannot be overwritten, only present if applicable. // // See https://taskcluster-staging.net/schemas/common/exchanges-reference-v0.json#/properties/entries/items/properties/routingKey/items/properties/constant 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 // // See https://taskcluster-staging.net/schemas/common/exchanges-reference-v0.json#/properties/entries/items/properties/routingKey/items/properties/multipleWords MultipleWords bool `json:"multipleWords"` // Identifier usable in client libraries // // See https://taskcluster-staging.net/schemas/common/exchanges-reference-v0.json#/properties/entries/items/properties/routingKey/items/properties/name 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. // // See https://taskcluster-staging.net/schemas/common/exchanges-reference-v0.json#/properties/entries/items/properties/routingKey/items/properties/required Required bool `json:"required"` // Short description of key in markdown // // See https://taskcluster-staging.net/schemas/common/exchanges-reference-v0.json#/properties/entries/items/properties/routingKey/items/properties/summary Summary string `json:"summary"` }