Documentation ¶
Index ¶
- Variables
- func CamelCaseToSpaceSeparated(displayName string) string
- func CapitalizeFirstLetterEveryWord(displayName string) string
- func DataObjectLocator(objectName, fieldName string) bool
- func IdenticalObjectLocator(objectName, fieldName string) bool
- func OnlyOptionalQueryParameters(objectName string, operation *openapi3.Operation) bool
- func Pluralize(displayName string) string
- type DisplayNameProcessor
- type Document
- type Explorer
- func (e Explorer) GetPathItems(pathMatcher PathMatcher, endpointResources map[string]string) []PathItem
- func (e Explorer) ReadObjects(operationName string, pathMatcher PathMatcher, ...) (Schemas, error)
- func (e Explorer) ReadObjectsGet(pathMatcher PathMatcher, objectEndpoints map[string]string, ...) (Schemas, error)
- func (e Explorer) ReadObjectsPost(pathMatcher PathMatcher, objectEndpoints map[string]string, ...) (Schemas, error)
- type ObjectArrayLocator
- type OpenapiFileManager
- type Option
- type PathItem
- type PathMatcher
- type PropertyFlattener
- type ReadOperationMethodFilter
- type Schema
- type Schemas
- type StarRulePathResolver
Constants ¶
This section is empty.
Variables ¶
var ErrUnprocessableObject = errors.New("don't know how to process schema")
Functions ¶
func CamelCaseToSpaceSeparated ¶
CamelCaseToSpaceSeparated converts camel case into lower case space separated string.
func CapitalizeFirstLetterEveryWord ¶
CapitalizeFirstLetterEveryWord makes all words start with capital except some prepositions.
func DataObjectLocator ¶
DataObjectLocator item schema within response is always stored under the data field. Ex: requesting contacts or leads or users will return payload with {"data":[...]}.
func IdenticalObjectLocator ¶
IdenticalObjectLocator item schema within response is stored under matching object name. Ex: requesting contacts will return payload with {"contacts":[...]}.
func OnlyOptionalQueryParameters ¶
OnlyOptionalQueryParameters operation must include only optional query parameters.
Types ¶
type DisplayNameProcessor ¶
DisplayNameProcessor allows to format Display Names.
type Document ¶
type Document struct {
// contains filtered or unexported fields
}
Document is a wrapper of openapi with null checks.
type Explorer ¶
type Explorer struct {
// contains filtered or unexported fields
}
Explorer allows to traverse schema in most common ways relevant for connectors metadata extraction.
func NewExplorer ¶
NewExplorer creates explorer on openAPI v3 file. See Option to discover how explorer can be customized.
func (Explorer) GetPathItems ¶
func (e Explorer) GetPathItems( pathMatcher PathMatcher, endpointResources map[string]string, ) []PathItem
GetPathItems returns path items where object name is a single word.
func (Explorer) ReadObjects ¶
func (e Explorer) ReadObjects( operationName string, pathMatcher PathMatcher, objectEndpoints map[string]string, displayNameOverride map[string]string, locator ObjectArrayLocator, ) (Schemas, error)
ReadObjects will explore OpenAPI file returning list of Schemas. See every parameter for detailed customization.
operationName - under which REST operation the schema resides. Ex: GET - list reading, POST - search reading. pathMatcher - guides which URL paths to include in search or to ignore. objectEndpoints - URL path mapped to ObjectName. Ex: /customer/orders -> orders.
Note: deep connector would need to do the reverse mapping to reconstruct URL given orders objectName.
displayNameOverride - objectName mapped to custom Display name. locator - callback that returns true if fieldName matched the target location of Object in response. Ex: if (objectName == orders && fieldName == data) => true
Given response with fields {meta{}, data{}, pagination{}} for orders object, the implementation indicates that schema will be located under `data`.
func (Explorer) ReadObjectsGet ¶
func (e Explorer) ReadObjectsGet( pathMatcher PathMatcher, objectEndpoints map[string]string, displayNameOverride map[string]string, locator ObjectArrayLocator, ) (Schemas, error)
ReadObjectsGet is the same as ReadObjectsGet but retrieves schemas for endpoints that perform reading via GET. If you need schemas located under GET and POST operations, make 2 calls as they will have different arguments in particular PathMatchingStrategy, and then Combine two lists of schemas.
func (Explorer) ReadObjectsPost ¶
func (e Explorer) ReadObjectsPost( pathMatcher PathMatcher, objectEndpoints map[string]string, displayNameOverride map[string]string, locator ObjectArrayLocator, ) (Schemas, error)
ReadObjectsPost is the same as ReadObjectsGet but retrieves schemas for endpoints that perform reading via POST.
type ObjectArrayLocator ¶
ObjectArrayLocator is a procedure that decides if field name is related to the object name. Below you can find the common cases.
func CustomMappingObjectCheck ¶
func CustomMappingObjectCheck(dict datautils.DefaultMap[string, string]) ObjectArrayLocator
CustomMappingObjectCheck builds ObjectArrayLocator using mapping, which knows exceptions and patterns to determine response field name.
Ex:
CustomMappingObjectCheck(datautils.NewDefaultMap(map[string]string{ "orders": "orders", "carts": "carts", "coupons": "coupons", }, func(key string) string { return "data" }))
This can be understood as follows: orders, carts, coupons REST resources will be found under JSON response field matching "it's name", while the rest will be located under "data" field.
type OpenapiFileManager ¶
type OpenapiFileManager struct {
// contains filtered or unexported fields
}
OpenapiFileManager locates openapi file. Allows to read data of interest. Use it when dealing with OpenAPI v3.
func NewOpenapiFileManager ¶
func NewOpenapiFileManager(file []byte) *OpenapiFileManager
func (OpenapiFileManager) GetExplorer ¶
func (m OpenapiFileManager) GetExplorer(opts ...Option) (*Explorer, error)
type Option ¶
type Option = func(params *parameters)
func WithDisplayNamePostProcessors ¶
func WithDisplayNamePostProcessors(processors ...DisplayNameProcessor) Option
WithDisplayNamePostProcessors will apply processors in the given order.
func WithMediaType ¶
WithMediaType picks which media type which should be used when searching schemas in API response. By default, schema is expected to be under "application/json" media response.
func WithParameterFilterGetMethod ¶
func WithParameterFilterGetMethod(parameterFilter ReadOperationMethodFilter) Option
WithParameterFilterGetMethod adds custom callback to decide if GET operation should be included based on parameters definitions.
func WithPropertyFlattening ¶
func WithPropertyFlattening(propertyFlattener PropertyFlattener) Option
WithPropertyFlattening allows nested fields to be moved to the top level. There are some APIs that hold fields of interest under grouping object, the nested object. This configuration flattens response schema fields. Please, have a look at PropertyFlattener documentation.
type PathItem ¶
type PathItem struct {
// contains filtered or unexported fields
}
func (PathItem) RetrieveSchemaOperation ¶
func (p PathItem) RetrieveSchemaOperation( operationName string, displayNameOverride map[string]string, locator ObjectArrayLocator, displayProcessor DisplayNameProcessor, operationMethodFilter ReadOperationMethodFilter, propertyFlattener PropertyFlattener, mime string, ) (*Schema, bool, error)
type PathMatcher ¶
type PropertyFlattener ¶
PropertyFlattener is used to inherit fields from nested object moving them to the top level. Ex:
{ "a":1, "b":2, "grouping": { "c":3, "d":4, }, "e":5 }
If we return true on "grouping" fieldName then it will be flattened with the resulting list of fields becoming "a", "b", "c", "d", "e".
type ReadOperationMethodFilter ¶
ReadOperationMethodFilter callback that filters REST operations based on endpoint parameters.
type Schema ¶
type StarRulePathResolver ¶
type StarRulePathResolver struct {
// contains filtered or unexported fields
}
StarRulePathResolver will report if path matches endpoint rule. Match can occur in 3 different ways, * exact value is inside the registry * or using star rule for
- prefix matching,
- suffix matching.
func NewAllowPathStrategy ¶
func NewAllowPathStrategy(paths []string) *StarRulePathResolver
NewAllowPathStrategy produces a path matching strategy that will accept only those paths that matched the list. Others will be denied. You can use star symbol to create a wild matcher. Ex: Basic: /v1/orders - matches exact path Suffix: */batch - matches paths ending with batch Prefix: /v2/* - matches paths starting with v2.
func NewDenyPathStrategy ¶
func NewDenyPathStrategy(paths []string) *StarRulePathResolver
NewDenyPathStrategy produces a path matching strategy that will deny only those paths that matched the list. Others will be allowed. You can use star symbol to create a wild matcher. Ex: Basic: /v1/orders - deny exact path Suffix: */batch - deny paths ending with batch Prefix: /v2/* - deny paths starting with v2.
func (StarRulePathResolver) IsPathMatching ¶
func (s StarRulePathResolver) IsPathMatching(path string) bool