MCPcopy Create free account
hub / github.com/cloudwan/gohan / Extend

Method Extend

schema/schema.go:569–611  ·  view source on GitHub ↗

Extend extends target schema

(fromSchema *Schema)

Source from the content-addressed store, hash-verified

567
568// Extend extends target schema
569func (schema *Schema) Extend(fromSchema *Schema) error {
570 if schema.Parent == "" {
571 schema.Parent = fromSchema.Parent
572 }
573 if schema.Prefix == "" {
574 schema.Prefix = fromSchema.Prefix
575 }
576 if schema.URL == "" {
577 schema.URL = fromSchema.URL
578 }
579 if schema.NamespaceID == "" {
580 schema.NamespaceID = fromSchema.NamespaceID
581 }
582 schema.JSONSchema["properties"] = util.ExtendMap(
583 util.MaybeMap(schema.JSONSchema["properties"]),
584 util.MaybeMap(fromSchema.JSONSchema["properties"]))
585
586 if util.ContainsString(util.MaybeStringList(schema.OrderPropertiesBefore), fromSchema.ID) {
587 schema.JSONSchema["propertiesOrder"] = util.ExtendStringList(
588 util.MaybeStringList(schema.JSONSchema["propertiesOrder"]),
589 util.MaybeStringList(fromSchema.JSONSchema["propertiesOrder"]))
590 } else {
591 schema.JSONSchema["propertiesOrder"] = util.ExtendStringList(
592 util.MaybeStringList(fromSchema.JSONSchema["propertiesOrder"]),
593 util.MaybeStringList(schema.JSONSchema["propertiesOrder"]))
594 }
595
596 schema.JSONSchema["required"] = util.ExtendStringList(
597 util.MaybeStringList(fromSchema.JSONSchema["required"]),
598 util.MaybeStringList(schema.JSONSchema["required"]))
599MergeAction:
600 for _, action := range fromSchema.Actions {
601 for _, existingAction := range schema.Actions {
602 if action.ID == existingAction.ID {
603 continue MergeAction
604 }
605 }
606 schema.Actions = append(schema.Actions, action)
607 }
608 schema.Metadata = util.ExtendMap(schema.Metadata, fromSchema.Metadata)
609 schema.IsolationLevel = util.ExtendMap(schema.IsolationLevel, fromSchema.IsolationLevel)
610 return schema.Init()
611}
612
613//Titles returns list of Titles
614func (schema *Schema) Titles() []string {

Callers 1

loadSchemaFromFileMethod · 0.45

Calls 2

InitMethod · 0.95
MaybeMapMethod · 0.80

Tested by

no test coverage detected