Documentation
¶
Overview ¶
Package holds higher-level abstractions on top of OpenAPI that are used to generate code via text/template for Databricks SDK in different languages.
Index ¶
- Variables
- type Batch
- type Binding
- type Entity
- func (e *Entity) CamelName() string
- func (e *Entity) Enum() (enum []EnumEntry)
- func (e *Entity) Field(name string) *Field
- func (e *Entity) Fields() (fields []*Field)
- func (e *Entity) FullName() string
- func (e *Entity) GetUnderlyingFields(path []string) ([]*Field, error)
- func (e *Entity) HasJsonField() bool
- func (e *Entity) HasQueryField() bool
- func (e *Entity) HasRequiredNonBodyField() bool
- func (e *Entity) IsAllRequiredFieldsPrimitive() bool
- func (e *Entity) IsExternal() bool
- func (e *Entity) IsNumber() bool
- func (e *Entity) IsObject() bool
- func (e *Entity) IsOnlyPrimitiveFields() bool
- func (e *Entity) IsPrimitive() bool
- func (e *Entity) IsPrivatePreview() bool
- func (e *Entity) IsPublicPreview() bool
- func (e *Entity) IsReferred() bool
- func (e *Entity) IsRequest() bool
- func (e *Entity) IsResponse() bool
- func (e *Entity) NonRequiredFields() (fields []*Field)
- func (e *Entity) PascalName() string
- func (e *Entity) RequiredFields() (fields []*Field)
- func (e *Entity) Traverse(fn func(*Entity))
- type EnumEntry
- type Field
- type Method
- func (m *Method) AsFlat() *Named
- func (m *Method) CanHaveResponseBody() bool
- func (m *Method) CmdletName(prefix string) string
- func (m *Method) GetByName() *Entity
- func (m *Method) HasIdentifierField() bool
- func (m *Method) HasNameField() bool
- func (m *Method) IdentifierField() *Field
- func (m *Method) IsCrudCreate() bool
- func (m *Method) IsCrudRead() bool
- func (m *Method) IsJsonOnly() bool
- func (m *Method) IsPrivatePreview() bool
- func (m *Method) IsPublicPreview() bool
- func (m *Method) NamedIdMap() *NamedIdMap
- func (m *Method) NeedsOffsetDedupe() bool
- func (m *Method) Pagination() *Pagination
- func (m *Method) Shortcut() *Shortcut
- func (m *Method) TitleVerb() string
- func (m *Method) Wait() *Wait
- type Named
- func (n *Named) AbbrName() string
- func (n *Named) CamelName() string
- func (n *Named) Comment(prefix string, maxLen int) string
- func (n *Named) ConstantName() string
- func (n *Named) DescriptionWithoutSummary() string
- func (n *Named) HasComment() bool
- func (n *Named) IsNameReserved() bool
- func (n *Named) KebabName() string
- func (n *Named) PascalName() string
- func (n *Named) Singular() *Named
- func (n *Named) SnakeName() string
- func (n *Named) Summary() string
- func (n *Named) TitleName() string
- func (n *Named) TrimPrefix(prefix string) *Named
- type NamedIdMap
- type Package
- func (pkg *Package) EmptyTypes() (types []*Named)
- func (pkg *Package) FullName() string
- func (pkg *Package) HasPagination() bool
- func (pkg *Package) HasPathParams() bool
- func (pkg *Package) HasWaits() bool
- func (pkg *Package) ImportedEntities() (res []*Entity)
- func (pkg *Package) ImportedPackages() (res []string)
- func (pkg *Package) Load(spec *openapi.Specification, tag openapi.Tag) error
- func (pkg *Package) MainService() *Service
- func (pkg *Package) Services() (types []*Service)
- func (pkg *Package) Types() (types []*Entity)
- type Pagination
- type PathPart
- type Service
- func (svc *Service) Create() *Method
- func (svc *Service) Delete() *Method
- func (svc *Service) FullName() string
- func (svc *Service) HasPagination() bool
- func (svc *Service) HasWaits() bool
- func (svc *Service) IsPrivatePreview() bool
- func (svc *Service) IsPublicPreview() bool
- func (svc *Service) List() *Method
- func (svc *Service) MatchesPackageName() bool
- func (svc *Service) Methods() (methods []*Method)
- func (svc *Service) Read() *Method
- func (svc *Service) Update() *Method
- func (svc *Service) Waits() (waits []*Wait)
- type Shortcut
- type Wait
- func (w *Wait) Binding() (binding []Binding)
- func (w *Wait) ComplexMessagePath() bool
- func (w *Wait) Failure() (match []EnumEntry)
- func (w *Wait) ForceBindRequest() bool
- func (w *Wait) MessagePath() (path []*Field)
- func (w *Wait) MessagePathHead() *Field
- func (w *Wait) Poll() *Method
- func (w *Wait) Status() *Field
- func (w *Wait) StatusPath() (path []*Field)
- func (w *Wait) Success() (match []EnumEntry)
- func (w *Wait) Timeout() int
Constants ¶
This section is empty.
Variables ¶
var ErrSkipThisFile = errors.New("skip generating this file")
var HelperFuncs = template.FuncMap{ "notLast": func(idx int, a interface{}) bool { return idx+1 != reflect.ValueOf(a).Len() }, "lower": strings.ToLower, "lowerFirst": func(s string) string { return strings.ToLower(s[0:1]) + s[1:] }, "trimPrefix": func(right, left string) string { return strings.TrimPrefix(left, right) }, "trimSuffix": func(right, left string) string { return strings.TrimSuffix(left, right) }, "replaceAll": func(from, to, str string) string { return strings.ReplaceAll(str, from, to) }, "without": func(left, right string) string { return strings.ReplaceAll(right, left, "") }, "skipThisFile": func() error { panic(ErrSkipThisFile) }, "alphanumOnly": func(in []*Field) (out []*Field) { for _, v := range in { if !alphanumRE.MatchString(v.Name) { continue } out = append(out, v) } return out }, "list": func(l ...any) []any { return l }, "in": func(haystack []any, needle string) bool { for _, v := range haystack { if needle == fmt.Sprint(v) { return true } } return false }, "dict": func(args ...any) map[string]any { if len(args)%2 != 0 { panic("number of arguments to dict is not even") } result := map[string]any{} for i := 0; i < len(args); i += 2 { k := fmt.Sprint(args[i]) v := args[i+1] result[k] = v } return result }, "getOrDefault": func(dict map[string]any, key string, def any) any { v, ok := dict[key] if ok { return v } return def }, "fmt": fmt.Sprintf, "concat": func(v ...string) string { return strings.Join(v, "") }, }
Functions ¶
This section is empty.
Types ¶
type Batch ¶
type Batch struct {
// contains filtered or unexported fields
}
func NewFromFile ¶
NewFromFile loads OpenAPI specification from file
func NewFromSpec ¶ added in v0.13.0
func NewFromSpec(spec *openapi.Specification) (*Batch, error)
NewFromSpec converts OpenAPI spec to intermediate representation
type Binding ¶
type Binding struct {
// Polling method request field
PollField *Field
// Wrapped method either response or request body field
Bind *Field
// Is wrapped method response used?
IsResponseBind bool
}
Binding connects fields in generated code across multiple requests
type Entity ¶
type Entity struct {
Named
Package *Package
ArrayValue *Entity
MapValue *Entity
IsInt bool
IsInt64 bool
IsFloat64 bool
IsBool bool
IsString bool
IsEmpty bool
// this field does not have a concrete type
IsAny bool
// this field is computed on the platform side
IsComputed bool
// if entity has required fields, this is the order of them
RequiredOrder []string
// Schema references the OpenAPI schema this entity was created from.
Schema *openapi.Schema
// contains filtered or unexported fields
}
Entity represents a Type
func (*Entity) CamelName ¶
CamelName overrides parent implementation by appending List suffix for unnamed list types
func (*Entity) GetUnderlyingFields ¶ added in v0.13.0
Given a list of field names, return the list of *Field objects which result from following the path of fields in the entity.
func (*Entity) HasJsonField ¶ added in v0.2.0
HasJsonField returns true if any of the fields is in the body
func (*Entity) HasQueryField ¶ added in v0.2.0
HasQueryField returns true if any of the fields is from query
func (*Entity) HasRequiredNonBodyField ¶ added in v0.13.0
func (*Entity) IsAllRequiredFieldsPrimitive ¶ added in v0.10.0
func (*Entity) IsExternal ¶
IsExternal returns true if entity is declared in external package and has to be imported from it
func (*Entity) IsObject ¶
IsObject returns true if entity is not a Mpa and has more than zero fields
func (*Entity) IsOnlyPrimitiveFields ¶ added in v0.2.0
func (*Entity) IsPrimitive ¶ added in v0.2.0
func (*Entity) IsPrivatePreview ¶ added in v0.10.0
IsPrivatePreview flags object being in private preview.
func (*Entity) IsPublicPreview ¶ added in v0.10.0
IsPublicPreview flags object being in public preview.
func (*Entity) IsReferred ¶ added in v0.13.0
func (*Entity) IsResponse ¶ added in v0.13.0
func (*Entity) NonRequiredFields ¶ added in v0.2.0
func (*Entity) PascalName ¶
PascalName overrides parent implementation by appending List suffix for unnamed list types
func (*Entity) RequiredFields ¶ added in v0.2.0
type Field ¶
type Field struct {
Named
Required bool
Entity *Entity
Of *Entity
IsJson bool
IsPath bool
IsQuery bool
Schema *openapi.Schema
}
Field of a Type (Entity)
func (*Field) IsOptionalObject ¶
func (*Field) IsPrivatePreview ¶ added in v0.10.0
IsPrivatePreview flags object being in private preview.
func (*Field) IsPublicPreview ¶ added in v0.10.0
IsPublicPreview flags object being in public preview.
type Method ¶
type Method struct {
Named
Service *Service
// HTTP method name
Verb string
// Full API Path, including /api/2.x prefix
Path string
// Slice of path params, e.g. permissions/{type}/{id}
PathParts []PathPart
// Request type representation
Request *Entity
// Response type representation
Response *Entity
EmptyResponseName Named
// The style of the request, either "rpc" or "rest". See the documentation on
// Operation for more details.
PathStyle openapi.PathStyle
// For list APIs, the path of fields in the response entity to follow to get
// the resource ID.
IdFieldPath []*Field
// For list APIs, the path of fields in the response entity to follow to get
// the user-friendly name of the resource.
NameFieldPath []*Field
// contains filtered or unexported fields
}
Method represents service RPC
func (*Method) CanHaveResponseBody ¶
func (*Method) CmdletName ¶ added in v0.16.0
func (*Method) GetByName ¶
GetByName returns entity from the same service with x-databricks-crud:read
func (*Method) HasIdentifierField ¶ added in v0.13.0
func (*Method) HasNameField ¶ added in v0.13.0
func (*Method) IdentifierField ¶ added in v0.13.0
func (*Method) IsCrudCreate ¶ added in v0.10.0
func (*Method) IsCrudRead ¶ added in v0.2.0
func (*Method) IsJsonOnly ¶ added in v0.10.1
func (*Method) IsPrivatePreview ¶ added in v0.10.0
IsPrivatePreview flags object being in private preview.
func (*Method) IsPublicPreview ¶ added in v0.10.0
IsPublicPreview flags object being in public preview.
func (*Method) NamedIdMap ¶
func (m *Method) NamedIdMap() *NamedIdMap
NamedIdMap returns name-to-id mapping retrieval definition for all entities of a type
func (*Method) NeedsOffsetDedupe ¶ added in v0.13.0
func (*Method) Pagination ¶
func (m *Method) Pagination() *Pagination
Pagination returns definition for possibly multi-request result iterator
type Named ¶
Named holds common methods for identifying and describing things
func (*Named) Comment ¶
Comment formats description into language-specific comment multi-line strings
func (*Named) ConstantName ¶
ConstantName creates NAMES_LIKE_THIS
func (*Named) DescriptionWithoutSummary ¶ added in v0.2.0
func (*Named) HasComment ¶
func (*Named) IsNameReserved ¶
func (*Named) Summary ¶ added in v0.2.0
Summary gets the first sentence from the description. Always ends in a dot.
func (*Named) TrimPrefix ¶ added in v0.8.0
TrimPrefix returns *Named, but with a prefix trimmed from CamelName()
Example:
(&Named{Name: "AccountMetastoreAssigment"}).TrimPrefix("account").CamelName() == "metastoreAssignment"
type NamedIdMap ¶
type NamedIdMap struct {
Named
IdPath []*Field
NamePath []*Field
Entity *Entity
// if List method returns []Item directly
// without generated iteration wrapper
Direct bool
}
NamedIdMap depends on Pagination and is generated, when paginated item entity has Identifier and Name fields. End-users usually use this method for drop-downs or any other selectors.
func (*NamedIdMap) Id ¶
func (n *NamedIdMap) Id() *Field
type Package ¶
type Package struct {
Named
Components *openapi.Components
// contains filtered or unexported fields
}
Package represents a service package, which contains entities and interfaces that are relevant to a single service
func (*Package) EmptyTypes ¶
EmptyTypes returns sorted list of types without fields
func (*Package) HasPagination ¶
HasPagination returns try if any service within this package has result iteration
func (*Package) HasPathParams ¶
HasPathParams returns true if any service has methods that rely on path params
func (*Package) HasWaits ¶
HasWaits returns true if any service has methods with long-running operations
func (*Package) ImportedEntities ¶
func (*Package) ImportedPackages ¶
func (*Package) MainService ¶ added in v0.2.0
MainService returns a Service that matches Package name
type Pagination ¶
type Pagination struct {
Offset *Field
Limit *Field
Results *Field
Entity *Entity
Token *Binding
Increment int
}
Pagination holds definition of result iteration type per specific RPC. Databricks as of now has a couple different types of pagination:
- next_token/next_page_token + repeated field
- offset/limit with zero-based offsets + repeated field
- page/limit with 1-based pages + repeated field
- repeated inline field
- repeated field
func (*Pagination) MultiRequest ¶
func (p *Pagination) MultiRequest() bool
type Service ¶
type Service struct {
Named
PathStyle openapi.PathStyle
IsAccounts bool
Package *Package
ByPathParamsMethods []*Shortcut
// contains filtered or unexported fields
}
Service represents specific Databricks API
func (*Service) Create ¶ added in v0.2.0
List returns a method annotated with x-databricks-crud:create
func (*Service) Delete ¶ added in v0.2.0
List returns a method annotated with x-databricks-crud:delete
func (*Service) HasPagination ¶
HasPagination returns true if any method has result iteration
func (*Service) IsPrivatePreview ¶ added in v0.10.0
IsPrivatePreview flags object being in private preview.
func (*Service) IsPublicPreview ¶ added in v0.10.0
IsPublicPreview flags object being in public preview.
func (*Service) MatchesPackageName ¶
MatchesPackageName if package name and service name are the same, e.g. `clusters` package & `Clusters` service
type Shortcut ¶
Shortcut holds definition of "shortcut" methods, that are generated for methods with request entities only with required fields.
type Wait ¶
type Wait struct {
Named
// represents a method that triggers the start of the long-running operation
Method *Method
}
Wait represents a long-running operation, that requires multiple RPC calls
func (*Wait) ComplexMessagePath ¶
func (*Wait) ForceBindRequest ¶
ForceBindRequest is a workaround for Jobs#RepairRun, that does not send run_id in response
func (*Wait) MessagePath ¶
MessagePath holds the path to the field of polled entity, that can tell about current inner status of the long-running operation
func (*Wait) MessagePathHead ¶
func (*Wait) Poll ¶
Poll returns method definition for checking the state of the long running operation
func (*Wait) StatusPath ¶
StatusPath holds the path to the field of polled entity, that holds current state of the long-running operation