MCPcopy Create free account
hub / github.com/cli/cli / writeProperties

Function writeProperties

script/ghmock/schemacmd.go:517–545  ·  view source on GitHub ↗

writeProperties lists an object's properties, or those of each item in a list of objects, with the ones a response must include first.

(w io.Writer, s *openapi3.Schema)

Source from the content-addressed store, hash-verified

515// writeProperties lists an object's properties, or those of each item in a
516// list of objects, with the ones a response must include first.
517func writeProperties(w io.Writer, s *openapi3.Schema) {
518 suffix := ":"
519 if s.Items != nil && s.Items.Value != nil {
520 s = s.Items.Value
521 suffix = " of each item:"
522 }
523 props, required := mergedProperties(s)
524 var must, may []string
525 for name := range props {
526 if required[name] {
527 must = append(must, name)
528 } else {
529 may = append(may, name)
530 }
531 }
532 for _, group := range []struct {
533 label string
534 names []string
535 }{{"Required properties", must}, {"Optional properties", may}} {
536 if len(group.names) == 0 {
537 continue
538 }
539 sort.Strings(group.names)
540 fmt.Fprintln(w, group.label+suffix)
541 for _, name := range group.names {
542 fmt.Fprintf(w, " %s: %s\n", name, describeSchemaType(props[name]))
543 }
544 }
545}
546
547// mergedProperties collects an object's properties and required names,
548// including those from allOf.

Callers 1

describeRESTFunction · 0.85

Calls 2

mergedPropertiesFunction · 0.85
describeSchemaTypeFunction · 0.85

Tested by

no test coverage detected