(rawTypeData interface{}, metaschema *Schema)
| 103 | } |
| 104 | |
| 105 | func newSchemaFromObj(rawTypeData interface{}, metaschema *Schema) (*Schema, error) { |
| 106 | typeData := rawTypeData.(map[string]interface{}) |
| 107 | |
| 108 | if metaschema != nil { |
| 109 | err := metaschema.Validate(metaschema.JSONSchema, typeData) |
| 110 | if err != nil { |
| 111 | return nil, err |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | id := util.MaybeString(typeData["id"]) |
| 116 | if id == "" { |
| 117 | return nil, &typeAssertionError{"id"} |
| 118 | } |
| 119 | plural := util.MaybeString(typeData["plural"]) |
| 120 | if plural == "" { |
| 121 | return nil, &typeAssertionError{"plural"} |
| 122 | } |
| 123 | title := util.MaybeString(typeData["title"]) |
| 124 | if title == "" { |
| 125 | return nil, &typeAssertionError{"title"} |
| 126 | } |
| 127 | description := util.MaybeString(typeData["description"]) |
| 128 | if description == "" { |
| 129 | return nil, &typeAssertionError{"description"} |
| 130 | } |
| 131 | singular := util.MaybeString(typeData["singular"]) |
| 132 | if singular == "" { |
| 133 | return nil, &typeAssertionError{"singular"} |
| 134 | } |
| 135 | |
| 136 | schema := NewSchema(id, plural, title, description, singular) |
| 137 | |
| 138 | schema.Prefix = util.MaybeString(typeData["prefix"]) |
| 139 | schema.URL = util.MaybeString(typeData["url"]) |
| 140 | schema.Type = util.MaybeString(typeData["type"]) |
| 141 | schema.Parent = util.MaybeString(typeData["parent"]) |
| 142 | schema.OnParentDeleteCascade, _ = typeData["on_parent_delete_cascade"].(bool) |
| 143 | schema.NamespaceID = util.MaybeString(typeData["namespace"]) |
| 144 | schema.IsolationLevel = util.MaybeMap(typeData["isolation_level"]) |
| 145 | jsonSchema, ok := typeData["schema"].(map[string]interface{}) |
| 146 | if !ok { |
| 147 | return nil, &typeAssertionError{"schema"} |
| 148 | } |
| 149 | schema.JSONSchema = jsonSchema |
| 150 | |
| 151 | schema.Metadata = util.MaybeMap(typeData["metadata"]) |
| 152 | schema.Extends = util.MaybeStringList(typeData["extends"]) |
| 153 | schema.OrderPropertiesBefore = util.MaybeStringList(typeData["order_properties_before"]) |
| 154 | |
| 155 | actions := util.MaybeMap(typeData["actions"]) |
| 156 | schema.Actions = []Action{} |
| 157 | for actionID, actionBody := range actions { |
| 158 | action, err := NewActionFromObject(actionID, actionBody) |
| 159 | if err != nil { |
| 160 | return nil, err |
| 161 | } |
| 162 | schema.Actions = append(schema.Actions, action) |
no test coverage detected