-
Notifications
You must be signed in to change notification settings - Fork 9
Closed
Description
Problem Statement
Currently, many models (e.g., FileModel in attachment-api/file.go) manually implement Get methods for every property, leading to significant boilerplate for type conversion and BackingStore interaction. While a generic solution exists in internal/store (DefaultBackedModelAccessorFunc), it is not yet universally adopted across the SDK.
Current Implementation Status
We have implemented:
internal/store.DefaultBackedModelAccessorFunc[S, T]
These are successfully used in several models, but older models like FileModel still use manual GetBackingStore().Get calls with explicit type assertions and error handling.
Proposed Solution
- Adopt Generic Accessors SDK-wide: Refactor all existing models to use the generic accessor functions from
internal/store. - Rename for Brevity (Optional): Consider aliasing these to shorter names like
ModelAccessoras originally proposed to improve readability. - Consistency: Ensure all models inherit from a common base (like
internal.BaseModel) to guaranteeBackingStoreavailability.
Example Refactor (FileModel)
From:
func (f *FileModel) GetSysID() (*string, error) {
val, err := f.GetBackingStore().Get(sysIDKey)
if err != nil {
return nil, err
}
if val == nil {
return nil, nil
}
res, ok := val.(*string)
if !ok {
return nil, errors.New("type mismatch")
}
return res, nil
}To:
func (f *FileModel) GetSysID() (*string, error) {
return store.DefaultBackedModelAccessorFunc[kiotaStore.BackingStore, *string](f.GetBackingStore(), sysIDKey)
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels