AddProperty adds a new property to the current Schema, and returns an error if it collides. Two identical fields will not collide, but two properties by the same name, but different definition, will collide. It's safe to merge the fields of two schemas with overlapping properties if those properties
(p Property)
| 104 | // fields of two schemas with overlapping properties if those properties are |
| 105 | // identical. |
| 106 | func (s *Schema) AddProperty(p Property) error { |
| 107 | // Scan all existing properties for a conflict |
| 108 | for _, e := range s.Properties { |
| 109 | if e.JsonFieldName == p.JsonFieldName && !PropertiesEqual(e, p) { |
| 110 | return fmt.Errorf("property '%s' already exists with a different type", e.JsonFieldName) |
| 111 | } |
| 112 | } |
| 113 | s.Properties = append(s.Properties, p) |
| 114 | return nil |
| 115 | } |
| 116 | |
| 117 | func (s Schema) GetAdditionalTypeDefs() []TypeDefinition { |
| 118 | return s.AdditionalTypes |
no test coverage detected