MCPcopy Create free account
hub / github.com/pydio/cells / createSample

Function createSample

common/utils/docs/openapi.go:129–167  ·  view source on GitHub ↗
(document *loads.Document, data *spec.Schema, dir string, chain ...string)

Source from the content-addressed store, hash-verified

127}
128
129func createSample(document *loads.Document, data *spec.Schema, dir string, chain ...string) interface{} {
130 if refScheme, refName, ok := getDefinition(document, data.Ref); ok {
131 for _, c := range chain {
132 if c == refName {
133 return "[Recursive structure]"
134 }
135 }
136 chain = append(chain, refName)
137 s := createSample(document, &refScheme, dir, chain...)
138 // Special case for treeNode, only keep Path field in sample
139 if m, o := s.(map[string]interface{}); o && refName == "treeNode" && dir == "in" {
140 return map[string]interface{}{"Path": m["Path"]}
141 }
142 return s
143 }
144 switch data.Type[0] {
145 case "boolean":
146 return true
147 case "string":
148 return "string"
149 case "integer":
150 return 10
151 case "array":
152 arSchema := data.Items.Schema
153 if len(data.Items.Schemas) > 0 {
154 arSchema = &data.Items.Schemas[0]
155 }
156 itemSample := createSample(document, arSchema, dir, chain...)
157 return []interface{}{itemSample}
158 case "object":
159 example := make(map[string]interface{})
160 for name, p := range data.SchemaProps.Properties {
161 example[name] = createSample(document, &p, dir, chain...)
162 }
163 return example
164 default:
165 return "[Unknown Type " + data.Type[0] + "]"
166 }
167}

Callers 1

parseSchemaFunction · 0.85

Calls 2

getDefinitionFunction · 0.85
makeFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…