api

package
v1.4.11-0...-3a3679d Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2016 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package api represents API abstractions for rendering service generated files.

Index

Constants

View Source
const (
	// ShapeValidationRequired states the shape must be set
	ShapeValidationRequired = iota

	// ShapeValidationMinVal states the shape must have at least a number of
	// elements, or for numbers a minimum value
	ShapeValidationMinVal

	// ShapeValidationNested states the shape has nested values that need
	// to be validated
	ShapeValidationNested
)

Variables

This section is empty.

Functions

func ParamsStructFromJSON

func ParamsStructFromJSON(value interface{}, shape *Shape, prefixPackageName bool) string

ParamsStructFromJSON returns a JSON string representation of a structure.

Types

type API

type API struct {
	Metadata      Metadata
	Operations    map[string]*Operation
	Shapes        map[string]*Shape
	Waiters       []Waiter
	Documentation string

	// Set to true to avoid removing unused shapes
	NoRemoveUnusedShapes bool

	// Set to true to avoid renaming to 'Input/Output' postfixed shapes
	NoRenameToplevelShapes bool

	// Set to true to ignore service/request init methods (for testing)
	NoInitMethods bool

	// Set to true to ignore String() and GoString methods (for generated tests)
	NoStringerMethods bool

	// Set to true to not generate API service name constants
	NoConstServiceNames bool

	// Set to true to not generate validation shapes
	NoValidataShapeMethods bool

	SvcClientImportPath string
	// contains filtered or unexported fields
}

An API defines a service API's definition. and logic to serialize the definition.

func Load

func Load(api, docs, paginators, waiters string) *API

Load takes a set of files for each filetype and returns an API pointer. The API will be initialized once all files have been loaded and parsed.

Will panic if any failure opening the definition JSON files, or there are unrecognized exported names.

func (*API) APIGoCode

func (a *API) APIGoCode() string

APIGoCode renders the API in Go code. Returning it as a string

func (*API) Attach

func (a *API) Attach(filename string)

Attach opens a file by name, and unmarshal its JSON data. Will proceed to setup the API if not already done so.

func (*API) AttachDocs

func (a *API) AttachDocs(filename string)

AttachDocs attaches documentation from a JSON filename.

func (*API) AttachPaginators

func (a *API) AttachPaginators(filename string)

AttachPaginators attaches pagination configuration from filename to the API.

func (*API) AttachString

func (a *API) AttachString(str string)

AttachString will unmarshal a raw JSON string, and setup the API if not already done so.

func (*API) AttachWaiters

func (a *API) AttachWaiters(filename string)

AttachWaiters reads a file of waiter definitions, and adds those to the API. Will panic if an error occurs.

func (*API) ExampleGoCode

func (a *API) ExampleGoCode() string

ExampleGoCode renders service example code. Returning it as a string.

func (*API) ExportableName

func (a *API) ExportableName(name string) string

ExportableName a name which is exportable as a value or name in Go code

func (*API) InterfaceGoCode

func (a *API) InterfaceGoCode() string

InterfaceGoCode returns the go code for the service's API operations as an interface{}. Assumes that the interface is being created in a different package than the service API's package.

func (*API) InterfacePackageName

func (a *API) InterfacePackageName() string

InterfacePackageName returns the package name for the interface.

func (*API) NewAPIGoCodeWithPkgName

func (a *API) NewAPIGoCodeWithPkgName(cfg string) string

NewAPIGoCodeWithPkgName returns a string of instantiating the API prefixed with its package name. Takes a string depicting the Config.

func (*API) NiceName

func (a *API) NiceName() string

NiceName returns the human friendly API name.

func (*API) OperationHasOutputPlaceholder

func (a *API) OperationHasOutputPlaceholder() bool

OperationHasOutputPlaceholder returns if any of the API operation input or output shapes are place holders.

func (*API) OperationList

func (a *API) OperationList() []*Operation

OperationList returns a slice of API operation pointers

func (*API) OperationNames

func (a *API) OperationNames() []string

OperationNames returns a slice of API operations supported.

func (*API) PackageName

func (a *API) PackageName() string

PackageName name of the API package

func (*API) ProtocolPackage

func (a *API) ProtocolPackage() string

ProtocolPackage returns the package name of the protocol this API uses.

func (*API) ServiceGoCode

func (a *API) ServiceGoCode() string

ServiceGoCode renders service go code. Returning it as a string.

func (*API) Setup

func (a *API) Setup()

Setup initializes the API.

func (*API) ShapeList

func (a *API) ShapeList() []*Shape

ShapeList returns a slice of shape pointers used by the API.

func (*API) ShapeNames

func (a *API) ShapeNames() []string

ShapeNames returns a slice of names for each shape used by the API.

func (*API) StructName

func (a *API) StructName() string

StructName returns the struct name for a given API.

func (*API) UseInitMethods

func (a *API) UseInitMethods() bool

