Add data bindings for top level properties within JSON fields

This commit is contained in:
Andrew Kingston 2021-12-06 19:55:21 +00:00
parent c21f4b9681
commit 999d8f3d55
1 changed files with 15 additions and 0 deletions

View File

@ -213,6 +213,21 @@ const getProviderContextBindings = (asset, dataProviders) => {
schema = info.schema schema = info.schema
table = info.table table = info.table
// Check for any JSON fields so we can add any top level properties
let jsonAdditions = {}
Object.keys(schema).forEach(fieldKey => {
const fieldSchema = schema[fieldKey]
if (fieldSchema.type === "json") {
const jsonSchema = convertJSONSchemaToTableSchema(fieldSchema, true)
Object.keys(jsonSchema).forEach(jsonKey => {
jsonAdditions[`${fieldKey}.${jsonKey}`] = {
type: jsonSchema[jsonKey].type,
}
})
}
})
schema = { ...schema, ...jsonAdditions }
// For JSON arrays, use the array name as the readable prefix. // For JSON arrays, use the array name as the readable prefix.
// Otherwise use the table name // Otherwise use the table name
if (datasource.type === "jsonarray") { if (datasource.type === "jsonarray") {