Skip to content

Commit

Permalink
Check for mapKey schema field
Browse files Browse the repository at this point in the history
Return error when needed mapKey schema field is not set.

Change-Id: I48e1c08ee9cace27448fbe6f32e15b75b0576a62
Partial-Bug: #1785278
  • Loading branch information
Daniel Furman committed Aug 27, 2018
1 parent e3231e2 commit 35334ed
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
12 changes: 6 additions & 6 deletions pkg/db/cassandra/cassandra.go
Expand Up @@ -435,12 +435,12 @@ func NewAmqpEventProcessor() *AmqpEventProcessor {

//AmqpMessage type
type AmqpMessage struct {
RequestID string `json:"request_id"`
Oper string `json:"oper"`
Type string `json:"type"`
UUID string `json:"uuid"`
FqName []string `json:"fq_name"`
Data json.RawMessage `json:"obj_dict"`
RequestID string `json:"request_id"`
Oper string `json:"oper"`
Type string `json:"type"`
UUID string `json:"uuid"`
FqName []string `json:"fq_name"`
Data json.RawMessage `json:"obj_dict"`
}

//Process sends msg to amqp exchange
Expand Down
16 changes: 11 additions & 5 deletions pkg/schema/schema.go
Expand Up @@ -693,7 +693,7 @@ func (api *API) resolveExtend() error {

func (api *API) resolveCollectionTypes() error {
for _, s := range api.Schemas {
for _, property := range s.JSONSchema.Properties {
for propertyName, property := range s.JSONSchema.Properties {
if property.CollectionType != "" {
propertyType := api.Types[property.ProtoType]

Expand All @@ -703,7 +703,9 @@ func (api *API) resolveCollectionTypes() error {
propertyType.CollectionType = property.CollectionType

if propertyType.CollectionType == "map" {
resolveMapCollectionType(property, propertyType)
if err := resolveMapCollectionType(property, propertyType); err != nil {
return errors.Wrapf(err, "invalid %q property of %q schema", propertyName, s.ID)
}
}
}
}
Expand All @@ -721,9 +723,13 @@ func checkCollectionTypes(property, propertyType *JSONSchema) error {
return nil
}

func resolveMapCollectionType(property, propertyType *JSONSchema) {
itemType := propertyType.OrderedProperties[0].Items
propertyType.MapKeyProperty = itemType.Properties[property.MapKey]
func resolveMapCollectionType(property, propertyType *JSONSchema) error {
if property.MapKey == "" {
return errors.New("empty mapKey field")
}

propertyType.MapKeyProperty = propertyType.OrderedProperties[0].Items.Properties[property.MapKey]
return nil
}

//MakeAPI load directory and generate API definitions.
Expand Down

0 comments on commit 35334ed

Please sign in to comment.