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)
| 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. |
| 517 | func 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. |
no test coverage detected