Documentation ¶
Overview ¶
Package expr defines expressions and data types used by the DSL and the code generators. The expressions implement the Preparer, Validator, and Finalizer interfaces. The code generators use the finalized expressions to generate the final output.
The data types defined in the expr package are primitive types corresponding to scalar values (bool, string, integers, and numbers), array types which repressent a collection of items, map types which represent maps of key/value pairs, and object types describing data structures with fields. The package also defines user types which can also be a result types. A result type is a user type used to describe response messages rendered using a view.
Index ¶
- Constants
- Variables
- func CanonicalIdentifier(identifier string) string
- func CreateTempFile(t *testing.T, content string) string
- func Diff(t *testing.T, s1, s2 string) string
- func Equal(dt, dt2 DataType) bool
- func ExtractHTTPWildcards(path string) []string
- func IsArray(dt DataType) bool
- func IsMap(dt DataType) bool
- func IsObject(dt DataType) bool
- func IsPrimitive(dt DataType) bool
- func NewLength(a *AttributeExpr, r *Random) int
- func QualifiedTypeName(t DataType) string
- func RunInvalidDSL(t *testing.T, dsl func()) error
- func TaggedAttribute(a *AttributeExpr, tag string) string
- func WalkMappedAttr(ma *MappedAttributeExpr, it MappedAttributeWalker) error
- type APIExpr
- type Array
- type ArrayVal
- type AttributeExpr
- func (a *AttributeExpr) AllRequired() []string
- func (a *AttributeExpr) Debug(prefix string)
- func (a *AttributeExpr) Delete(name string)
- func (a *AttributeExpr) EvalName() string
- func (a *AttributeExpr) Example(r *Random) interface{}
- func (a *AttributeExpr) Finalize()
- func (a *AttributeExpr) Find(name string) *AttributeExpr
- func (a *AttributeExpr) GetDefault(attName string) interface{}
- func (a *AttributeExpr) HasDefaultValue(attName string) bool
- func (a *AttributeExpr) HasTag(tag string) bool
- func (a *AttributeExpr) Inherit(parent *AttributeExpr)
- func (a *AttributeExpr) IsPrimitivePointer(attName string, useDefault bool) bool
- func (a *AttributeExpr) IsRequired(attName string) bool
- func (a *AttributeExpr) IsRequiredNoDefault(attName string) bool
- func (a *AttributeExpr) IsSupportedValidationFormat(vf ValidationFormat) bool
- func (a *AttributeExpr) Merge(other *AttributeExpr)
- func (a *AttributeExpr) Prepare()
- func (a *AttributeExpr) SetDefault(def interface{})
- func (a *AttributeExpr) Validate(ctx string, parent eval.Expression) *eval.ValidationErrors
- type CompositeExpr
- type ContactExpr
- type DataType
- type DocsExpr
- type ErrorExpr
- type ExampleExpr
- type FlowExpr
- type FlowKind
- type GRPCEndpointExpr
- type GRPCErrorExpr
- type GRPCExpr
- type GRPCResponseExpr
- type GRPCServiceExpr
- func (svc *GRPCServiceExpr) Description() string
- func (svc *GRPCServiceExpr) Endpoint(name string) *GRPCEndpointExpr
- func (svc *GRPCServiceExpr) EndpointFor(name string, m *MethodExpr) *GRPCEndpointExpr
- func (svc *GRPCServiceExpr) Error(name string) *ErrorExpr
- func (svc *GRPCServiceExpr) EvalName() string
- func (svc *GRPCServiceExpr) GRPCError(name string) *GRPCErrorExpr
- func (svc *GRPCServiceExpr) Name() string
- func (svc *GRPCServiceExpr) Prepare()
- func (svc *GRPCServiceExpr) Validate() error
- type GeneratedRoot
- type HTTPEndpointExpr
- func (e *HTTPEndpointExpr) Description() string
- func (e *HTTPEndpointExpr) EvalName() string
- func (e *HTTPEndpointExpr) Finalize()
- func (e *HTTPEndpointExpr) HasAbsoluteRoutes() bool
- func (e *HTTPEndpointExpr) Name() string
- func (e *HTTPEndpointExpr) PathParams() *MappedAttributeExpr
- func (e *HTTPEndpointExpr) Prepare()
- func (e *HTTPEndpointExpr) QueryParams() *MappedAttributeExpr
- func (e *HTTPEndpointExpr) Validate() error
- type HTTPErrorExpr
- type HTTPExpr
- type HTTPFileServerExpr
- type HTTPResponseExpr
- type HTTPServiceExpr
- func (svc *HTTPServiceExpr) CanonicalEndpoint() *HTTPEndpointExpr
- func (svc *HTTPServiceExpr) Description() string
- func (svc *HTTPServiceExpr) Endpoint(name string) *HTTPEndpointExpr
- func (svc *HTTPServiceExpr) EndpointFor(name string, m *MethodExpr) *HTTPEndpointExpr
- func (svc *HTTPServiceExpr) Error(name string) *ErrorExpr
- func (svc *HTTPServiceExpr) EvalName() string
- func (svc *HTTPServiceExpr) Finalize()
- func (svc *HTTPServiceExpr) FullPaths() []string
- func (svc *HTTPServiceExpr) HTTPError(name string) *HTTPErrorExpr
- func (svc *HTTPServiceExpr) Name() string
- func (svc *HTTPServiceExpr) Parent() *HTTPServiceExpr
- func (svc *HTTPServiceExpr) Prepare()
- func (svc *HTTPServiceExpr) Validate() error
- type HostExpr
- type Kind
- type LicenseExpr
- type Map
- type MapVal
- type MappedAttributeExpr
- func (ma *MappedAttributeExpr) Attribute() *AttributeExpr
- func (ma *MappedAttributeExpr) Delete(attName string)
- func (ma *MappedAttributeExpr) ElemName(keyName string) string
- func (ma *MappedAttributeExpr) FindKey(keyName string) (string, bool)
- func (ma *MappedAttributeExpr) IsEmpty() bool
- func (ma *MappedAttributeExpr) KeyName(elemName string) string
- func (ma *MappedAttributeExpr) Map(elemName, attName string)
- func (ma *MappedAttributeExpr) Merge(other *MappedAttributeExpr)
- func (ma *MappedAttributeExpr) Remap()
- type MappedAttributeWalker
- type MetaExpr
- type MethodExpr
- type NamedAttributeExpr
- type Object
- func (o *Object) Attribute(name string) *AttributeExpr
- func (o *Object) Delete(n string)
- func (o *Object) Example(r *Random) interface{}
- func (o *Object) Hash() string
- func (o *Object) IsCompatible(val interface{}) bool
- func (o *Object) Kind() Kind
- func (o *Object) Merge(other *Object) *Object
- func (o *Object) Name() string
- func (o *Object) Rename(n, m string)
- func (o *Object) Set(n string, att *AttributeExpr)
- type Primitive
- type Random
- type ResultTypeExpr
- func (m *ResultTypeExpr) Dup(att *AttributeExpr) UserType
- func (m *ResultTypeExpr) Finalize()
- func (m *ResultTypeExpr) HasMultipleViews() bool
- func (m *ResultTypeExpr) ID() string
- func (m *ResultTypeExpr) Kind() Kind
- func (m *ResultTypeExpr) Name() string
- func (m *ResultTypeExpr) View(name string) *ViewExpr
- func (m *ResultTypeExpr) ViewHasAttribute(view, attr string) bool
- type RootExpr
- func (r *RootExpr) DependsOn() []eval.Root
- func (r *RootExpr) Error(name string) *ErrorExpr
- func (r *RootExpr) EvalName() string
- func (r *RootExpr) Finalize()
- func (r *RootExpr) GeneratedResultType(id string) *ResultTypeExpr
- func (r *RootExpr) HTTPService(name string) *HTTPServiceExpr
- func (r *RootExpr) HTTPServiceFor(s *ServiceExpr) *HTTPServiceExpr
- func (r *RootExpr) Packages() []string
- func (r *RootExpr) Service(name string) *ServiceExpr
- func (r *RootExpr) UserType(name string) UserType
- func (r *RootExpr) Validate() error
- func (r *RootExpr) WalkSets(walk eval.SetWalker)
- type RouteExpr
- type SchemeExpr
- type SchemeKind
- type ScopeExpr
- type SecurityExpr
- type ServerExpr
- type ServiceExpr
- type StreamKind
- type TypeMap
- type URIExpr
- type UserType
- type UserTypeExpr
- func (u *UserTypeExpr) Attribute() *AttributeExpr
- func (u *UserTypeExpr) Dup(att *AttributeExpr) UserType
- func (u *UserTypeExpr) Example(r *Random) interface{}
- func (u *UserTypeExpr) Hash() string
- func (u *UserTypeExpr) ID() string
- func (u *UserTypeExpr) IsCompatible(val interface{}) bool
- func (u *UserTypeExpr) Kind() Kind
- func (u *UserTypeExpr) Name() string
- func (u *UserTypeExpr) Rename(n string)
- func (u *UserTypeExpr) SetAttribute(att *AttributeExpr)
- type Val
- type ValidationExpr
- type ValidationFormat
- type ViewExpr
Constants ¶
const ( // FormatDate describes RFC3339 date values. FormatDate ValidationFormat = "date" // FormatDateTime describes RFC3339 date time values. FormatDateTime ValidationFormat = "date-time" // FormatUUID describes RFC4122 UUID values. FormatUUID = "uuid" // FormatEmail describes RFC5322 email addresses. FormatEmail = "email" // FormatHostname describes RFC1035 Internet hostnames. FormatHostname = "hostname" // FormatIPv4 describes RFC2373 IPv4 address values. FormatIPv4 = "ipv4" // FormatIPv6 describes RFC2373 IPv6 address values. FormatIPv6 = "ipv6" // FormatIP describes RFC2373 IPv4 or IPv6 address values. FormatIP = "ip" // FormatURI describes RFC3986 URI values. FormatURI = "uri" // FormatMAC describes IEEE 802 MAC-48, EUI-48 or EUI-64 MAC address values. FormatMAC = "mac" // FormatCIDR describes RFC4632 and RFC4291 CIDR notation IP address values. FormatCIDR = "cidr" // FormatRegexp describes regular expression syntax accepted by RE2. FormatRegexp = "regexp" // FormatJSON describes JSON text. FormatJSON = "json" // FormatRFC1123 describes RFC1123 date time values. FormatRFC1123 = "rfc1123" )
const ( StatusContinue = 100 // RFC 7231, 6.2.1 StatusSwitchingProtocols = 101 // RFC 7231, 6.2.2 StatusProcessing = 102 // RFC 2518, 10.1 StatusOK = 200 // RFC 7231, 6.3.1 StatusCreated = 201 // RFC 7231, 6.3.2 StatusAccepted = 202 // RFC 7231, 6.3.3 StatusNonAuthoritativeInfo = 203 // RFC 7231, 6.3.4 StatusNoContent = 204 // RFC 7231, 6.3.5 StatusResetContent = 205 // RFC 7231, 6.3.6 StatusPartialContent = 206 // RFC 7233, 4.1 StatusMultiStatus = 207 // RFC 4918, 11.1 StatusAlreadyReported = 208 // RFC 5842, 7.1 StatusIMUsed = 226 // RFC 3229, 10.4.1 StatusMultipleChoices = 300 // RFC 7231, 6.4.1 StatusMovedPermanently = 301 // RFC 7231, 6.4.2 StatusFound = 302 // RFC 7231, 6.4.3 StatusSeeOther = 303 // RFC 7231, 6.4.4 StatusNotModified = 304 // RFC 7232, 4.1 StatusUseProxy = 305 // RFC 7231, 6.4.5 StatusTemporaryRedirect = 307 // RFC 7231, 6.4.7 StatusPermanentRedirect = 308 // RFC 7538, 3 StatusBadRequest = 400 // RFC 7231, 6.5.1 StatusPaymentRequired = 402 // RFC 7231, 6.5.2 StatusForbidden = 403 // RFC 7231, 6.5.3 StatusNotFound = 404 // RFC 7231, 6.5.4 StatusMethodNotAllowed = 405 // RFC 7231, 6.5.5 StatusNotAcceptable = 406 // RFC 7231, 6.5.6 StatusProxyAuthRequired = 407 // RFC 7235, 3.2 StatusRequestTimeout = 408 // RFC 7231, 6.5.7 StatusConflict = 409 // RFC 7231, 6.5.8 StatusGone = 410 // RFC 7231, 6.5.9 StatusLengthRequired = 411 // RFC 7231, 6.5.10 StatusPreconditionFailed = 412 // RFC 7232, 4.2 StatusRequestEntityTooLarge = 413 // RFC 7231, 6.5.11 StatusRequestURITooLong = 414 // RFC 7231, 6.5.12 StatusUnsupportedResultType = 415 // RFC 7231, 6.5.13 StatusRequestedRangeNotSatisfiable = 416 // RFC 7233, 4.4 StatusExpectationFailed = 417 // RFC 7231, 6.5.14 StatusTeapot = 418 // RFC 7168, 2.3.3 StatusUnprocessableEntity = 422 // RFC 4918, 11.2 StatusLocked = 423 // RFC 4918, 11.3 StatusFailedDependency = 424 // RFC 4918, 11.4 StatusUpgradeRequired = 426 // RFC 7231, 6.5.15 StatusPreconditionRequired = 428 // RFC 6585, 3 StatusTooManyRequests = 429 // RFC 6585, 4 StatusRequestHeaderFieldsTooLarge = 431 // RFC 6585, 5 StatusInternalServerError = 500 // RFC 7231, 6.6.1 StatusNotImplemented = 501 // RFC 7231, 6.6.2 StatusBadGateway = 502 // RFC 7231, 6.6.3 StatusGatewayTimeout = 504 // RFC 7231, 6.6.5 StatusHTTPVersionNotSupported = 505 // RFC 7231, 6.6.6 StatusVariantAlsoNegotiates = 506 // RFC 2295, 8.1 StatusInsufficientStorage = 507 // RFC 4918, 11.5 StatusLoopDetected = 508 // RFC 5842, 7.2 StatusNotExtended = 510 // RFC 2774, 7 StatusNetworkAuthenticationRequired = 511 // RFC 6585, 6 )
const ( // Boolean is the type for a JSON boolean. Boolean = Primitive(BooleanKind) // Int is the type for a signed integer. Int = Primitive(IntKind) // Int32 is the type for a signed 32-bit integer. Int32 = Primitive(Int32Kind) // Int64 is the type for a signed 64-bit integer. Int64 = Primitive(Int64Kind) // UInt is the type for an unsigned integer. UInt = Primitive(UIntKind) // UInt32 is the type for an unsigned 32-bit integer. UInt32 = Primitive(UInt32Kind) // UInt64 is the type for an unsigned 64-bit integer. UInt64 = Primitive(UInt64Kind) // Float32 is the type for a 32-bit floating number. Float32 = Primitive(Float32Kind) // Float64 is the type for a 64-bit floating number. Float64 = Primitive(Float64Kind) // String is the type for a JSON string. String = Primitive(StringKind) // Bytes is the type for binary data. Bytes = Primitive(BytesKind) // Any is the type for an arbitrary JSON value (interface{} in Go). Any = Primitive(AnyKind) )
const (
// DefaultView is the name of the default result type view.
DefaultView = "default"
)
Variables ¶
var ( // ErrorResultIdentifier is the result type identifier used for error // responses. ErrorResultIdentifier = "application/vnd.goa.error" // ErrorResult is the built-in result type for error responses. ErrorResult = &ResultTypeExpr{ UserTypeExpr: &UserTypeExpr{ AttributeExpr: &AttributeExpr{ Type: errorResultType, Description: "Error response result type", UserExamples: []*ExampleExpr{{ Summary: "BadRequest", Value: Val{ "name": "bad_request", "id": "3F1FKVRR", "message": "Value of ID must be an integer", }, }}, Validation: &ValidationExpr{Required: []string{"name", "id", "message", "temporary", "timeout", "fault"}}, }, TypeName: "error", }, Identifier: ErrorResultIdentifier, Views: []*ViewExpr{errorResultView}, } )
var Empty = &UserTypeExpr{ TypeName: "Empty", AttributeExpr: &AttributeExpr{ Description: "Empty represents empty values", Type: &Object{}, }, }
Empty represents empty values.
var HTTPWildcardRegex = regexp.MustCompile(`/{\*?([a-zA-Z0-9_]+)}`)
HTTPWildcardRegex is the regular expression used to capture path parameters.
var Root = &RootExpr{GeneratedTypes: &GeneratedRoot{}}
Root is the root object built by the DSL.
Functions ¶
func CanonicalIdentifier ¶
CanonicalIdentifier returns the result type identifier sans suffix which is what the DSL uses to store and lookup result types.
func CreateTempFile ¶
CreateTempFile creates a temporary file and writes the given content. It is used only for testing.
func Diff ¶
Diff returns a diff between s1 and s2. It uses the diff tool if installed otherwise degrades to using the dmp package.
func Equal ¶
Equal compares the types recursively and returns true if they are equal. Two types are equal if:
- both types have the same kind
- array types have elements whose types are equal
- map types have keys and elements whose types are equal
- objects have the same attribute names and the attribute types are equal
Note: calling Equal is not equivalent to evaluation dt.Hash() == dt2.Hash() as the former may return true for two user types with different names and thus with different hash values.
func ExtractHTTPWildcards ¶
ExtractHTTPWildcards returns the names of the wildcards that appear in a HTTP path.
func IsPrimitive ¶
IsPrimitive returns true if the data type is a primitive type.
func NewLength ¶
func NewLength(a *AttributeExpr, r *Random) int
NewLength returns an int that validates the generator attribute length validations if any.
func QualifiedTypeName ¶
QualifiedTypeName returns the qualified type name for the given data type. The qualified type name includes the name of the type of the elements of array or map types. This is useful in reporting types in error messages, examples of qualified type names:
"array<string>" "map<string, string>" "map<string, array<int32>>"
func RunInvalidDSL ¶
RunInvalidDSL returns the error resulting from running the given DSL. It is used only in tests.
func TaggedAttribute ¶
func TaggedAttribute(a *AttributeExpr, tag string) string
TaggedAttribute returns the name of the child attribute of a with the given tag if a is an object.
func WalkMappedAttr ¶
func WalkMappedAttr(ma *MappedAttributeExpr, it MappedAttributeWalker) error
WalkMappedAttr iterates over the mapped attributes. It calls the given function giving each attribute as it iterates. WalkMappedAttr stops if there is no more attribute to iterate over or if the iterator function returns an error in which case it returns the error.
Types ¶
type APIExpr ¶
type APIExpr struct { // DSLFunc contains the DSL used to initialize the expression. eval.DSLFunc // Name of API Name string // Title of API Title string // Description of API Description string // Version is the version of the API described by this DSL. Version string // Servers lists the API hosts. Servers []*ServerExpr // TermsOfService describes or links to the service terms of API. TermsOfService string // Contact provides the API users with contact information. Contact *ContactExpr // License describes the API license. License *LicenseExpr // Docs points to the API external documentation. Docs *DocsExpr // Meta is a list of key/value pairs. Meta MetaExpr // Requirements contains the security requirements that apply to // all the API service methods. One requirement is composed of // potentially multiple schemes. Incoming requests must validate // at least one requirement to be authorized. Requirements []*SecurityExpr // HTTP contains the HTTP specific API level expressions. HTTP *HTTPExpr // GRPC contains the gRPC specific API level expressions. GRPC *GRPCExpr // contains filtered or unexported fields }
APIExpr contains the global properties for a API expression.
func NewAPIExpr ¶
NewAPIExpr initializes an API expression.
func (*APIExpr) DefaultServer ¶
func (a *APIExpr) DefaultServer() *ServerExpr
DefaultServer returns a server expression that describes a server which exposes all the services in the design and listens on localhost port 80 for HTTP requests and port 8080 for gRPC requests.
func (*APIExpr) Finalize ¶
func (a *APIExpr) Finalize()
Finalize makes sure that the API name is initialized and there is at least one server definition (if none exists, it creates a default server). If API name is empty, it sets the name of the first service definition as API name.
type Array ¶
type Array struct {
ElemType *AttributeExpr
}
Array is the type used to describe field arrays or repeated fields.
func (*Array) Example ¶
Example generates a pseudo-random array value using the given random generator.
func (*Array) IsCompatible ¶
IsCompatible returns true if val is compatible with p.
type ArrayVal ¶
type ArrayVal []interface{}
ArrayVal is the type used to set the default value for arrays.
type AttributeExpr ¶
type AttributeExpr struct { // DSLFunc contains the DSL used to initialize the expression. eval.DSLFunc // Attribute type Type DataType // Base types if any Bases []DataType // Attribute reference types if any References []DataType // Optional description Description string // Docs points to external documentation Docs *DocsExpr // Optional validations Validation *ValidationExpr // Meta is a list of key/value pairs Meta MetaExpr // Optional member default value DefaultValue interface{} // ZeroValue sets the zero value for the attribute type ZeroValue interface{} // UserExample set in DSL or computed in Finalize UserExamples []*ExampleExpr }
AttributeExpr defines an object field with optional description, default value and validations.
func DupAtt ¶
func DupAtt(att *AttributeExpr) *AttributeExpr
DupAtt creates a copy of the given attribute.
func (*AttributeExpr) AllRequired ¶
func (a *AttributeExpr) AllRequired() []string
AllRequired returns the list of all required fields from the underlying object. This method recurses if the type is itself an attribute (i.e. a UserType, this happens with the Reference DSL for example).
func (*AttributeExpr) Debug ¶
func (a *AttributeExpr) Debug(prefix string)
Debug dumps the attribute to STDOUT in a goa developer friendly way.
func (*AttributeExpr) Delete ¶
func (a *AttributeExpr) Delete(name string)
Delete removes an attribute with the given name. It does nothing if the attribute expression is not an object type.
func (*AttributeExpr) EvalName ¶
func (a *AttributeExpr) EvalName() string
EvalName returns the name used by the DSL evaluation.
func (*AttributeExpr) Example ¶
func (a *AttributeExpr) Example(r *Random) interface{}
Example returns the example set on the attribute at design time. If there isn't such a value then Example computes a random value for the attribute using the given random value producer.
func (*AttributeExpr) Finalize ¶
func (a *AttributeExpr) Finalize()
Finalize merges base and reference type attributes and finalizes the Type attribute.
func (*AttributeExpr) Find ¶
func (a *AttributeExpr) Find(name string) *AttributeExpr
Find finds a child attribute with the given name in the attribute and its bases and references. If the parent attribute is not an object, it returns nil.
func (*AttributeExpr) GetDefault ¶
func (a *AttributeExpr) GetDefault(attName string) interface{}
GetDefault gets the default value for the child attribute with the given name. It returns nil if the child attribute with the given name does not exist or if the child attribute does not have a default value.
func (*AttributeExpr) HasDefaultValue ¶
func (a *AttributeExpr) HasDefaultValue(attName string) bool
HasDefaultValue returns true if the attribute with the given name has a default value.
func (*AttributeExpr) HasTag ¶
func (a *AttributeExpr) HasTag(tag string) bool
HasTag returns true if the attribute is an object that has an attribute with the given tag.
func (*AttributeExpr) Inherit ¶
func (a *AttributeExpr) Inherit(parent *AttributeExpr)
Inherit merges the properties of existing target type attributes with the argument's. The algorithm is recursive so that child attributes are also merged.
func (*AttributeExpr) IsPrimitivePointer ¶
func (a *AttributeExpr) IsPrimitivePointer(attName string, useDefault bool) bool
IsPrimitivePointer returns true if the field generated for the given attribute should be a pointer to a primitive type. The receiver attribute must be an object.
If useDefault is true and the attribute has a default value then IsPrimitivePointer returns false. This makes it possible to differentiate between request types where attributes with default values should not be generated using a pointer value and response types where they should.
DefaultValue UseDefault Pointer (assuming all other conditions are true) Yes True False Yes False True No True True No False True
func (*AttributeExpr) IsRequired ¶
func (a *AttributeExpr) IsRequired(attName string) bool
IsRequired returns true if the given string matches the name of a required attribute, false otherwise. This method only applies to attributes of type Object.
func (*AttributeExpr) IsRequiredNoDefault ¶
func (a *AttributeExpr) IsRequiredNoDefault(attName string) bool
IsRequiredNoDefault returns true if the given string matches the name of a required attribute and the attribute has no default value, false otherwise. This method only applies to attributes of type Object.
func (*AttributeExpr) IsSupportedValidationFormat ¶
func (a *AttributeExpr) IsSupportedValidationFormat(vf ValidationFormat) bool
IsSupportedValidationFormat checks if the validation format is supported by goa.
func (*AttributeExpr) Merge ¶
func (a *AttributeExpr) Merge(other *AttributeExpr)
Merge merges other's attributes into a overriding attributes of a with attributes of other with identical names.
This only applies to attributes of type Object and Merge panics if the argument or the target is not of type Object.
func (*AttributeExpr) Prepare ¶
func (a *AttributeExpr) Prepare()
Prepare initializes the Meta expression.
func (*AttributeExpr) SetDefault ¶
func (a *AttributeExpr) SetDefault(def interface{})
SetDefault sets the default for the attribute. It also converts HashVal and ArrayVal to map and slice respectively.
func (*AttributeExpr) Validate ¶
func (a *AttributeExpr) Validate(ctx string, parent eval.Expression) *eval.ValidationErrors
Validate tests whether the attribute required fields exist. Since attributes are unaware of their context, additional context information can be provided to be used in error messages. The parent definition context is automatically added to error messages.
type CompositeExpr ¶
type CompositeExpr interface { // Attribute returns the composite expression embedded attribute. Attribute() *AttributeExpr }
CompositeExpr defines a generic composite expression that contains an attribute. This makes it possible for plugins to use attributes in their own data structures.
type ContactExpr ¶
type ContactExpr struct { // Name of the contact person/organization Name string `json:"name,omitempty"` // Email address of the contact person/organization Email string `json:"email,omitempty"` // URL pointing to the contact information URL string `json:"url,omitempty"` }
ContactExpr contains the API contact information.
func (*ContactExpr) EvalName ¶
func (c *ContactExpr) EvalName() string
EvalName is the qualified name of the expression.
type DataType ¶
type DataType interface { // Kind of data type, one of the Kind enum. Kind() Kind // Name returns the type name. Name() string // IsCompatible checks whether val has a Go type that is compatible with the data // type. IsCompatible(interface{}) bool // Example generates a pseudo-random value using the given random generator. Example(*Random) interface{} // Hash returns a unique hash value for the instance of the type. Hash() string }
DataType is the common interface to all types.
type DocsExpr ¶
type DocsExpr struct { // Description of documentation. Description string `json:"description,omitempty"` // URL to documentation. URL string `json:"url,omitempty"` }
DocsExpr points to external documentation.
type ErrorExpr ¶
type ErrorExpr struct { // AttributeExpr is the underlying attribute. *AttributeExpr // Name is the unique name of the error. Name string }
ErrorExpr defines an error response. It consists of a named attribute.
type ExampleExpr ¶
type ExampleExpr struct { // Summary is the example short summary. Summary string // Description is an optional long description. Description string // Value is the example value. Value interface{} }
ExampleExpr represents an example.
func (*ExampleExpr) EvalName ¶
func (a *ExampleExpr) EvalName() string
EvalName returns the name used by the DSL evaluation.
type FlowExpr ¶
type FlowExpr struct { // Kind is the kind of flow. Kind FlowKind // AuthorizationURL to be used for implicit or authorizationCode // flows. AuthorizationURL string // TokenURL to be used for password, clientCredentials or // authorizationCode flows. TokenURL string // RefreshURL to be used for obtaining refresh token. RefreshURL string }
FlowExpr describes a specific OAuth2 flow.
func (*FlowExpr) Validate ¶
func (f *FlowExpr) Validate() *eval.ValidationErrors
Validate ensures that TokenURL and AuthorizationURL are valid URLs.
type FlowKind ¶
type FlowKind int
FlowKind is a type of OAuth2 flow.
const ( // AuthorizationCodeFlowKind identifies a OAuth2 authorization code // flow. AuthorizationCodeFlowKind FlowKind = iota + 1 // ImplicitFlowKind identifiers a OAuth2 implicit flow. ImplicitFlowKind // PasswordFlowKind identifies a Resource Owner Password flow. PasswordFlowKind // ClientCredentialsFlowKind identifies a OAuth Client Credentials flow. ClientCredentialsFlowKind )
type GRPCEndpointExpr ¶
type GRPCEndpointExpr struct { eval.DSLFunc // MethodExpr is the underlying method expression. MethodExpr *MethodExpr // Service is the parent service. Service *GRPCServiceExpr // Request is the message passed to the gRPC method. Request *AttributeExpr // StreamingRequest is the message passed to the gRPC method through a // stream. StreamingRequest *AttributeExpr // Responses is the success gRPC response from the method. Response *GRPCResponseExpr // GRPCErrors is the list of all the possible error gRPC responses. GRPCErrors []*GRPCErrorExpr // Metadata is the metadata to be sent in a gRPC request. Metadata *MappedAttributeExpr // Requirements is the list of security requirements for the gRPC endpoint. Requirements []*SecurityExpr // Meta is a set of key/value pairs with semantic that is // specific to each generator, see dsl.Meta. Meta MetaExpr }
GRPCEndpointExpr describes a gRPC endpoint. It embeds a MethodExpr and adds gRPC specific properties.
func (*GRPCEndpointExpr) Description ¶
func (e *GRPCEndpointExpr) Description() string
Description of gRPC endpoint
func (*GRPCEndpointExpr) EvalName ¶
func (e *GRPCEndpointExpr) EvalName() string
EvalName returns the generic expression name used in error messages.
func (*GRPCEndpointExpr) Finalize ¶
func (e *GRPCEndpointExpr) Finalize()
Finalize ensures the request and response attributes are initialized.
func (*GRPCEndpointExpr) Prepare ¶
func (e *GRPCEndpointExpr) Prepare()
Prepare initializes the Request and Response if nil.
func (*GRPCEndpointExpr) Validate ¶
func (e *GRPCEndpointExpr) Validate() error
Validate validates the endpoint expression by checking if the request and responses contains the "rpc:tag" in the meta. It also makes sure that there is only one response per status code.
type GRPCErrorExpr ¶
type GRPCErrorExpr struct { // ErrorExpr is the underlying goa design error expression. *ErrorExpr // Name of error to match it up with the appropriate ErrorExpr. Name string // Response is the corresponding gRPC response. Response *GRPCResponseExpr }
GRPCErrorExpr defines a gRPC error response including its name, status, and result type.
func (*GRPCErrorExpr) Dup ¶
func (e *GRPCErrorExpr) Dup() *GRPCErrorExpr
Dup creates a copy of the error expression.
func (*GRPCErrorExpr) EvalName ¶
func (e *GRPCErrorExpr) EvalName() string
EvalName returns the generic definition name used in error messages.
func (*GRPCErrorExpr) Finalize ¶
func (e *GRPCErrorExpr) Finalize(a *GRPCEndpointExpr)
Finalize looks up the corresponding method error expression.
func (*GRPCErrorExpr) Validate ¶
func (e *GRPCErrorExpr) Validate() *eval.ValidationErrors
Validate makes sure there is a error expression that matches the gRPC error expression.
type GRPCExpr ¶
type GRPCExpr struct { // Services contains the gRPC services created by the DSL. Services []*GRPCServiceExpr // Errors lists the error gRPC error responses defined globally. Errors []*GRPCErrorExpr }
GRPCExpr contains the API level gRPC specific expressions.
func (*GRPCExpr) Service ¶
func (g *GRPCExpr) Service(name string) *GRPCServiceExpr
Service returns the service with the given name if any.
func (*GRPCExpr) ServiceFor ¶
func (g *GRPCExpr) ServiceFor(s *ServiceExpr) *GRPCServiceExpr
ServiceFor creates a new or returns the existing service definition for the given service.
type GRPCResponseExpr ¶
type GRPCResponseExpr struct { // gRPC status code StatusCode int // Response description Description string // Response Message if any Message *AttributeExpr // Parent expression, one of EndpointExpr, ServiceExpr or // RootExpr. Parent eval.Expression // Headers is the header metadata to be sent in the gRPC response. Headers *MappedAttributeExpr // Trailers is the trailer metadata to be sent in the gRPC response. Trailers *MappedAttributeExpr // Meta is a list of key/value pairs. Meta MetaExpr }
GRPCResponseExpr defines a gRPC response including its status code, result type, and metadata.
func (*GRPCResponseExpr) Dup ¶
func (r *GRPCResponseExpr) Dup() *GRPCResponseExpr
Dup creates a copy of the response expression.
func (*GRPCResponseExpr) EvalName ¶
func (r *GRPCResponseExpr) EvalName() string
EvalName returns the generic definition name used in error messages.
func (*GRPCResponseExpr) Finalize ¶
func (r *GRPCResponseExpr) Finalize(a *GRPCEndpointExpr, svcAtt *AttributeExpr)
Finalize ensures that the response message type is set. If Message DSL is used to set the response message then the message type is set by mapping the attributes to the method Result expression. If no response message set explicitly, the message is set from the method Result expression.
func (*GRPCResponseExpr) Prepare ¶
func (r *GRPCResponseExpr) Prepare()
Prepare makes sure the response message and metadata are initialized.
func (*GRPCResponseExpr) Validate ¶
func (r *GRPCResponseExpr) Validate(e *GRPCEndpointExpr) *eval.ValidationErrors
Validate checks that the response definition is consistent: its status is set and the result type definition if any is valid.
type GRPCServiceExpr ¶
type GRPCServiceExpr struct { eval.DSLFunc // ServiceExpr is the service expression that backs this service. ServiceExpr *ServiceExpr // Name of parent service if any ParentName string // GRPCEndpoints is the list of service endpoints. GRPCEndpoints []*GRPCEndpointExpr // GRPCErrors lists gRPC errors that apply to all endpoints. GRPCErrors []*GRPCErrorExpr // Meta is a set of key/value pairs with semantic that is // specific to each generator. Meta MetaExpr }
GRPCServiceExpr describes a gRPC service.
func (*GRPCServiceExpr) Description ¶
func (svc *GRPCServiceExpr) Description() string
Description of service (service)
func (*GRPCServiceExpr) Endpoint ¶
func (svc *GRPCServiceExpr) Endpoint(name string) *GRPCEndpointExpr
Endpoint returns the service endpoint with the given name or nil if there isn't one.
func (*GRPCServiceExpr) EndpointFor ¶
func (svc *GRPCServiceExpr) EndpointFor(name string, m *MethodExpr) *GRPCEndpointExpr
EndpointFor builds the endpoint for the given method.
func (*GRPCServiceExpr) Error ¶
func (svc *GRPCServiceExpr) Error(name string) *ErrorExpr
Error returns the error with the given name.
func (*GRPCServiceExpr) EvalName ¶
func (svc *GRPCServiceExpr) EvalName() string
EvalName returns the generic definition name used in error messages.
func (*GRPCServiceExpr) GRPCError ¶
func (svc *GRPCServiceExpr) GRPCError(name string) *GRPCErrorExpr
GRPCError returns the service gRPC error with given name if any.
func (*GRPCServiceExpr) Prepare ¶
func (svc *GRPCServiceExpr) Prepare()
Prepare initializes the error responses.
func (*GRPCServiceExpr) Validate ¶
func (svc *GRPCServiceExpr) Validate() error
Validate makes sure the service is valid.
type GeneratedRoot ¶
type GeneratedRoot []UserType
GeneratedRoot records the generated result types and is a DSL root evaluated after Root.
func (*GeneratedRoot) DependsOn ¶
func (r *GeneratedRoot) DependsOn() []eval.Root
DependsOn ensures that Root executes first.
func (*GeneratedRoot) EvalName ¶
func (r *GeneratedRoot) EvalName() string
EvalName is the name of the expression used by eval.
func (*GeneratedRoot) Packages ¶
func (r *GeneratedRoot) Packages() []string
Packages returns the Go import path to this and the dsl packages.
func (*GeneratedRoot) WalkSets ¶
func (r *GeneratedRoot) WalkSets(w eval.SetWalker)
WalkSets returns the generated result types for evaluation.
type HTTPEndpointExpr ¶
type HTTPEndpointExpr struct { eval.DSLFunc // MethodExpr is the underlying method expression. MethodExpr *MethodExpr // Service is the parent service. Service *HTTPServiceExpr // Endpoint routes Routes []*RouteExpr // MapQueryParams - when not nil - indicates that the HTTP // request query string parameters are used to build a map. // - If the value is the empty string then the map is stored // in the method payload (which must be of type Map) // - If the value is a non-empty string then the map is // stored in the payload attribute with the corresponding // name (which must of be of type Map) MapQueryParams *string // Params defines the HTTP request path and query parameters. Params *MappedAttributeExpr // Headers defines the HTTP request headers. Headers *MappedAttributeExpr // Body describes the HTTP request body. Body *AttributeExpr // StreamingBody describes the body transferred through the websocket // stream. StreamingBody *AttributeExpr // Responses is the list of all the possible success HTTP // responses. Responses []*HTTPResponseExpr // HTTPErrors is the list of all the possible error HTTP // responses. HTTPErrors []*HTTPErrorExpr // Requirements contains the security requirements for the HTTP endpoint. Requirements []*SecurityExpr // MultipartRequest indicates that the request content type for // the endpoint is a multipart type. MultipartRequest bool // Meta is a set of key/value pairs with semantic that is // specific to each generator, see dsl.Meta. Meta MetaExpr }
HTTPEndpointExpr describes a HTTP endpoint. It embeds a MethodExpr and adds HTTP specific properties.
It defines both an HTTP endpoint and the shape of HTTP requests and responses made to that endpoint. The shape of requests is defined via "parameters", there are path parameters (i.e. portions of the URL that define parameter values), query string parameters and a payload parameter (request body).
func (*HTTPEndpointExpr) Description ¶
func (e *HTTPEndpointExpr) Description() string
Description of HTTP endpoint
func (*HTTPEndpointExpr) EvalName ¶
func (e *HTTPEndpointExpr) EvalName() string
EvalName returns the generic expression name used in error messages.
func (*HTTPEndpointExpr) Finalize ¶
func (e *HTTPEndpointExpr) Finalize()
Finalize is run post DSL execution. It merges response definitions, creates implicit endpoint parameters and initializes querystring parameters. It also flattens the error responses and makes sure the error types are all user types so that the response encoding code can properly use the type to infer the response that it needs to build.
func (*HTTPEndpointExpr) HasAbsoluteRoutes ¶
func (e *HTTPEndpointExpr) HasAbsoluteRoutes() bool
HasAbsoluteRoutes returns true if all the endpoint routes are absolute.
func (*HTTPEndpointExpr) PathParams ¶
func (e *HTTPEndpointExpr) PathParams() *MappedAttributeExpr
PathParams computes a mapped attribute containing the subset of e.Params that describe path parameters.
func (*HTTPEndpointExpr) Prepare ¶
func (e *HTTPEndpointExpr) Prepare()
Prepare computes the request path and query string parameters as well as the headers and body taking into account the inherited values from the service.
func (*HTTPEndpointExpr) QueryParams ¶
func (e *HTTPEndpointExpr) QueryParams() *MappedAttributeExpr
QueryParams computes a mapped attribute containing the subset of e.Params that describe query parameters.
func (*HTTPEndpointExpr) Validate ¶
func (e *HTTPEndpointExpr) Validate() error
Validate validates the endpoint expression.
type HTTPErrorExpr ¶
type HTTPErrorExpr struct { // ErrorExpr is the underlying goa design error expression. *ErrorExpr // Name of error, we need a separate copy of the name to match it // up with the appropriate ErrorExpr. Name string // Response is the corresponding HTTP response. Response *HTTPResponseExpr }
HTTPErrorExpr defines a HTTP error response including its name, status, headers and result type.
func (*HTTPErrorExpr) Dup ¶
func (e *HTTPErrorExpr) Dup() *HTTPErrorExpr
Dup creates a copy of the error expression.
func (*HTTPErrorExpr) EvalName ¶
func (e *HTTPErrorExpr) EvalName() string
EvalName returns the generic definition name used in error messages.
func (*HTTPErrorExpr) Finalize ¶
func (e *HTTPErrorExpr) Finalize(a *HTTPEndpointExpr)
Finalize looks up the corresponding method error expression.
func (*HTTPErrorExpr) Validate ¶
func (e *HTTPErrorExpr) Validate() *eval.ValidationErrors
Validate makes sure there is a error expression that matches the HTTP error expression.
type HTTPExpr ¶
type HTTPExpr struct { // Path is the common request path prefix to all the service // HTTP endpoints. Path string // Params defines the HTTP request path and query parameters // common to all the API endpoints. Params *MappedAttributeExpr // Headers defines the HTTP request headers common to to all // the API endpoints. Headers *MappedAttributeExpr // Consumes lists the mime types supported by the API // controllers. Consumes []string // Produces lists the mime types generated by the API // controllers. Produces []string // Services contains the services created by the DSL. Services []*HTTPServiceExpr // Errors lists the error HTTP responses. Errors []*HTTPErrorExpr }
HTTPExpr contains the API level HTTP specific expressions.
func (*HTTPExpr) Finalize ¶
func (h *HTTPExpr) Finalize()
Finalize initializes Consumes and Produces with defaults if not set.
func (*HTTPExpr) Service ¶
func (h *HTTPExpr) Service(name string) *HTTPServiceExpr
Service returns the service with the given name if any.
func (*HTTPExpr) ServiceFor ¶
func (h *HTTPExpr) ServiceFor(s *ServiceExpr) *HTTPServiceExpr
ServiceFor creates a new or returns the existing service definition for the given service.
type HTTPFileServerExpr ¶
type HTTPFileServerExpr struct { // Service is the parent service. Service *HTTPServiceExpr // Description for docs Description string // Docs points to the service external documentation Docs *DocsExpr // FilePath is the file path to the static asset(s) FilePath string // RequestPaths is the list of HTTP paths that serve the assets. RequestPaths []string // Meta is a list of key/value pairs Meta MetaExpr }
HTTPFileServerExpr defines an endpoint that serves static assets through HTTP.
func (*HTTPFileServerExpr) EvalName ¶
func (f *HTTPFileServerExpr) EvalName() string
EvalName returns the generic definition name used in error messages.
func (*HTTPFileServerExpr) Finalize ¶
func (f *HTTPFileServerExpr) Finalize()
Finalize normalizes the request path.
func (*HTTPFileServerExpr) IsDir ¶
func (f *HTTPFileServerExpr) IsDir() bool
IsDir returns true if the file server serves a directory, false otherwise.
type HTTPResponseExpr ¶
type HTTPResponseExpr struct { // HTTP status StatusCode int // Response description Description string // Headers describe the HTTP response headers. Headers *MappedAttributeExpr // Response body if any Body *AttributeExpr // Response Content-Type header value ContentType string // Tag the value a field of the result must have for this // response to be used. Tag [2]string // Parent expression, one of EndpointExpr, ServiceExpr or // RootExpr. Parent eval.Expression // Meta is a list of key/value pairs Meta MetaExpr }
HTTPResponseExpr defines a HTTP response including its status code, headers and result type.
func (*HTTPResponseExpr) Dup ¶
func (r *HTTPResponseExpr) Dup() *HTTPResponseExpr
Dup creates a copy of the response expression.
func (*HTTPResponseExpr) EvalName ¶
func (r *HTTPResponseExpr) EvalName() string
EvalName returns the generic definition name used in error messages.
func (*HTTPResponseExpr) Finalize ¶
func (r *HTTPResponseExpr) Finalize(a *HTTPEndpointExpr, svcAtt *AttributeExpr)
Finalize sets the response result type from its type if the type is a result type and no result type is already specified.
func (*HTTPResponseExpr) Prepare ¶
func (r *HTTPResponseExpr) Prepare()
Prepare makes sure the response is initialized even if not done explicitly by
func (*HTTPResponseExpr) Validate ¶
func (r *HTTPResponseExpr) Validate(e *HTTPEndpointExpr) *eval.ValidationErrors
Validate checks that the response definition is consistent: its status is set and the result type definition if any is valid.
type HTTPServiceExpr ¶
type HTTPServiceExpr struct { eval.DSLFunc // ServiceExpr is the service expression that backs this // service. ServiceExpr *ServiceExpr // Common URL prefixes to all service endpoint HTTP requests Paths []string // Params defines the HTTP request path and query parameters // common to all the service endpoints. Params *MappedAttributeExpr // Headers defines the HTTP request headers common to all the // service endpoints. Headers *MappedAttributeExpr // Name of parent service if any ParentName string // Endpoint with canonical service path CanonicalEndpointName string // HTTPEndpoints is the list of service endpoints. HTTPEndpoints []*HTTPEndpointExpr // HTTPErrors lists HTTP errors that apply to all endpoints. HTTPErrors []*HTTPErrorExpr // FileServers is the list of static asset serving endpoints FileServers []*HTTPFileServerExpr // Meta is a set of key/value pairs with semantic that is // specific to each generator. Meta MetaExpr }
HTTPServiceExpr describes a HTTP service. It defines both a result type and a set of endpoints that can be executed through HTTP requests. HTTPServiceExpr embeds a ServiceExpr and adds HTTP specific properties.
func (*HTTPServiceExpr) CanonicalEndpoint ¶
func (svc *HTTPServiceExpr) CanonicalEndpoint() *HTTPEndpointExpr
CanonicalEndpoint returns the canonical endpoint of the service if any. The canonical endpoint is used to compute hrefs to services.
func (*HTTPServiceExpr) Description ¶
func (svc *HTTPServiceExpr) Description() string
Description of service (service)
func (*HTTPServiceExpr) Endpoint ¶
func (svc *HTTPServiceExpr) Endpoint(name string) *HTTPEndpointExpr
Endpoint returns the service endpoint with the given name or nil if there isn't one.
func (*HTTPServiceExpr) EndpointFor ¶
func (svc *HTTPServiceExpr) EndpointFor(name string, m *MethodExpr) *HTTPEndpointExpr
EndpointFor builds the endpoint for the given method.
func (*HTTPServiceExpr) Error ¶
func (svc *HTTPServiceExpr) Error(name string) *ErrorExpr
Error returns the error with the given name.
func (*HTTPServiceExpr) EvalName ¶
func (svc *HTTPServiceExpr) EvalName() string
EvalName returns the generic definition name used in error messages.
func (*HTTPServiceExpr) Finalize ¶
func (svc *HTTPServiceExpr) Finalize()
Finalize initializes the path if no path is set in design.
func (*HTTPServiceExpr) FullPaths ¶
func (svc *HTTPServiceExpr) FullPaths() []string
FullPaths computes the base paths to the service endpoints concatenating the API and parent service base paths as needed.
func (*HTTPServiceExpr) HTTPError ¶
func (svc *HTTPServiceExpr) HTTPError(name string) *HTTPErrorExpr
HTTPError returns the service HTTP error with given name if any.
func (*HTTPServiceExpr) Parent ¶
func (svc *HTTPServiceExpr) Parent() *HTTPServiceExpr
Parent returns the parent service if any, nil otherwise.
func (*HTTPServiceExpr) Prepare ¶
func (svc *HTTPServiceExpr) Prepare()
Prepare initializes the error responses.
func (*HTTPServiceExpr) Validate ¶
func (svc *HTTPServiceExpr) Validate() error
Validate makes sure the service is valid.
type HostExpr ¶
type HostExpr struct { // Name of host Name string // Name of server that uses host. ServerName string // Description of host Description string // URIs to host if any, may contain parameter elements using // the "{param}" syntax. URIs []URIExpr // Variables defines the URI variables if any. Variables *AttributeExpr }
HostExpr describes a server host.
func (*HostExpr) Attribute ¶
func (h *HostExpr) Attribute() *AttributeExpr
Attribute returns the variables attribute.
func (*HostExpr) HasGRPCScheme ¶
HasGRPCScheme returns true if at least one of the URIs in the host expression define "grpc" or "grpcs" scheme.
func (*HostExpr) HasHTTPScheme ¶
HasHTTPScheme returns true if at least one of the URIs in the host expression define "http" or "https" scheme.
type Kind ¶
type Kind uint
A Kind defines the conceptual type that a DataType represents.
const ( // BooleanKind represents a boolean. BooleanKind Kind = iota + 1 // IntKind represents a signed integer. IntKind // Int32Kind represents a signed 32-bit integer. Int32Kind // Int64Kind represents a signed 64-bit integer. Int64Kind // UIntKind represents an unsigned integer. UIntKind // UInt32Kind represents an unsigned 32-bit integer. UInt32Kind // UInt64Kind represents an unsigned 64-bit integer. UInt64Kind // Float32Kind represents a 32-bit floating number. Float32Kind // Float64Kind represents a 64-bit floating number. Float64Kind // StringKind represents a JSON string. StringKind // BytesKind represent a series of bytes (binary data). BytesKind // ArrayKind represents a JSON array. ArrayKind // ObjectKind represents a JSON object. ObjectKind // MapKind represents a JSON object where the keys are not known in // advance. MapKind // UserTypeKind represents a user type. UserTypeKind // ResultTypeKind represents a result type. ResultTypeKind // AnyKind represents an unknown type. AnyKind )
type LicenseExpr ¶
type LicenseExpr struct { // Name of license used for the API Name string `json:"name,omitempty"` // URL to the license used for the API URL string `json:"url,omitempty"` }
LicenseExpr contains the license information for the API.
func (*LicenseExpr) EvalName ¶
func (l *LicenseExpr) EvalName() string
EvalName is the qualified name of the expression.
type Map ¶
type Map struct { KeyType *AttributeExpr ElemType *AttributeExpr }
Map is the type used to describe maps of fields.
func (*Map) IsCompatible ¶
IsCompatible returns true if o describes the (Go) type of val.
type MapVal ¶
type MapVal map[interface{}]interface{}
MapVal is the type used to set the default value for maps.
type MappedAttributeExpr ¶
type MappedAttributeExpr struct { *AttributeExpr // contains filtered or unexported fields }
MappedAttributeExpr is an attribute expression of type object that map the object keys to external names (e.g. HTTP header names).
func DupMappedAtt ¶
func DupMappedAtt(ma *MappedAttributeExpr) *MappedAttributeExpr
DupMappedAtt creates a deep copy of ma.
func NewEmptyMappedAttributeExpr ¶
func NewEmptyMappedAttributeExpr() *MappedAttributeExpr
NewEmptyMappedAttributeExpr creates an empty mapped attribute expression.
func NewMappedAttributeExpr ¶
func NewMappedAttributeExpr(att *AttributeExpr) *MappedAttributeExpr
NewMappedAttributeExpr instantiates a mapped attribute expression for the given attribute. The type of att must be Object.
func (*MappedAttributeExpr) Attribute ¶
func (ma *MappedAttributeExpr) Attribute() *AttributeExpr
Attribute returns the original attribute using "att:elem" format for the keys.
func (*MappedAttributeExpr) Delete ¶
func (ma *MappedAttributeExpr) Delete(attName string)
Delete removes a child attribute given its name.
func (*MappedAttributeExpr) ElemName ¶
func (ma *MappedAttributeExpr) ElemName(keyName string) string
ElemName returns the transport element name of the given object key. It returns keyName if it's a key of the mapped attribute object type. It panics if there is no mapping and keyName is not a key.
func (*MappedAttributeExpr) FindKey ¶
func (ma *MappedAttributeExpr) FindKey(keyName string) (string, bool)
FindKey finds the given key in the mapped attribute expression. If key is found, it returns the transport element name of the key and true. Otherwise, it returns an empty string and false.
func (*MappedAttributeExpr) IsEmpty ¶
func (ma *MappedAttributeExpr) IsEmpty() bool
IsEmpty returns true if the mapped attribute contains no key.
func (*MappedAttributeExpr) KeyName ¶
func (ma *MappedAttributeExpr) KeyName(elemName string) string
KeyName returns the object key of the given transport element name. It returns elemName if it's a key of the mapped attribute object type. It panics if there is no mapping and elemName is not a key.
func (*MappedAttributeExpr) Map ¶
func (ma *MappedAttributeExpr) Map(elemName, attName string)
Map records the element name of one of the child attributes. Map panics if attName is not the name of a child attribute.
func (*MappedAttributeExpr) Merge ¶
func (ma *MappedAttributeExpr) Merge(other *MappedAttributeExpr)
Merge merges other's attributes into a overriding attributes of a with attributes of other with identical names.
func (*MappedAttributeExpr) Remap ¶
func (ma *MappedAttributeExpr) Remap()
Remap recomputes the name mappings from the inner attribute. Use this if the underlying attribute is modified after the mapped attribute has been initially created.
type MappedAttributeWalker ¶
type MappedAttributeWalker func(name, elem string, a *AttributeExpr) error
MappedAttributeWalker is the type of functions given to WalkMappedAttr.
name is the name of the attribute elem the name of the corresponding transport element a is the corresponding attribute expression
type MetaExpr ¶
MetaExpr is a set of key/value pairs
type MethodExpr ¶
type MethodExpr struct { // DSLFunc contains the DSL used to initialize the expression. eval.DSLFunc // Name of method. Name string // Description of method for consumption by humans. Description string // Docs points to the method external documentation if any. Docs *DocsExpr // Payload attribute Payload *AttributeExpr // Result attribute Result *AttributeExpr // Errors lists the error responses. Errors []*ErrorExpr // Requirements contains the security requirements for the // method. One requirement is composed of potentially multiple // schemes. Incoming requests must validate at least one // requirement to be authorized. Requirements []*SecurityExpr // Service that owns method. Service *ServiceExpr // Meta is an arbitrary set of key/value pairs, see dsl.Meta Meta MetaExpr // Stream is the kind of stream (none, payload, result, or both) // the method defines. Stream StreamKind // StreamingPayload is the payload sent across the stream. StreamingPayload *AttributeExpr }
MethodExpr defines a single method.
func (*MethodExpr) Error ¶
func (m *MethodExpr) Error(name string) *ErrorExpr
Error returns the error with the given name. It looks up recursively in the endpoint then the service and finally the root expression.
func (*MethodExpr) EvalName ¶
func (m *MethodExpr) EvalName() string
EvalName returns the generic expression name used in error messages.
func (*MethodExpr) Finalize ¶
func (m *MethodExpr) Finalize()
Finalize makes sure the method payload and result types are set. It also projects the result if it is a result type and a view is explicitly set in the design or a result type having at most one view.
func (*MethodExpr) IsPayloadStreaming ¶
func (m *MethodExpr) IsPayloadStreaming() bool
IsPayloadStreaming determines whether the method streams payload.
func (*MethodExpr) IsStreaming ¶
func (m *MethodExpr) IsStreaming() bool
IsStreaming determines whether the method streams payload or result.
func (*MethodExpr) Prepare ¶
func (m *MethodExpr) Prepare()
Prepare makes sure the payload and result types are initialized (to the Empty type if nil).
func (*MethodExpr) Validate ¶
func (m *MethodExpr) Validate() error
Validate validates the method payloads, results, and errors (if any).
type NamedAttributeExpr ¶
type NamedAttributeExpr struct { // Name of attribute Name string // Attribute Attribute *AttributeExpr }
NamedAttributeExpr describes object attributes together with their names.
type Object ¶
type Object []*NamedAttributeExpr
Object is the type used to describe composite data structures. Note: not a map because order matters.
func (*Object) Attribute ¶
func (o *Object) Attribute(name string) *AttributeExpr
Attribute returns the attribute with the given name if any, nil otherwise.
func (*Object) Delete ¶
Delete creates a new object with the same named attributes as o but without the named attribute n if any.
func (*Object) IsCompatible ¶
IsCompatible returns true if o describes the (Go) type of val.
func (*Object) Merge ¶
Merge creates a new object consisting of the named attributes of o appended with duplicates of the named attributes of other. Named attributes of o that have an identical name to named attributes of other get overridden.
func (*Object) Rename ¶
Rename changes the name of the named attribute n to m. Rename does nothing if o does not have an attribute named n.
func (*Object) Set ¶
func (o *Object) Set(n string, att *AttributeExpr)
Set replaces the object named attribute n if any - creates a new object by appending to the slice of named attributes otherwise. The resulting object is returned in both cases.
type Primitive ¶
type Primitive Kind
Primitive is the type for null, boolean, integer, number, string, and time.
func (Primitive) Example ¶
Example generates a pseudo-random primitive value using the given random generator.
func (Primitive) IsCompatible ¶
IsCompatible returns true if val is compatible with p.
type Random ¶
type Random struct { Seed string Seen map[string]*interface{} // contains filtered or unexported fields }
Random generates consistent random values of different types given a seed. The random values are consistent in that given the same seed the same random values get generated. The generator tracks the user types that it has processed to avoid infinite recursions, this means a new generator should be created when wanting to generate a new random value for a user type.
type ResultTypeExpr ¶
type ResultTypeExpr struct { // A result type is a user type *UserTypeExpr // Identifier is the RFC 6838 result type media type identifier. Identifier string // ContentType identifies the value written to the response // "Content-Type" header. ContentType string // Views list the supported views indexed by name. Views []*ViewExpr }
ResultTypeExpr is a user type which describes views used to render responses.
func NewResultTypeExpr ¶
func NewResultTypeExpr(name, identifier string, fn func()) *ResultTypeExpr
NewResultTypeExpr creates a result type definition but does not execute the DSL.
func Project ¶
func Project(m *ResultTypeExpr, view string, seen ...map[string]*AttributeExpr) (*ResultTypeExpr, error)
Project creates a ResultTypeExpr containing the fields defined in the view expression of m named after the view argument.
The resulting result type defines a default view. The result type identifier is computed by adding a parameter called "view" to the original identifier. The value of the "view" parameter is the name of the view.
func (*ResultTypeExpr) Dup ¶
func (m *ResultTypeExpr) Dup(att *AttributeExpr) UserType
Dup creates a deep copy of the result type given a deep copy of its attribute.
func (*ResultTypeExpr) Finalize ¶
func (m *ResultTypeExpr) Finalize()
Finalize builds the default view if not explicitly defined and finalizes the underlying UserTypeExpr.
func (*ResultTypeExpr) HasMultipleViews ¶
func (m *ResultTypeExpr) HasMultipleViews() bool
HasMultipleViews returns true if the result type has more than one view.
func (*ResultTypeExpr) ID ¶
func (m *ResultTypeExpr) ID() string
ID returns the identifier of the result type.
func (*ResultTypeExpr) Name ¶
func (m *ResultTypeExpr) Name() string
Name returns the result type name.
func (*ResultTypeExpr) View ¶
func (m *ResultTypeExpr) View(name string) *ViewExpr
View returns the view with the given name.
func (*ResultTypeExpr) ViewHasAttribute ¶
func (m *ResultTypeExpr) ViewHasAttribute(view, attr string) bool
ViewHasAttribute returns true if the result type view has the given attribute.
type RootExpr ¶
type RootExpr struct { // API contains the API expression built by the DSL. API *APIExpr // Services contains the list of services exposed by the API. Services []*ServiceExpr // Errors contains the list of errors returned by all the API // methods. Errors []*ErrorExpr // Types contains the user types described in the DSL. Types []UserType // ResultTypes contains the result types described in the DSL. ResultTypes []UserType // GeneratedTypes contains the types generated during DSL // execution. GeneratedTypes *GeneratedRoot // Conversions list the user type to external type mappings. Conversions []*TypeMap // Creations list the external type to user type mappings. Creations []*TypeMap // Schemes list the registered security schemes. Schemes []*SchemeExpr // Meta is a set of key/value pairs with semantic that is // specific to each generator. Meta MetaExpr }
RootExpr is the struct built by the DSL on process start.
func (*RootExpr) Finalize ¶
func (r *RootExpr) Finalize()
Finalize finalizes the server expressions.
func (*RootExpr) GeneratedResultType ¶
func (r *RootExpr) GeneratedResultType(id string) *ResultTypeExpr
GeneratedResultType returns the generated result type expression with the given id, nil if there isn't one.
func (*RootExpr) HTTPService ¶
func (r *RootExpr) HTTPService(name string) *HTTPServiceExpr
HTTPService returns the HTTP service with the given name if any.
func (*RootExpr) HTTPServiceFor ¶
func (r *RootExpr) HTTPServiceFor(s *ServiceExpr) *HTTPServiceExpr
HTTPServiceFor creates a new or returns the existing HTTP service definition for the given service.
func (*RootExpr) Service ¶
func (r *RootExpr) Service(name string) *ServiceExpr
Service returns the service with the given name.
func (*RootExpr) UserType ¶
UserType returns the user type expression with the given name if found, nil otherwise.
type RouteExpr ¶
type RouteExpr struct { // Method is the HTTP method, e.g. "GET", "POST", etc. Method string // Path is the URL path e.g. "/tasks/{id}" Path string // Endpoint is the endpoint this route applies to. Endpoint *HTTPEndpointExpr // Meta is an arbitrary set of key/value pairs, see // dsl.Meta Meta MetaExpr }
RouteExpr represents an endpoint route (HTTP endpoint).
func (*RouteExpr) FullPaths ¶
FullPaths returns the endpoint full paths computed by concatenating the service base paths with the route specific path.
func (*RouteExpr) IsAbsolute ¶
IsAbsolute returns true if the endpoint path should not be concatenated to the service and API base paths.
func (*RouteExpr) Params ¶
Params returns all the route parameters across all the base paths. For example for the route "GET /foo/{fooID:foo_id}" Params returns []string{"fooID:foo_id"}.
func (*RouteExpr) Validate ¶
func (r *RouteExpr) Validate() *eval.ValidationErrors
Validate validates a route expression by ensuring that the route parameters can be inferred from the method payload and there is no duplicate parameters in an absolute route.
type SchemeExpr ¶
type SchemeExpr struct { // Kind is the sort of security scheme this object represents. Kind SchemeKind // SchemeName is the name of the security scheme, e.g. "googAuth", // "my_big_token", "jwt". SchemeName string // Description describes the security scheme e.g. "Google OAuth2" Description string // In determines the location of the API key, one of "header" or // "query". In string // Name refers to a header or parameter name, based on In's // value. Name string // Scopes lists the JWT or OAuth2 scopes. Scopes []*ScopeExpr // Flows determine the oauth2 flows supported by this scheme. Flows []*FlowExpr // Meta is a list of key/value pairs Meta MetaExpr }
SchemeExpr defines a security scheme used to authenticate against the method being designed.
func DupScheme ¶
func DupScheme(sch *SchemeExpr) *SchemeExpr
DupScheme creates a copy of the given scheme expression.
func (*SchemeExpr) EvalName ¶
func (s *SchemeExpr) EvalName() string
EvalName returns the generic definition name used in error messages.
func (*SchemeExpr) Hash ¶
func (s *SchemeExpr) Hash() string
Hash returns a unique hash value for s.
func (*SchemeExpr) Validate ¶
func (s *SchemeExpr) Validate() *eval.ValidationErrors
Validate ensures that the method payload contains attributes required by the scheme.
type SchemeKind ¶
type SchemeKind int
SchemeKind is a type of security scheme.
const ( // OAuth2Kind identifies a "OAuth2" security scheme. OAuth2Kind SchemeKind = iota + 1 // BasicAuthKind means "basic" security scheme. BasicAuthKind // APIKeyKind means "apiKey" security scheme. APIKeyKind // JWTKind means an "apiKey" security scheme, with support for // TokenPath and Scopes. JWTKind // NoKind means to have no security for this endpoint. NoKind )
func (SchemeKind) String ¶
func (k SchemeKind) String() string
type ScopeExpr ¶
type ScopeExpr struct { // Name of the scope. Name string // Description is the description of the scope. Description string }
ScopeExpr defines a security scope.
type SecurityExpr ¶
type SecurityExpr struct { // Schemes is the list of security schemes used for this // requirement. Schemes []*SchemeExpr // Scopes list the required scopes if any. Scopes []string }
SecurityExpr defines a security requirement.
func DupRequirement ¶
func DupRequirement(req *SecurityExpr) *SecurityExpr
DupRequirement creates a copy of the given security requirement.
func (*SecurityExpr) EvalName ¶
func (s *SecurityExpr) EvalName() string
EvalName returns the generic definition name used in error messages.
type ServerExpr ¶
type ServerExpr struct { // Name of server Name string // Description of server Description string // Services list the services hosted by the server. Services []string // Hosts list the server hosts. Hosts []*HostExpr }
ServerExpr contains a single API host information.
func (*ServerExpr) EvalName ¶
func (s *ServerExpr) EvalName() string
EvalName is the qualified name of the expression.
func (*ServerExpr) Finalize ¶
func (s *ServerExpr) Finalize()
Finalize initializes the server services and/or host with default values if not set explicitly in the design.
func (*ServerExpr) Schemes ¶
func (s *ServerExpr) Schemes() []string
Schemes returns the list of transport schemes used by all the server endpoints. The possible values for the elements of the returned slice are "http", "https", "grpc" and "grpcs".
func (*ServerExpr) Validate ¶
func (s *ServerExpr) Validate() error
Validate validates the server and server hosts.
type ServiceExpr ¶
type ServiceExpr struct { // DSLFunc contains the DSL used to initialize the expression. eval.DSLFunc // Name of service. Name string // Description of service used in documentation. Description string // Docs points to external documentation Docs *DocsExpr // Methods is the list of service methods. Methods []*MethodExpr // Errors list the errors common to all the service methods. Errors []*ErrorExpr // Requirements contains the security requirements that apply to // all the service methods. One requirement is composed of // potentially multiple schemes. Incoming requests must validate // at least one requirement to be authorized. Requirements []*SecurityExpr // Meta is a set of key/value pairs with semantic that is // specific to each generator. Meta MetaExpr }
ServiceExpr describes a set of related methods.
func (*ServiceExpr) Error ¶
func (s *ServiceExpr) Error(name string) *ErrorExpr
Error returns the error with the given name if any.
func (*ServiceExpr) EvalName ¶
func (s *ServiceExpr) EvalName() string
EvalName returns the generic expression name used in error messages.
func (*ServiceExpr) Finalize ¶
func (s *ServiceExpr) Finalize()
Finalize finalizes all the service methods and errors.
func (*ServiceExpr) Hash ¶
func (s *ServiceExpr) Hash() string
Hash returns a unique hash value for s.
func (*ServiceExpr) Method ¶
func (s *ServiceExpr) Method(n string) *MethodExpr
Method returns the method expression with the given name, nil if there isn't one.
func (*ServiceExpr) Validate ¶
func (s *ServiceExpr) Validate() error
Validate validates the service methods and errors.
type StreamKind ¶
type StreamKind int
StreamKind is a type denoting the kind of stream.
const ( // NoStreamKind represents no payload or result stream in method. NoStreamKind StreamKind = iota + 1 // ClientStreamKind represents client sends a streaming payload to // method. ClientStreamKind // ServerStreamKind represents server sends a streaming result from // method. ServerStreamKind // BidirectionalStreamKind represents client and server sending payload // and result respectively via a stream. BidirectionalStreamKind )
type TypeMap ¶
type TypeMap struct { // User is the user type being converted or created. User UserType // External is an instance of the type being converted from or to. External interface{} }
TypeMap defines a user to external type mapping.
type UserType ¶
type UserType interface { DataType eval.Expression // Finalizes the underlying type. eval.Finalizer // Provides the underlying type and validations. CompositeExpr // ID returns the identifier for the user type. ID() string // Rename changes the type name to the given value. Rename(string) // SetAttribute updates the underlying attribute. SetAttribute(*AttributeExpr) // Dup makes a shallow copy of the type and assigns its // attribute with att. Dup(att *AttributeExpr) UserType // Validate checks that the user type expression is consistent. Validate(ctx string, parent eval.Expression) *eval.ValidationErrors }
UserType is the interface implemented by all user type implementations. Plugins may leverage this interface to introduce their own types.
type UserTypeExpr ¶
type UserTypeExpr struct { // The embedded attribute expression. *AttributeExpr // Name of type TypeName string }
UserTypeExpr describes user defined types.
func NewUserTypeExpr ¶
func NewUserTypeExpr(name string, fn func()) *UserTypeExpr
NewUserTypeExpr creates a user type expression but does not execute the DSL.
func (*UserTypeExpr) Attribute ¶
func (u *UserTypeExpr) Attribute() *AttributeExpr
Attribute returns the embedded attribute.
func (*UserTypeExpr) Dup ¶
func (u *UserTypeExpr) Dup(att *AttributeExpr) UserType
Dup creates a deep copy of the user type given a deep copy of its attribute.
func (*UserTypeExpr) Example ¶
func (u *UserTypeExpr) Example(r *Random) interface{}
Example produces an example for the user type which is JSON serialization compatible.
func (*UserTypeExpr) Hash ¶
func (u *UserTypeExpr) Hash() string
Hash returns a unique hash value for u.
func (*UserTypeExpr) ID ¶
func (u *UserTypeExpr) ID() string
ID returns the identifier (type name) for the user type.
func (*UserTypeExpr) IsCompatible ¶
func (u *UserTypeExpr) IsCompatible(val interface{}) bool
IsCompatible returns true if u describes the (Go) type of val.
func (*UserTypeExpr) Rename ¶
func (u *UserTypeExpr) Rename(n string)
Rename changes the type name to the given value.
func (*UserTypeExpr) SetAttribute ¶
func (u *UserTypeExpr) SetAttribute(att *AttributeExpr)
SetAttribute sets the embedded attribute.
type Val ¶
type Val map[string]interface{}
Val is the type used to provide the value of examples for attributes that are objects.
type ValidationExpr ¶
type ValidationExpr struct { // Values represents an enum validation as described at // http://json-schema.org/latest/json-schema-validation.html#anchor76. Values []interface{} // Format represents a format validation as described at // http://json-schema.org/latest/json-schema-validation.html#anchor104. Format ValidationFormat // PatternValidationExpr represents a pattern validation as // described at // http://json-schema.org/latest/json-schema-validation.html#anchor33 Pattern string // Minimum represents an minimum value validation as described // at // http://json-schema.org/latest/json-schema-validation.html#anchor21. Minimum *float64 // Maximum represents a maximum value validation as described at // http://json-schema.org/latest/json-schema-validation.html#anchor17. Maximum *float64 // MinLength represents an minimum length validation as // described at // http://json-schema.org/latest/json-schema-validation.html#anchor29. MinLength *int // MaxLength represents an maximum length validation as // described at // http://json-schema.org/latest/json-schema-validation.html#anchor26. MaxLength *int // Required list the required fields of object attributes as // described at // http://json-schema.org/latest/json-schema-validation.html#anchor61. Required []string }
ValidationExpr contains validation rules for an attribute.
func (*ValidationExpr) AddRequired ¶
func (v *ValidationExpr) AddRequired(required ...string)
AddRequired merges the required fields into v.
func (*ValidationExpr) Dup ¶
func (v *ValidationExpr) Dup() *ValidationExpr
Dup makes a shallow dup of the validation.
func (*ValidationExpr) HasRequiredOnly ¶
func (v *ValidationExpr) HasRequiredOnly() bool
HasRequiredOnly returns true if the validation only has the Required field with a non-zero value.
func (*ValidationExpr) Merge ¶
func (v *ValidationExpr) Merge(other *ValidationExpr)
Merge merges other into v.
func (*ValidationExpr) RemoveRequired ¶
func (v *ValidationExpr) RemoveRequired(required string)
RemoveRequired removes the given field from the list of required fields.
type ValidationFormat ¶
type ValidationFormat string
ValidationFormat is the type used to enumerate the possible string formats.
type ViewExpr ¶
type ViewExpr struct { // Set of properties included in view *AttributeExpr // Name of view Name string // Parent result Type Parent *ResultTypeExpr }
ViewExpr defines which fields to render when building a response. The view is an object whose field names must match the names of the parent result type field names. The field definitions are inherited from the parent result type but may be overridden.
Source Files ¶
- api.go
- attribute.go
- docs.go
- dup.go
- example.go
- generated.go
- grpc.go
- grpc_endpoint.go
- grpc_error.go
- grpc_response.go
- grpc_service.go
- helpers.go
- http.go
- http_body_types.go
- http_endpoint.go
- http_error.go
- http_file_server.go
- http_response.go
- http_service.go
- init.go
- mapped_attribute.go
- method.go
- random.go
- result_type.go
- root.go
- security.go
- server.go
- service.go
- testing.go
- types.go
- user_type.go