UseInitMethods returns if the service's init method should be rendered.

func (*API) WaitersGoCode

func (a *API) WaitersGoCode() string

WaitersGoCode generates and returns Go code for each of the waiters of this API.

type HTTPInfo

type HTTPInfo struct {
	Method       string
	RequestURI   string
	ResponseCode uint
}

A HTTPInfo defines the method of HTTP request for the Operation.

type Metadata

type Metadata struct {
	APIVersion          string
	EndpointPrefix      string
	SigningName         string
	ServiceAbbreviation string
	ServiceFullName     string
	SignatureVersion    string
	JSONVersion         string
	TargetPrefix        string
	Protocol            string
}

A Metadata is the metadata about an API's definition.

type Operation

type Operation struct {
	API           *API `json:"-"`
	ExportedName  string
	Name          string
	Documentation string
	HTTP          HTTPInfo
	InputRef      ShapeRef `json:"input"`
	OutputRef     ShapeRef `json:"output"`
	Paginator     *Paginator
	Deprecated    bool   `json:"deprecated"`
	AuthType      string `json:"authtype"`
}

An Operation defines a specific API Operation.

func (*Operation) Example

func (o *Operation) Example() string

Example returns a string of the rendered Go code for the Operation

func (*Operation) ExampleInput

func (o *Operation) ExampleInput() string

ExampleInput return a string of the rendered Go code for an example's input parameters

func (*Operation) GoCode

func (o *Operation) GoCode() string

GoCode returns a string of rendered GoCode for this Operation

func (*Operation) HasInput

func (o *Operation) HasInput() bool

HasInput returns if the Operation accepts an input paramater

func (*Operation) HasOutput

func (o *Operation) HasOutput() bool

HasOutput returns if the Operation accepts an output parameter

func (*Operation) InterfaceSignature

func (o *Operation) InterfaceSignature() string

InterfaceSignature returns a string representing the Operation's interface{} functional signature.

type Paginator

type Paginator struct {
	InputTokens  interface{} `json:"input_token"`
	OutputTokens interface{} `json:"output_token"`
	LimitKey     string      `json:"limit_key"`
	MoreResults  string      `json:"more_results"`
}

Paginator keeps track of pagination configuration for an API operation.

func (*Paginator) InputTokensString

func (p *Paginator) InputTokensString() string

InputTokensString returns output tokens formatted as a list

func (*Paginator) OutputTokensString

func (p *Paginator) OutputTokensString() string

OutputTokensString returns output tokens formatted as a list

type Shape

type Shape struct {
	API              *API `json:"-"`
	ShapeName        string
	Documentation    string
	MemberRefs       map[string]*ShapeRef `json:"members"`
	MemberRef        ShapeRef             `json:"member"`
	KeyRef           ShapeRef             `json:"key"`
	ValueRef         ShapeRef             `json:"value"`
	Required         []string
	Payload          string
	Type             string
	Exception        bool
	Enum             []string
	EnumConsts       []string
	Flattened        bool
	Streaming        bool
	Location         string
	LocationName     string
	IdempotencyToken bool `json:"idempotencyToken"`
	XMLNamespace     XMLInfo
	Min              float64 // optional Minimum length (string, list) or value (number)
	Max              float64 // optional Maximum length (string, list) or value (number)

	// Defines if the shape is a placeholder and should not be used directly
	Placeholder bool

	Deprecated bool `json:"deprecated"`

	Validations ShapeValidations
	// contains filtered or unexported fields
}

A Shape defines the definition of a shape type

func (*Shape) Docstring

func (s *Shape) Docstring() string

Docstring returns the godocs formated documentation

func (*Shape) EnumName

func (s *Shape) EnumName(n int) string

EnumName returns the Nth enum in the shapes Enum list

func (*Shape) GoCode

func (s *Shape) GoCode() string

GoCode returns the rendered Go code for the Shape.

func (*Shape) GoCodeStringers

func (s *Shape) GoCodeStringers() string

GoCodeStringers renders the Stringers for API input/output shapes

func (*Shape) GoStructType

func (s *Shape) GoStructType(name string, ref *ShapeRef) string

GoStructType returns the type of a struct field based on the API model definition.

func (*Shape) GoTags

func (s *Shape) GoTags(root, required bool) string

GoTags returns the struct tags for a shape.

func (*Shape) GoType

func (s *Shape) GoType() string

GoType returns a shape's Go type

func (*Shape) GoTypeElem

func (s *Shape) GoTypeElem() string

GoTypeElem returns the Go type for the Shape. If the shape type is a pointer just the type will be returned minus the pointer *.

func (*Shape) GoTypeWithPkgName

func (s *Shape) GoTypeWithPkgName() string

GoTypeWithPkgName returns a shape's type as a string with the package name in <packageName>.<type> format. Package naming only applies to structures.

func (*Shape) IsEnum

func (s *Shape) IsEnum() bool

IsEnum returns whether this shape is an enum list

