| 1950 | } |
| 1951 | |
| 1952 | static void add_table_properties(tablemap *tablemap, |
| 1953 | struct table_desc *td, |
| 1954 | const jsmntok_t *properties) |
| 1955 | { |
| 1956 | const jsmntok_t *t; |
| 1957 | size_t i; |
| 1958 | |
| 1959 | json_for_each_obj(i, t, properties) { |
| 1960 | const jsmntok_t *type; |
| 1961 | struct column *col; |
| 1962 | |
| 1963 | if (ignore_column(td, t)) |
| 1964 | continue; |
| 1965 | type = json_get_member(schemas, t+1, "type"); |
| 1966 | /* Stub properties don't have types, it should exist in |
| 1967 | * another branch with actual types, so ignore this */ |
| 1968 | if (!type) |
| 1969 | continue; |
| 1970 | |
| 1971 | col = tal(td->columns, struct column); |
| 1972 | |
| 1973 | /* Some things are so old we ignore them. */ |
| 1974 | if (!add_deprecated(schemas, t+1, col)) { |
| 1975 | tal_free(col); |
| 1976 | continue; |
| 1977 | } |
| 1978 | |
| 1979 | if (json_tok_streq(schemas, type, "array")) { |
| 1980 | const jsmntok_t *items; |
| 1981 | |
| 1982 | items = json_get_member(schemas, t+1, "items"); |
| 1983 | type = json_get_member(schemas, items, "type"); |
| 1984 | |
| 1985 | col->sub = new_table_desc(col, tablemap, td, t, t, false); |
| 1986 | /* Array of primitives? Treat as single-entry obj */ |
| 1987 | if (!json_tok_streq(schemas, type, "object")) |
| 1988 | add_table_singleton(col->sub, t, items); |
| 1989 | else |
| 1990 | add_table_object(tablemap, col->sub, items); |
| 1991 | } else if (json_tok_streq(schemas, type, "object")) { |
| 1992 | col->sub = new_table_desc(col, tablemap, td, t, t, true); |
| 1993 | add_table_object(tablemap, col->sub, t+1); |
| 1994 | } else { |
| 1995 | col->ftype = find_fieldtype(type); |
| 1996 | col->sub = NULL; |
| 1997 | } |
| 1998 | col->dbname = db_column_name(col, td, t); |
| 1999 | /* Some schemas repeat, assume they're the same */ |
| 2000 | if (find_column(td, col->dbname)) { |
| 2001 | tal_free(col); |
| 2002 | } else { |
| 2003 | col->jsonname = json_strdup(col, schemas, t); |
| 2004 | tal_arr_expand(&td->columns, col); |
| 2005 | } |
| 2006 | } |
| 2007 | } |
| 2008 | |
| 2009 | /* tok is the JSON schema member for an object */ |
no test coverage detected