render de-normalized schema format
(tableTitle string, properties sdk.SchemaPropertiesMap)
| 94 | |
| 95 | // render de-normalized schema format |
| 96 | func RenderSchemaTable(tableTitle string, properties sdk.SchemaPropertiesMap) error { |
| 97 | if len(properties) == 0 { |
| 98 | return nil |
| 99 | } |
| 100 | |
| 101 | t := output.NewTableWriter() |
| 102 | t.SetTitle(tableTitle) |
| 103 | t.AppendHeader(table.Row{"Field", "Type", "Required", "Description"}) |
| 104 | |
| 105 | // Sort map |
| 106 | keys := make([]string, 0, len(properties)) |
| 107 | for k := range properties { |
| 108 | keys = append(keys, k) |
| 109 | } |
| 110 | |
| 111 | sort.Strings(keys) |
| 112 | |
| 113 | for _, k := range keys { |
| 114 | v := properties[k] |
| 115 | |
| 116 | propertyType := v.Type |
| 117 | if v.Format != "" { |
| 118 | propertyType = fmt.Sprintf("%s (%s)", propertyType, v.Format) |
| 119 | } |
| 120 | |
| 121 | color := text.Colors{} |
| 122 | if v.Required { |
| 123 | color = text.Colors{text.FgHiYellow} |
| 124 | } |
| 125 | |
| 126 | var requiredInfo = color.Sprint(hBool(v.Required)) |
| 127 | if v.Default != "" && !v.Required { |
| 128 | requiredInfo = fmt.Sprintf("%s (default: %s)", requiredInfo, v.Default) |
| 129 | } |
| 130 | |
| 131 | t.AppendRow(table.Row{color.Sprint(v.Name), color.Sprint(propertyType), requiredInfo, v.Description}) |
| 132 | } |
| 133 | |
| 134 | t.Render() |
| 135 | |
| 136 | return nil |
| 137 | } |
| 138 | |
| 139 | // render raw JSON schema document |
| 140 | func RenderSchemaRaw(tableTitle string, s string) error { |
no test coverage detected