Skip to content

Commit

Permalink
Remove map key resolve workaround
Browse files Browse the repository at this point in the history
Partial-Bug: #1785278
Change-Id: I83cda692daeb5ec27d6b89a18f9baaeb8adad32b
  • Loading branch information
kbr- committed Aug 23, 2018
1 parent f1d1e2f commit 77e721b
Showing 1 changed file with 3 additions and 32 deletions.
35 changes: 3 additions & 32 deletions pkg/schema/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -703,9 +703,7 @@ func (api *API) resolveCollectionTypes() error {
propertyType.CollectionType = property.CollectionType

if propertyType.CollectionType == "map" {
if err := resolveMapCollectionType(property, propertyType); err != nil {
return err
}
resolveMapCollectionType(property, propertyType)
}
}
}
Expand All @@ -723,36 +721,9 @@ func checkCollectionTypes(property, propertyType *JSONSchema) error {
return nil
}

func resolveMapCollectionType(property, propertyType *JSONSchema) error {
func resolveMapCollectionType(property, propertyType *JSONSchema) {
itemType := propertyType.OrderedProperties[0].Items

if property.MapKey != "" {
log.Warn("Remove inferMapKeyProperty workaround now!")
propertyType.MapKeyProperty = itemType.Properties[property.MapKey]
} else {
var err error
propertyType.MapKeyProperty, err = inferMapKeyProperty(property, itemType)
if err != nil {
return err
}
}
return nil
}

// inferMapKeyProperty gets key property of given map property (with CollectionType == "map").
// TODO: get information about key property of map property (with CollectionType == "map") from schema
func inferMapKeyProperty(property, itemType *JSONSchema) (*JSONSchema, error) {
mapKeyProperty, ok := itemType.Properties["key"]
if !ok {
mapKeyProperty, ok = itemType.Properties["name"]
if !ok {
return nil, errors.Errorf(
"type %s is used as 'map' collection type, but has neither 'key' nor 'name' properties",
property.ProtoType,
)
}
}
return mapKeyProperty, nil
propertyType.MapKeyProperty = itemType.Properties[property.MapKey]
}

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

0 comments on commit 77e721b

Please sign in to comment.