MCPcopy
hub / github.com/yannh/kubeconform / process

Function process

openapi2jsonschema-go/openapi2jsonschema.go:266–361  ·  view source on GitHub ↗

process consumes one CRD source (file or URL) and writes one JSON schema per version found, mirroring the original Python control flow.

(path string, filenameFormat string, denyRoot bool)

Source from the content-addressed store, hash-verified

264// process consumes one CRD source (file or URL) and writes one JSON schema per
265// version found, mirroring the original Python control flow.
266func process(path string, filenameFormat string, denyRoot bool) error {
267 r, err := openInput(path)
268 if err != nil {
269 return err
270 }
271 defer r.Close()
272
273 dec := yaml.NewDecoder(r)
274 var defs []*OrderedMap
275 for {
276 var node yaml.Node
277 if err := dec.Decode(&node); err != nil {
278 if err == io.EOF {
279 break
280 }
281 return err
282 }
283 v, err := yamlToData(&node)
284 if err != nil {
285 return err
286 }
287 m, ok := v.(*OrderedMap)
288 if !ok || m == nil {
289 continue
290 }
291 if items, ok := m.Get("items"); ok {
292 if list, ok := items.([]any); ok {
293 for _, it := range list {
294 if im, ok := it.(*OrderedMap); ok {
295 defs = append(defs, im)
296 }
297 }
298 }
299 }
300 kind, ok := m.Get("kind")
301 if !ok {
302 continue
303 }
304 if ks, _ := kind.(string); ks != "CustomResourceDefinition" {
305 continue
306 }
307 defs = append(defs, m)
308 }
309
310 for _, y := range defs {
311 spec, ok := getMap(y, "spec")
312 if !ok {
313 continue
314 }
315 names, _ := getMap(spec, "names")
316 kind, _ := getString(names, "kind")
317 fullgroup, _ := getString(spec, "group")
318 group := strings.SplitN(fullgroup, ".", 2)[0]
319
320 versions, hasVersions := spec.Get("versions")
321 versionList, _ := versions.([]any)
322
323 if hasVersions && len(versionList) > 0 {

Callers 1

mainFunction · 0.85

Calls 7

openInputFunction · 0.85
yamlToDataFunction · 0.85
getMapFunction · 0.85
getStringFunction · 0.85
formatFilenameFunction · 0.85
writeSchemaFileFunction · 0.85
GetMethod · 0.65

Tested by

no test coverage detected