@@ -23,19 +23,19 @@ func (w *JSONSchemaWriter) WriteSchema(blocks []*configBlock) error {
23
23
return encoder .Encode (schema )
24
24
}
25
25
26
- func (w * JSONSchemaWriter ) generateJSONSchema (blocks []* configBlock ) map [string ]interface {} {
27
- schema := map [string ]interface {} {
26
+ func (w * JSONSchemaWriter ) generateJSONSchema (blocks []* configBlock ) map [string ]any {
27
+ schema := map [string ]any {
28
28
"$schema" : "https://json-schema.org/draft/2020-12/schema" ,
29
29
"$id" : "https://raw.githubusercontent.com/cortexproject/cortex/master/schemas/cortex-config-schema.json" ,
30
30
"title" : "Cortex Configuration Schema" ,
31
31
"description" : "JSON Schema for Cortex configuration file" ,
32
32
"type" : "object" ,
33
- "properties" : map [string ]interface {} {},
34
- "definitions" : map [string ]interface {} {},
33
+ "properties" : map [string ]any {},
34
+ "definitions" : map [string ]any {},
35
35
}
36
36
37
- properties := schema ["properties" ].(map [string ]interface {} )
38
- definitions := schema ["definitions" ].(map [string ]interface {} )
37
+ properties := schema ["properties" ].(map [string ]any )
38
+ definitions := schema ["definitions" ].(map [string ]any )
39
39
40
40
// Process each config block
41
41
for _ , block := range blocks {
@@ -51,15 +51,15 @@ func (w *JSONSchemaWriter) generateJSONSchema(blocks []*configBlock) map[string]
51
51
return schema
52
52
}
53
53
54
- func (w * JSONSchemaWriter ) processBlockEntries (block * configBlock , properties map [string ]interface {} , definitions map [string ]interface {} ) {
54
+ func (w * JSONSchemaWriter ) processBlockEntries (block * configBlock , properties map [string ]any , definitions map [string ]any ) {
55
55
for _ , entry := range block .entries {
56
56
switch entry .kind {
57
57
case "field" :
58
58
properties [entry .name ] = w .generateFieldSchema (entry )
59
59
case "block" :
60
60
if entry .root {
61
61
// Root blocks are referenced via $ref
62
- properties [entry .name ] = map [string ]interface {} {
62
+ properties [entry .name ] = map [string ]any {
63
63
"$ref" : fmt .Sprintf ("#/definitions/%s" , entry .block .name ),
64
64
}
65
65
// Add the block to definitions if not already there
@@ -74,17 +74,17 @@ func (w *JSONSchemaWriter) processBlockEntries(block *configBlock, properties ma
74
74
}
75
75
}
76
76
77
- func (w * JSONSchemaWriter ) generateBlockSchema (block * configBlock ) map [string ]interface {} {
78
- obj := map [string ]interface {} {
77
+ func (w * JSONSchemaWriter ) generateBlockSchema (block * configBlock ) map [string ]any {
78
+ obj := map [string ]any {
79
79
"type" : "object" ,
80
- "properties" : map [string ]interface {} {},
80
+ "properties" : map [string ]any {},
81
81
}
82
82
83
83
if block .desc != "" {
84
84
obj ["description" ] = block .desc
85
85
}
86
86
87
- properties := obj ["properties" ].(map [string ]interface {} )
87
+ properties := obj ["properties" ].(map [string ]any )
88
88
89
89
for _ , entry := range block .entries {
90
90
switch entry .kind {
@@ -93,7 +93,7 @@ func (w *JSONSchemaWriter) generateBlockSchema(block *configBlock) map[string]in
93
93
case "block" :
94
94
if entry .root {
95
95
// Reference to another root block
96
- properties [entry .name ] = map [string ]interface {} {
96
+ properties [entry .name ] = map [string ]any {
97
97
"$ref" : fmt .Sprintf ("#/definitions/%s" , entry .block .name ),
98
98
}
99
99
} else {
@@ -106,8 +106,8 @@ func (w *JSONSchemaWriter) generateBlockSchema(block *configBlock) map[string]in
106
106
return obj
107
107
}
108
108
109
- func (w * JSONSchemaWriter ) generateFieldSchema (entry * configEntry ) map [string ]interface {} {
110
- prop := map [string ]interface {} {
109
+ func (w * JSONSchemaWriter ) generateFieldSchema (entry * configEntry ) map [string ]any {
110
+ prop := map [string ]any {
111
111
"type" : w .getJSONType (entry .fieldType ),
112
112
}
113
113
@@ -143,7 +143,7 @@ func (w *JSONSchemaWriter) generateFieldSchema(entry *configEntry) map[string]in
143
143
if strings .HasPrefix (entry .fieldType , "list of " ) {
144
144
prop ["type" ] = "array"
145
145
itemType := strings .TrimPrefix (entry .fieldType , "list of " )
146
- prop ["items" ] = map [string ]interface {} {
146
+ prop ["items" ] = map [string ]any {
147
147
"type" : w .getJSONType (itemType ),
148
148
}
149
149
}
@@ -185,7 +185,7 @@ func (w *JSONSchemaWriter) getJSONType(goType string) string {
185
185
}
186
186
}
187
187
188
- func (w * JSONSchemaWriter ) parseDefaultValue (defaultStr , goType string ) interface {} {
188
+ func (w * JSONSchemaWriter ) parseDefaultValue (defaultStr , goType string ) any {
189
189
if defaultStr == "" {
190
190
return nil
191
191
}
@@ -206,11 +206,11 @@ func (w *JSONSchemaWriter) parseDefaultValue(defaultStr, goType string) interfac
206
206
default :
207
207
// Handle special cases
208
208
if defaultStr == "[]" {
209
- return []interface {} {}
209
+ return []any {}
210
210
}
211
211
if strings .HasPrefix (defaultStr , "[" ) && strings .HasSuffix (defaultStr , "]" ) {
212
212
// Try to parse as JSON array
213
- var arr []interface {}
213
+ var arr []any
214
214
if err := json .Unmarshal ([]byte (defaultStr ), & arr ); err == nil {
215
215
return arr
216
216
}
0 commit comments