Documentation ¶
Index ¶
- Constants
- func MakeUniq(base string, taken []string) string
- type APIDescriptor
- type Action
- type ActionParam
- type ArrayDataType
- type Attribute
- type BasicDataType
- type ByName
- type DataType
- type EnumerableDataType
- type ObjectDataType
- type PathPattern
- type Resource
- type SourceUploadDataType
- type UploadDataType
Constants ¶
const ( PathParam = 0 QueryParam = 1 PayloadParam = 2 )
Possible param locations
Variables ¶
This section is empty.
Functions ¶
Types ¶
type APIDescriptor ¶
type APIDescriptor struct { Version string // API Version Resources map[string]*Resource // Resources indexed by name Types map[string]*ObjectDataType // Types used by resource actions indexed by name ResourceNames []string // Resource names ordered alphabetically TypeNames []string // Type names ordered alphabetically NeedTime bool // Whether generated code uses the time.Time package NeedJSON bool // Whether generated code uses encoding/json package }
APIDescriptor contains the results of the analyzer Analyze() method. This includes all the API resources, actions and types.
func (*APIDescriptor) FinalizeTypeNames ¶
func (d *APIDescriptor) FinalizeTypeNames(rawTypes map[string][]*ObjectDataType)
FinalizeTypeNames goes through all the types generated by the analyzer and generate unique names.
func (*APIDescriptor) Merge ¶
func (d *APIDescriptor) Merge(other *APIDescriptor) error
Merge two descriptors together, make sure there are no duplicate resource names and that common types are compatible.
type Action ¶
type Action struct { Name string // Action name, e.g. "create", "multi_terminate" MethodName string // Go method name, e.g. "Create", "MultiTerminate" Description string // Action description ResourceName string // Name of resource that contains this action PathPatterns []*PathPattern // Action path patterns Payload DataType // Payload type if any Params []*ActionParam // Action method parameters LeafParams []*ActionParam // Action parameter leaves (for command line) Return string // Type of method results, e.g. "*ServerArray" ReturnLocation bool // Whether API returns a location header PathParamNames []string // Name of path parameters if any (e.g. :id in /clouds/:id) QueryParamNames []string // Name of query string parameters if any PayloadParamNames []string // Name of payload parameter names if any (payload top level keys) }
Action is a resource action.
func (*Action) HasOptionalParams ¶
HasOptionalParams returns true if the action takes optional parameters, false otherwise.
func (*Action) MandatoryParams ¶
func (a *Action) MandatoryParams() []*ActionParam
MandatoryParams returns the list of all action mandatory parameters
type ActionParam ¶
type ActionParam struct { Name string // Name of parameter QueryName string // Query string style parameter name Description string // Description of parameter VarName string // go variable name Location int // 0 for path param, 1 for query param, 2 for payload param Type DataType // Type of parameter Mandatory bool // Whether parameter is mandatory NonBlank bool // Whether parameter must not be blank if provided (string or array) Regexp string // Regular expression string parameter must match ValidValues []interface{} // Allowed values (if not empty) Min int // Minimum value (int) Max int // Maximum value (int) }
ActionParam is the data structure used to render method params.
func (*ActionParam) IsEquivalent ¶
func (p *ActionParam) IsEquivalent(other *ActionParam) bool
IsEquivalent returns true if other represents the same data type as the target.
func (*ActionParam) Signature ¶
func (p *ActionParam) Signature() (sig string)
Signature generates the signature used e.g. when specifying param in function signatures.
type ArrayDataType ¶
type ArrayDataType struct {
ElemType *ActionParam
}
ArrayDataType is an array data type, it defines the type of its elements.
func (*ArrayDataType) IsEquivalent ¶
func (a *ArrayDataType) IsEquivalent(other DataType) bool
IsEquivalent returns true if other represents the same data type as the target.
func (*ArrayDataType) Name ¶
func (a *ArrayDataType) Name() string
Name is name of element appended with "[]"
type Attribute ¶
type Attribute struct { Name string // Attribute name, e.g. "elasticity_params" FieldName string // Corresponding go struct field name, e.g. "ElasticityParams" FieldType string // Corresponding go struct type, e.g. "*ElasticityParams" }
Attribute is the resource attributes used to generate resource type definition. There may also be a ObjectDataType describing the resource media type for example to use as action parameter. The below is solely to generate the go struct corresponding to the resource.
type BasicDataType ¶
type BasicDataType string
BasicDataType is a basic data type.
func (*BasicDataType) IsEquivalent ¶
func (b *BasicDataType) IsEquivalent(other DataType) bool
IsEquivalent returns true if other represents the same data type as the target.
type ByName ¶
type ByName []*ActionParam
ByName makes it possible to sort action parameters by name.
type DataType ¶
type DataType interface { IsEquivalent(other DataType) bool // true if datatype and other represent the same data structure Name() string // Type name }
DataType is the common interface implemented by all data types.
type EnumerableDataType ¶
type EnumerableDataType int
EnumerableDataType is used for map like data types.
func (*EnumerableDataType) IsEquivalent ¶
func (e *EnumerableDataType) IsEquivalent(other DataType) bool
IsEquivalent returns true if other represents the same data type as the target.
func (*EnumerableDataType) Name ¶
func (e *EnumerableDataType) Name() string
Name returns the type name.
type ObjectDataType ¶
type ObjectDataType struct { TypeName string Fields []*ActionParam }
ObjectDataType is an object data type, it has a name and fields.
func (*ObjectDataType) IsEquivalent ¶
func (o *ObjectDataType) IsEquivalent(other DataType) bool
IsEquivalent returns true if other represents the same data type as the target.
type PathPattern ¶
type PathPattern struct { HTTPMethod string // Action HTTP method, e.g. "GET", "POST" Path string // Path as it appears in metadata Pattern string // Actual pattern, e.g. "/clouds/%s/instances/%s" Variables []string // Pattern variable names in order of appearance in pattern, e.g. "cloud_id", "id" Regexp string // Regular expression used to match href }
A PathPattern represents a possible path for a given action.
type Resource ¶
type Resource struct { Name string // Resource name, e.g. "ServerArray" ClientName string // Name of go client struct, e.g. "API" Description string // Resource description Attributes []*Attribute // Resource attributes Actions []*Action // Resource actions, e.g. "index", "show", "update" ... LocatorFunc string // Source code for Locator factory method if any Identifier string // The mediatype identifier of the resource Links map[string]string // Map of resource links and their descriptions }
Resource is the data structure used to describe API resources.
type SourceUploadDataType ¶ added in v5.0.3
type SourceUploadDataType string
SourceUploadDataType represents the body of a file as a plain text string.
func (*SourceUploadDataType) IsEquivalent ¶ added in v5.0.3
func (e *SourceUploadDataType) IsEquivalent(other DataType) bool
IsEquivalent returns true if other represents the same data type as the target.
func (*SourceUploadDataType) Name ¶ added in v5.0.3
func (e *SourceUploadDataType) Name() string
Name returns the type name.
type UploadDataType ¶
type UploadDataType struct {
TypeName string
}
UploadDataType represents the payload of a multipart request with a file part.
func (*UploadDataType) IsEquivalent ¶
func (u *UploadDataType) IsEquivalent(other DataType) bool
IsEquivalent returns true if other represents the same data type as the target.