Esempio n. 1
0
// Extend extends target schema
func (schema *Schema) Extend(fromSchema *Schema) error {
	if schema.Parent == "" {
		schema.Parent = fromSchema.Parent
	}
	if schema.Prefix == "" {
		schema.Prefix = fromSchema.Prefix
	}
	if schema.URL == "" {
		schema.URL = fromSchema.URL
	}
	if schema.NamespaceID == "" {
		schema.NamespaceID = fromSchema.NamespaceID
	}
	schema.JSONSchema["properties"] = util.ExtendMap(
		util.MaybeMap(schema.JSONSchema["properties"]),
		util.MaybeMap(fromSchema.JSONSchema["properties"]))

	schema.JSONSchema["propertiesOrder"] = util.ExtendStringList(
		util.MaybeStringList(fromSchema.JSONSchema["propertiesOrder"]),
		util.MaybeStringList(schema.JSONSchema["propertiesOrder"]))

MergeAction:
	for _, action := range fromSchema.Actions {
		for _, existingAction := range schema.Actions {
			if action.ID == existingAction.ID {
				continue MergeAction
			}
		}
		schema.Actions = append(schema.Actions, action)
	}
	schema.Metadata = util.ExtendMap(schema.Metadata, fromSchema.Metadata)
	return schema.Init()
}
Esempio n. 2
0
func (schema *Schema) relatedSchemas() []string {
	schemas := []string{}
	for _, p := range schema.Properties {
		if p.Relation != "" {
			schemas = append(schemas, p.Relation)
		}
	}
	schemas = util.ExtendStringList(schemas, schema.Extends)
	return schemas
}