-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypes.go
More file actions
204 lines (171 loc) · 6.32 KB
/
types.go
File metadata and controls
204 lines (171 loc) · 6.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
package jsonforms
// AST represents the complete parsed structure of a JSON Forms definition
type AST struct {
UISchema UISchemaElement `json:"uischema"`
Schema any `json:"schema"` // Raw JSON Schema
}
// UISchemaElement is the base interface for all UI schema elements
type UISchemaElement interface {
GetType() string
GetRule() *Rule
GetOptions() map[string]any
GetI18n() *string
}
// BaseUISchemaElement contains common fields shared by all UI schema elements
type BaseUISchemaElement struct {
Type string `json:"type"`
Rule *Rule `json:"rule,omitempty"`
Options map[string]any `json:"options,omitempty"`
I18n *string `json:"i18n,omitempty"`
}
// GetType returns the type of the UI schema element
func (b *BaseUISchemaElement) GetType() string {
return b.Type
}
// GetRule returns the rule associated with this element
func (b *BaseUISchemaElement) GetRule() *Rule {
return b.Rule
}
// GetOptions returns the options map for this element
func (b *BaseUISchemaElement) GetOptions() map[string]any {
return b.Options
}
// GetI18n returns the internationalization key for this element
func (b *BaseUISchemaElement) GetI18n() *string {
return b.I18n
}
// SchemaProperty represents a resolved JSON Schema property definition.
// Fields are nil/zero when not present in the schema.
type SchemaProperty struct {
Type string `json:"type,omitempty"`
Format string `json:"format,omitempty"`
Enum []any `json:"enum,omitempty"`
Const any `json:"const,omitempty"`
Default any `json:"default,omitempty"`
Pattern string `json:"pattern,omitempty"`
MinLength *int `json:"minLength,omitempty"`
MaxLength *int `json:"maxLength,omitempty"`
Minimum *float64 `json:"minimum,omitempty"`
Maximum *float64 `json:"maximum,omitempty"`
Required bool `json:"-"` // true if this property appears in parent's "required" array
Properties map[string]*SchemaProperty `json:"properties,omitempty"` // for type: "object"
}
// Control binds a UI input to a specific data property
type Control struct {
BaseUISchemaElement
Scope string `json:"scope"`
Label any `json:"label,omitempty"` // Can be string, bool, or LabelDescription
SchemaProperty *SchemaProperty `json:"-"` // Resolved from Scope against the data schema
}
// LabelDescription provides detailed label configuration
type LabelDescription struct {
Text string `json:"text"`
Show *bool `json:"show,omitempty"`
}
// VerticalLayout stacks UI elements vertically
type VerticalLayout struct {
BaseUISchemaElement
Elements []UISchemaElement `json:"elements"`
}
// HorizontalLayout arranges UI elements side-by-side
type HorizontalLayout struct {
BaseUISchemaElement
Elements []UISchemaElement `json:"elements"`
}
// Group is a vertical layout with a descriptive label
type Group struct {
BaseUISchemaElement
Label string `json:"label"`
Elements []UISchemaElement `json:"elements"`
}
// Categorization provides tab-like organization of related sections
type Categorization struct {
BaseUISchemaElement
Label *string `json:"label,omitempty"`
Elements []CategoryElement `json:"elements"` // Can contain Category or nested Categorization
}
// CategoryElement is a marker interface for elements that can be in a Categorization
type CategoryElement interface {
UISchemaElement
IsCategoryElement()
}
// Category represents an individual tab/category within a Categorization
type Category struct {
BaseUISchemaElement
Label string `json:"label"`
Elements []UISchemaElement `json:"elements"`
}
// IsCategoryElement marks Category as a valid Categorization child
func (c *Category) IsCategoryElement() {}
// IsCategoryElement marks Categorization as a valid Categorization child (recursive)
func (c *Categorization) IsCategoryElement() {}
// Label displays static text in the form
type Label struct {
BaseUISchemaElement
Text string `json:"text"`
}
// CustomElement represents an unknown/custom element type that is not a standard JSON Forms element
type CustomElement struct {
BaseUISchemaElement
RawData map[string]any `json:"-"` // Complete raw element data
Elements []UISchemaElement `json:"elements,omitempty"` // Child elements (recursively parsed)
}
// Rule defines conditional behavior for UI elements
type Rule struct {
Effect RuleEffect `json:"effect"`
Condition Condition `json:"condition"`
}
// RuleEffect specifies what happens when a rule's condition is met
type RuleEffect string
const (
RuleEffectHIDE RuleEffect = "HIDE"
RuleEffectSHOW RuleEffect = "SHOW"
RuleEffectENABLE RuleEffect = "ENABLE"
RuleEffectDISABLE RuleEffect = "DISABLE"
)
// Condition is the base interface for all condition types
type Condition interface {
GetType() string
}
// SchemaBasedCondition validates a scope against a JSON Schema
type SchemaBasedCondition struct {
Type string `json:"type,omitempty"` // Optional, defaults to SCHEMA_BASED
Scope string `json:"scope"`
Schema any `json:"schema"` // JSON Schema object
FailWhenUndefined *bool `json:"failWhenUndefined,omitempty"`
}
// GetType returns the condition type
func (s *SchemaBasedCondition) GetType() string {
if s.Type != "" {
return s.Type
}
return "SCHEMA_BASED"
}
// LeafCondition performs simple value comparison
type LeafCondition struct {
Type string `json:"type"` // "LEAF"
Scope string `json:"scope"`
ExpectedValue any `json:"expectedValue"`
}
// GetType returns the condition type
func (l *LeafCondition) GetType() string {
return l.Type
}
// AndCondition combines multiple conditions with AND logic
type AndCondition struct {
Type string `json:"type"` // "AND"
Conditions []Condition `json:"conditions"`
}
// GetType returns the condition type
func (a *AndCondition) GetType() string {
return a.Type
}
// OrCondition combines multiple conditions with OR logic
type OrCondition struct {
Type string `json:"type"` // "OR"
Conditions []Condition `json:"conditions"`
}
// GetType returns the condition type
func (o *OrCondition) GetType() string {
return o.Type
}