diff --git a/models/meshmodel/core/v1alpha1/component.go b/models/meshmodel/core/v1alpha1/component.go index b606a340..6f4645bd 100644 --- a/models/meshmodel/core/v1alpha1/component.go +++ b/models/meshmodel/core/v1alpha1/component.go @@ -33,7 +33,7 @@ type ComponentDefinition struct { Format ComponentFormat `json:"format" yaml:"format"` Metadata map[string]interface{} `json:"metadata" yaml:"metadata"` Model Model `json:"model"` - Schema string `json:"schema" yaml:"schema"` + Schema string `json:"schema,omitempty" yaml:"schema"` CreatedAt time.Time `json:"-"` UpdatedAt time.Time `json:"-"` } @@ -44,7 +44,7 @@ type ComponentDefinitionDB struct { DisplayName string `json:"displayName" gorm:"displayName"` Format ComponentFormat `json:"format" yaml:"format"` Metadata []byte `json:"metadata" yaml:"metadata"` - Schema string `json:"schema" yaml:"schema"` + Schema string `json:"schema,omitempty" yaml:"schema"` CreatedAt time.Time `json:"-"` UpdatedAt time.Time `json:"-"` } @@ -55,7 +55,19 @@ func (c ComponentDefinition) Type() types.CapabilityType { func (c ComponentDefinition) GetID() uuid.UUID { return c.ID } +func schemaValidationCheck(schema string) (valid bool) { + if schema == "" { + return + } + m := make(map[string]interface{}) + _ = json.Unmarshal([]byte(schema), &m) + if m["properties"] == nil { + return + } + valid = true + return +} func CreateComponent(db *database.Handler, c ComponentDefinition) (uuid.UUID, error) { c.ID = uuid.New() tempModelID := uuid.New() @@ -63,6 +75,9 @@ func CreateComponent(db *database.Handler, c ComponentDefinition) (uuid.UUID, er if err != nil { return uuid.UUID{}, err } + if !schemaValidationCheck(c.Schema) { + c.Metadata["hasInvalidSchema"] = true + } modelID := uuid.NewSHA1(uuid.UUID{}, byt) var model Model modelCreationLock.Lock() @@ -138,6 +153,9 @@ func GetMeshModelComponents(db *database.Handler, f ComponentFilter) (c []Compon fmt.Println(err.Error()) //for debugging } for _, cm := range componentDefinitionsWithModel { + if f.Trim { + cm.Schema = "" + } c = append(c, cm.ComponentDefinitionDB.GetComponentDefinition(cm.Model)) } return c @@ -147,6 +165,7 @@ type ComponentFilter struct { Name string APIVersion string Greedy bool //when set to true - instead of an exact match, name will be prefix matched + Trim bool //when set to true - the schema is not returned DisplayName string ModelName string Version string