staticschema

package
v0.0.0-...-f03a05a Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

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

Variables

This section is empty.

Functions

This section is empty.

Types

type FieldMetadata

type FieldMetadata struct {
	DisplayName  string           `json:"displayName,omitempty"`
	ValueType    common.ValueType `json:"valueType,omitempty"`
	ProviderType string           `json:"providerType,omitempty"`
	ReadOnly     bool             `json:"readOnly,omitempty"`
	Values       FieldValues      `json:"values,omitempty"`
}

type FieldMetadataMap

type FieldMetadataMap interface {
	FieldMetadataMapV1 | FieldMetadataMapV2
}

type FieldMetadataMapV1

type FieldMetadataMapV1 map[string]string

type FieldMetadataMapV2

type FieldMetadataMapV2 map[string]FieldMetadata

type FieldValue

type FieldValue struct {
	Value        string `json:"value,omitempty"`
	DisplayValue string `json:"displayValue,omitempty"`
}

type FieldValues

type FieldValues []FieldValue

type FileManager

type FileManager[F FieldMetadataMap] struct {
	// contains filtered or unexported fields
}

FileManager operates on schema.json file.

func NewFileManager

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

func (FileManager[F]) MustLoadSchemas

func (m FileManager[F]) MustLoadSchemas() *Metadata[F]

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

func (FileManager[F]) SaveSchemas

func (m FileManager[F]) SaveSchemas(schemas *Metadata[F]) error

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

type Metadata

type Metadata[F FieldMetadataMap] struct {
	// Modules is a map of object names to object metadata
	Modules map[common.ModuleID]Module[F] `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[F FieldMetadataMap]() *Metadata[F]

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

func (*Metadata[F]) Add

func (m *Metadata[F]) Add(
	moduleID common.ModuleID,
	objectName, objectDisplayName, urlPath, responseKey string,
	fieldMetadataMap F,
	docsURL *string,
)

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

func (*Metadata[F]) LookupArrayFieldName

func (m *Metadata[F]) 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[F]) LookupModuleURLPath

func (m *Metadata[F]) LookupModuleURLPath(moduleID common.ModuleID) string

func (*Metadata[F]) LookupURLPath

func (m *Metadata[F]) 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[F]) ModuleRegistry

func (m *Metadata[F]) ModuleRegistry() common.Modules

ModuleRegistry returns the list of API modules from static schema.

func (*Metadata[F]) ObjectNames

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

ObjectNames provides a registry of object names grouped by module.

func (*Metadata[F]) Select

func (m *Metadata[F]) 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[F]) SelectOne

func (m *Metadata[F]) 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[F FieldMetadataMap] struct {
	ID      common.ModuleID      `json:"id"`
	Path    string               `json:"path"`
	Objects map[string]Object[F] `json:"objects"`
}

type Object

type Object[F FieldMetadataMap] 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"`

	// Fields is a map of field names to either field display names or extended field metadata.
	Fields F `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