diff --git a/models/meshmodel/core/v1alpha1/component.go b/models/meshmodel/core/v1alpha1/component.go index b606a340..076d3de9 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,18 @@ func (c ComponentDefinition) Type() types.CapabilityType { func (c ComponentDefinition) GetID() uuid.UUID { return c.ID } - +func emptySchemaCheck(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 +74,9 @@ func CreateComponent(db *database.Handler, c ComponentDefinition) (uuid.UUID, er if err != nil { return uuid.UUID{}, err } + if !emptySchemaCheck(c.Schema) { + c.Metadata["hasInvalidSchema"] = true + } modelID := uuid.NewSHA1(uuid.UUID{}, byt) var model Model modelCreationLock.Lock() @@ -138,6 +152,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 +164,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 diff --git a/models/meshmodel/core/v1alpha1/models.go b/models/meshmodel/core/v1alpha1/models.go index 2095879e..279e725f 100644 --- a/models/meshmodel/core/v1alpha1/models.go +++ b/models/meshmodel/core/v1alpha1/models.go @@ -9,7 +9,7 @@ import ( var modelCreationLock sync.Mutex //Each component/relationship will perform a check and if the model already doesn't exist, it will create a model. This lock will make sure that there are no race conditions. type ModelFilter struct { Name string - DisplayName string //If Name is already passed, avoid passing Display name unless greedy=true, else the filter will translate to an AND returning only the models where name and display name match exactly. Ignore, if this behaviour is expected. + DisplayName string //If Name is already passed, avoid passing Display name unless greedy=true, else the filter will translate to an AND returning only the models where name and display name match exactly. Ignore, if this behavior is expected. Greedy bool //when set to true - instead of an exact match, name will be prefix matched. Also an OR will be performed of name and display_name Version string Category string