MCPcopy Create free account
hub / github.com/oapi-codegen/oapi-codegen / AddProperty

Method AddProperty

pkg/codegen/schema.go:106–115  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

104// fields of two schemas with overlapping properties if those properties are
105// identical.
106func (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
117func (s Schema) GetAdditionalTypeDefs() []TypeDefinition {
118 return s.AdditionalTypes

Callers 1

mergeSchemasV1Function · 0.95

Calls 1

PropertiesEqualFunction · 0.85

Tested by

no test coverage detected