staticschema

package
v0.0.0-...-1301960 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const RootModuleID common.ModuleID = "root"
View Source
const SchemasFile = "schemas.json"

Variables

View Source
var ErrObjectNotFound = errors.New("object not found")

Functions

This section is empty.

Types

type FileManager

type FileManager struct {
	// contains filtered or unexported fields
}

FileManager operates on schema.json file.

func NewFileManager

func NewFileManager(schemas []byte, locator fileconv.FileLocator) *FileManager

func (FileManager) MustLoadSchemas

func (m FileManager) MustLoadSchemas() *Metadata

MustLoadSchemas parses static schema file and returns Metadata for deep connector.

func (FileManager) SaveSchemas

func (m FileManager) SaveSchemas(schemas *Metadata) error

SaveSchemas is useful method when creating or updating static schema file.

type Metadata

type Metadata struct {
	// Modules is a map of object names to object metadata
	Modules map[common.ModuleID]Module `json:"modules"`
}

Metadata is data that is saved in the static file.

This structure offers the following main methods: Metadata.ObjectNames - registry of object names by modules. Metadata.LookupURLPath - resolves URL given object name. Metadata.Select - produces output suitable for connectors.ObjectMetadataConnector.

func NewMetadata

func NewMetadata() *Metadata

NewMetadata constructs empty Metadata. To populate it with data use Metadata.Add method.

func (*Metadata) Add

func (r *Metadata) Add(
	moduleID common.ModuleID,
	objectName, objectDisplayName, fieldName, urlPath, responseKey string,
	docsURL *string,
)

Add will appropriately store the data, abiding to data structure rules. NOTE: empty module id is treated as root module.

func (*Metadata) LookupArrayFieldName

func (r *Metadata) LookupArrayFieldName(moduleID common.ModuleID, objectName string) string

LookupArrayFieldName will give you the field name which holds the array of objects in provider response. Ex: CustomerSubscriptions is located under field name subscriptions => { "subscriptions": [{},{},{}] }.

func (*Metadata) LookupModuleURLPath

func (r *Metadata) LookupModuleURLPath(moduleID common.ModuleID) string

func (*Metadata) LookupURLPath

func (r *Metadata) LookupURLPath(moduleID common.ModuleID, objectName string) (string, error)

LookupURLPath will give you the URL path for the object located under the module. NOTE: empty module id is treated as root module.

func (*Metadata) ModuleRegistry

func (r *Metadata) ModuleRegistry() common.Modules

ModuleRegistry returns the list of API modules from static schema.

func (*Metadata) ObjectNames

func (r *Metadata) ObjectNames() datautils.UniqueLists[common.ModuleID, string]

ObjectNames provides a registry of object names grouped by module.

func (*Metadata) Select

func (r *Metadata) Select(
	moduleID common.ModuleID, objectNames []string,
) (*common.ListObjectMetadataResult, error)

Select will look for object names under the module and will return metadata result for those objects. NOTE: empty module id is treated as root module.

func (*Metadata) SelectOne

func (r *Metadata) SelectOne(
	moduleID common.ModuleID, objectName string,
) (*common.ObjectMetadata, error)

SelectOne reads one object metadata from the static file. NOTE: empty module id is treated as root module.

type Module

type Module struct {
	ID      common.ModuleID   `json:"id"`
	Path    string            `json:"path"`
	Objects map[string]Object `json:"objects"`
}

type Object

type Object struct {
	// Provider's display name for the object
	DisplayName string `json:"displayName"`

	// This is the endpoint URLPath to this REST API resource/object.
	// It can be used to make request to "list objects".
	URLPath string `json:"path"`

	// A field name where the object is located within provider response.
	ResponseKey string `json:"responseKey"`

	// FieldsMap is a map of field names to field display names
	FieldsMap map[string]string `json:"fields"`

	// DocsURL points to docs endpoint. Optional.
	DocsURL *string `json:"docs,omitempty"`
}

Jump to

Keyboard shortcuts

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