Documentation ¶
Overview ¶
Package model contains the core logic of the code generation process.
Index ¶
- func GenerateCode(goOutputDir, modelData string)
- type API
- type APIDefinition
- type APIEntry
- type APIModel
- type APIReferenceFile
- type AllOf
- type AnyOf
- type Entry
- type Exchange
- type ExchangeEntry
- type ForEachIn
- type IfThen
- type JsonSubSchema
- type RequiredScope
- type RouteElement
- type ScopeExpressionTemplate
- type SortedAPIDefs
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 { *APIReferenceFile // contains filtered or unexported fields }
API represents the HTTP interface of a Taskcluster service
type APIDefinition ¶
type APIDefinition struct { URL string `json:"url"` Name string `json:"name"` DocRoot string `json:"docroot"` Data APIModel PackageName string ExampleVarName string PackagePath string SchemaURL 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 APIModel ¶
type APIModel interface { String() string // contains filtered or unexported methods }
type APIReferenceFile ¶ added in v1.0.230
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://schemas.taskcluster.net/base/v1/api-reference.json#/properties/$schema Schema string `json:"$schema"` // BaseUrl for all _routes_ described in this document // // See https://schemas.taskcluster.net/base/v1/api-reference.json#/properties/baseUrl BaseURL string `json:"baseUrl"` // API description in markdown // // See https://schemas.taskcluster.net/base/v1/api-reference.json#/properties/description Description string `json:"description"` // Array of methods in this reference // // See https://schemas.taskcluster.net/base/v1/api-reference.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://schemas.taskcluster.net/base/v1/api-reference.json#/properties/serviceName ServiceName string `json:"serviceName"` // API title in markdown // // See https://schemas.taskcluster.net/base/v1/api-reference.json#/properties/title Title string `json:"title"` // API reference version // // Possible values: // * 0 // // See https://schemas.taskcluster.net/base/v1/api-reference.json#/properties/version Version json.RawMessage `json:"version"` }
Reference of methods implemented by API
See https://schemas.taskcluster.net/base/v1/api-reference.json#
type AllOf ¶ added in v1.0.230
type AllOf struct { // See http://schemas.taskcluster.net/base/v1/api-reference.json#/definitions/scopeExpressionTemplate/oneOf[2]/properties/AllOf AllOf []ScopeExpressionTemplate `json:"AllOf"` }
AllOf objects will evaluate to true if all subexpressions are true
type AnyOf ¶ added in v1.0.230
type AnyOf struct { // See http://schemas.taskcluster.net/base/v1/api-reference.json#/definitions/scopeExpressionTemplate/oneOf[1]/properties/AnyOf AnyOf []ScopeExpressionTemplate `json:"AnyOf"` }
AnyOf objects will evaluate to true if any subexpressions are true
type Entry ¶ added in v1.0.230
type Entry struct { // Arguments from `route` that must be replaced, they'll appear wrapped in brackets inside `route`. // // See https://schemas.taskcluster.net/base/v1/api-reference.json#/properties/entries/items/properties/args Args []string `json:"args"` // Description (ie. documentation) for the API entry // // See https://schemas.taskcluster.net/base/v1/api-reference.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://schemas.taskcluster.net/base/v1/api-reference.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://schemas.taskcluster.net/base/v1/api-reference.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://schemas.taskcluster.net/base/v1/api-reference.json#/properties/entries/items/properties/name Name string `json:"name"` // One of: // * OutputSchema // * Blob // // See https://schemas.taskcluster.net/base/v1/api-reference.json#/properties/entries/items/properties/output Output string `json:"output,omitempty"` // List of accepted query-string parameters, these are always optional. // // See https://schemas.taskcluster.net/base/v1/api-reference.json#/properties/entries/items/properties/query Query []string `json:"query,omitempty"` // Route for the call, note that arguments wrapped with brackets, like `/v1/user/<userId>/` must be replaced. And the route must be appended to the `baseUrl` // // See https://schemas.taskcluster.net/base/v1/api-reference.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://schemas.taskcluster.net/base/v1/api-reference.json#/properties/entries/items/properties/scopes Scopes ScopeExpressionTemplate `json:"scopes,omitempty"` // Stability level of the API // // Possible values: // * "deprecated" // * "experimental" // * "stable" // // See https://schemas.taskcluster.net/base/v1/api-reference.json#/properties/entries/items/properties/stability Stability string `json:"stability"` // Title of API entry // // See https://schemas.taskcluster.net/base/v1/api-reference.json#/properties/entries/items/properties/title Title string `json:"title"` // Type of entry, currently only `function`. // // Possible values: // * "function" // // See https://schemas.taskcluster.net/base/v1/api-reference.json#/properties/entries/items/properties/type Type string `json:"type"` }
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"` ServiceName string `json:"serviceName"` // contains filtered or unexported fields }
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 // contains filtered or unexported fields }
func (*ExchangeEntry) String ¶
func (entry *ExchangeEntry) String() string
type ForEachIn ¶ added in v1.0.230
type ForEachIn struct { // Syntax: ^[\x20-\x7e]*$ // // See http://schemas.taskcluster.net/base/v1/api-reference.json#/definitions/scopeExpressionTemplate/oneOf[4]/properties/each Each string `json:"each"` // Syntax: ^[\x20-\x7e]*$ // // See http://schemas.taskcluster.net/base/v1/api-reference.json#/definitions/scopeExpressionTemplate/oneOf[4]/properties/for For string `json:"for"` // Syntax: ^[\x20-\x7e]*$ // // See http://schemas.taskcluster.net/base/v1/api-reference.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 IfThen ¶ added in v1.0.230
type IfThen struct { // Syntax: ^[\x20-\x7e]*$ // // See http://schemas.taskcluster.net/base/v1/api-reference.json#/definitions/scopeExpressionTemplate/oneOf[3]/properties/if If string `json:"if"` // See http://schemas.taskcluster.net/base/v1/api-reference.json#/definitions/scopeExpressionTemplate/oneOf[3]/properties/then Then ScopeExpressionTemplate `json:"then"` }
if/then objects will replace themselves with the contents of then if the `if` is true
type JsonSubSchema ¶
type JsonSubSchema jsonschema2go.JsonSubSchema
func (*JsonSubSchema) TypeDefinition ¶
func (jsonSubSchema *JsonSubSchema) TypeDefinition(level int, extraPackages map[string]bool) (classDefinition, comment, typ string)
type RequiredScope ¶ added in v1.0.230
type RequiredScope string
The most basic element of a scope expression
Syntax: ^[\x20-\x7e]*$
func (*RequiredScope) String ¶ added in v1.0.230
func (rs *RequiredScope) String() string
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 ScopeExpressionTemplate ¶ added in v1.0.230
type ScopeExpressionTemplate struct { RawMessage json.RawMessage // One of: // * "AllOf" // * "AnyOf" // * "ForEachIn" // * "IfThen" // * "RequiredScope" Type string AllOf *AllOf AnyOf *AnyOf ForEachIn *ForEachIn IfThen *IfThen RequiredScope *RequiredScope }
See http://schemas.taskcluster.net/base/v1/api-reference.json#/definitions/scopeExpressionTemplate
func (*ScopeExpressionTemplate) MarshalJSON ¶ added in v1.0.230
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 ¶ added in v1.0.230
func (scopes *ScopeExpressionTemplate) String() string
func (*ScopeExpressionTemplate) UnmarshalJSON ¶ added in v1.0.230
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
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)