1
0
mirror of https://github.com/rancher/steve.git synced 2025-09-20 02:51:11 +00:00

Make schema type definitions recursive.

This commit is contained in:
Chad Roberts
2025-01-24 11:25:34 -05:00
parent 809e927a0c
commit b03e41404c
2 changed files with 65 additions and 20 deletions

View File

@@ -20,23 +20,34 @@ func (s *schemaFieldVisitor) VisitArray(array *proto.Array) {
// it was kept this way to provide backwards compat with previous endpoints.
array.SubType.Accept(s)
subField := s.field
field.Type = "array"
field.SubType = subField.Type
field.Type = "array[" + subField.Type + "]"
s.field = field
}
// VisitMap turns a map into a definitionField (stored on the receiver). For maps of complex types, will also visit the
// subtype.
//func (s *schemaFieldVisitor) VisitMap(protoMap *proto.Map) {
// field := definitionField{
// Description: protoMap.GetDescription(),
// }
// // this currently is not recursive and provides little information for nested types- while this isn't optimal,
// // it was kept this way to provide backwards compat with previous endpoints.
// protoMap.SubType.Accept(s)
// subField := s.field
// field.Type = "map[" + subField.Type + "]"
// s.field = field
//}
func (s *schemaFieldVisitor) VisitMap(protoMap *proto.Map) {
field := definitionField{
Description: protoMap.GetDescription(),
}
// this currently is not recursive and provides little information for nested types- while this isn't optimal,
// it was kept this way to provide backwards compat with previous endpoints.
protoMap.SubType.Accept(s)
subField := s.field
field.Type = "map"
field.SubType = subField.Type
// Recursively visit the value subtype
subVisitor := &schemaFieldVisitor{definitions: s.definitions}
protoMap.SubType.Accept(subVisitor)
subField := subVisitor.field
// Represent the map as "map[string]<value_type>"
field.Type = "map[string]" + subField.Type
s.field = field
}