parseProjectFieldDefinitions parses the "field-definitions" (or "field_definitions") list from a project config map. Only fields with both name and data-type are included.
(configMap map[string]any, debugLog *logger.Logger)
| 75 | // parseProjectFieldDefinitions parses the "field-definitions" (or "field_definitions") list |
| 76 | // from a project config map. Only fields with both name and data-type are included. |
| 77 | func parseProjectFieldDefinitions(configMap map[string]any, debugLog *logger.Logger) []ProjectFieldDefinition { |
| 78 | fieldsData, hasFields := configMap["field-definitions"] |
| 79 | if !hasFields { |
| 80 | // Allow underscore variant as well |
| 81 | fieldsData, hasFields = configMap["field_definitions"] |
| 82 | } |
| 83 | if !hasFields { |
| 84 | return nil |
| 85 | } |
| 86 | fieldsList, ok := fieldsData.([]any) |
| 87 | if !ok { |
| 88 | return nil |
| 89 | } |
| 90 | |
| 91 | var fields []ProjectFieldDefinition |
| 92 | for i, fieldItem := range fieldsList { |
| 93 | fieldMap, ok := fieldItem.(map[string]any) |
| 94 | if !ok { |
| 95 | continue |
| 96 | } |
| 97 | |
| 98 | field := ProjectFieldDefinition{} |
| 99 | |
| 100 | if name, exists := fieldMap["name"]; exists { |
| 101 | if nameStr, ok := name.(string); ok { |
| 102 | field.Name = nameStr |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | dataType, hasDataType := fieldMap["data-type"] |
| 107 | if !hasDataType { |
| 108 | dataType = fieldMap["data_type"] |
| 109 | } |
| 110 | if dataTypeStr, ok := dataType.(string); ok { |
| 111 | field.DataType = dataTypeStr |
| 112 | } |
| 113 | |
| 114 | if options, exists := fieldMap["options"]; exists { |
| 115 | if optionsList, ok := options.([]any); ok { |
| 116 | for _, opt := range optionsList { |
| 117 | if optStr, ok := opt.(string); ok { |
| 118 | field.Options = append(field.Options, optStr) |
| 119 | } |
| 120 | } |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | if field.Name != "" && field.DataType != "" { |
| 125 | fields = append(fields, field) |
| 126 | debugLog.Printf("Parsed field definition %d: %s (%s)", i+1, field.Name, field.DataType) |
| 127 | } |
| 128 | } |
| 129 | return fields |
| 130 | } |