func (*Shape) IsInternal

func (s *Shape) IsInternal() bool

IsInternal returns whether the shape was defined in this package

func (*Shape) IsRequired

func (s *Shape) IsRequired(member string) bool

IsRequired returns if member is a required field.

func (*Shape) MemberNames

func (s *Shape) MemberNames() []string

MemberNames returns a slice of struct member names.

func (*Shape) NestedShape

func (s *Shape) NestedShape() *Shape

NestedShape returns the shape pointer value for the shape which is nested under the current shape. If the shape is not nested nil will be returned.

strucutures, the current shape is returned map: the value shape of the map is returned list: the element shape of the list is returned

func (*Shape) Rename

func (s *Shape) Rename(newName string)

Rename changes the name of the Shape to newName. Also updates the associated API's reference to use newName.

type ShapeRef

type ShapeRef struct {
	API              *API   `json:"-"`
	Shape            *Shape `json:"-"`
	Documentation    string
	ShapeName        string `json:"shape"`
	Location         string
	LocationName     string
	QueryName        string
	Flattened        bool
	Streaming        bool
	XMLAttribute     bool
	XMLNamespace     XMLInfo
	Payload          string
	IdempotencyToken bool `json:"idempotencyToken"`
	Deprecated       bool `json:"deprecated"`
}

A ShapeRef defines the usage of a shape within the API.

func (*ShapeRef) Docstring

func (ref *ShapeRef) Docstring() string

Docstring returns the godocs formated documentation

func (*ShapeRef) GoTags

func (ref *ShapeRef) GoTags(toplevel bool, isRequired bool) string

GoTags returns the rendered tags string for the ShapeRef

func (*ShapeRef) GoType

func (ref *ShapeRef) GoType() string

GoType returns a shape ref's Go type.

func (*ShapeRef) GoTypeElem

func (ref *ShapeRef) GoTypeElem() string

GoTypeElem returns the Go type for the Shape. If the shape type is a pointer just the type will be returned minus the pointer *.

func (*ShapeRef) GoTypeWithPkgName

func (ref *ShapeRef) GoTypeWithPkgName() string

GoTypeWithPkgName returns a shape's type as a string with the package name in <packageName>.<type> format. Package naming only applies to structures.

type ShapeTag

type ShapeTag struct {
	Key, Val string
}

ShapeTag is a struct tag that will be applied to a shape's generated code

func (ShapeTag) String

func (s ShapeTag) String() string

String returns the string representation of the shape tag

type ShapeTags

type ShapeTags []ShapeTag

ShapeTags is a collection of shape tags and provides serialization of the tags in an ordered list.

func (ShapeTags) Join

func (s ShapeTags) Join(sep string) string

Join returns an ordered serialization of the shape tags with the provided separator.

func (ShapeTags) String

func (s ShapeTags) String() string

String is an alias for Join with the empty space separator.

type ShapeValidation

type ShapeValidation struct {
	// Name of the shape to be validated
	Name string
	// Reference to the shape within the context the shape is referenced
	Ref *ShapeRef
	// Type of validation needed
	Type ShapeValidationType
}

A ShapeValidation contains information about a shape and the type of validation that is needed

func (ShapeValidation) GoCode

func (sv ShapeValidation) GoCode() string

GoCode returns the generated Go code for the Shape with its validation type.

type ShapeValidationType

type ShapeValidationType int

A ShapeValidationType is the type of validation that a shape needs

type ShapeValidations

type ShapeValidations []ShapeValidation

A ShapeValidations is a collection of shape validations needed nested within a parent shape

func (ShapeValidations) GoCode

func (vs ShapeValidations) GoCode(shape *Shape) string

GoCode generates the Go code needed to perform validations for the shape and its nested fields.

func (ShapeValidations) Has

Has returns true or false if the ShapeValidations already contains the the reference and validation type.

type WaitAcceptor

type WaitAcceptor struct {
	Expected interface{}
	Matcher  string
	State    string
	Argument string
}

A WaitAcceptor is an individual wait acceptor definition.

func (*WaitAcceptor) ExpectedString

func (a *WaitAcceptor) ExpectedString() string

ExpectedString returns the string that was expected by the WaitAcceptor

type Waiter

type Waiter struct {
	Name          string
	Delay         int
	MaxAttempts   int
	OperationName string `json:"operation"`
	Operation     *Operation
	Acceptors     []WaitAcceptor
}

A Waiter is an individual waiter definition.

func (*Waiter) GoCode

func (w *Waiter) GoCode() string

GoCode returns the generated Go code for an individual waiter.

func (*Waiter) InterfaceSignature

func (w *Waiter) InterfaceSignature() string

InterfaceSignature returns a string representing the Waiter's interface function signature.

type XMLInfo

type XMLInfo struct {
	Prefix string
	URI    string
}

A XMLInfo defines URL and prefix for Shapes when rendered as XML

Jump to

Keyboard shortcuts

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