mirror of https://github.com/databricks/cli.git
fix: Updated styles
This commit is contained in:
parent
2aadfcbcb2
commit
c6703c1363
|
@ -20,6 +20,7 @@ type rootNode struct {
|
||||||
ObjectKeyAttributes []attributeNode
|
ObjectKeyAttributes []attributeNode
|
||||||
ArrayItemAttributes []attributeNode
|
ArrayItemAttributes []attributeNode
|
||||||
TopLevel bool
|
TopLevel bool
|
||||||
|
Type string
|
||||||
}
|
}
|
||||||
|
|
||||||
type attributeNode struct {
|
type attributeNode struct {
|
||||||
|
@ -51,6 +52,7 @@ func getNodes(s jsonschema.Schema, refs map[string]jsonschema.Schema, customFiel
|
||||||
Description: getDescription(v, item.topLevel),
|
Description: getDescription(v, item.topLevel),
|
||||||
TopLevel: item.topLevel,
|
TopLevel: item.topLevel,
|
||||||
Example: getExample(v),
|
Example: getExample(v),
|
||||||
|
Type: getHumanReadableType(v.Type),
|
||||||
}
|
}
|
||||||
|
|
||||||
node.Attributes = getAttributes(v.Properties, refs)
|
node.Attributes = getAttributes(v.Properties, refs)
|
||||||
|
@ -91,8 +93,6 @@ func buildMarkdown(nodes []rootNode, outputFile, header string) error {
|
||||||
m := md.NewMarkdown(f)
|
m := md.NewMarkdown(f)
|
||||||
m = m.PlainText(header)
|
m = m.PlainText(header)
|
||||||
for _, node := range nodes {
|
for _, node := range nodes {
|
||||||
isArray := len(node.ArrayItemAttributes) > 0
|
|
||||||
|
|
||||||
m = m.LF()
|
m = m.LF()
|
||||||
if node.TopLevel {
|
if node.TopLevel {
|
||||||
m = m.H2(node.Title)
|
m = m.H2(node.Title)
|
||||||
|
@ -100,24 +100,24 @@ func buildMarkdown(nodes []rootNode, outputFile, header string) error {
|
||||||
m = m.H3(node.Title)
|
m = m.H3(node.Title)
|
||||||
}
|
}
|
||||||
m = m.LF()
|
m = m.LF()
|
||||||
if isArray {
|
|
||||||
m = m.PlainText("**`Type: Array`**")
|
if node.Type != "" {
|
||||||
|
m = m.PlainText(fmt.Sprintf("**`Type: %s`**", node.Type))
|
||||||
m = m.LF()
|
m = m.LF()
|
||||||
m = m.PlainText(node.Description)
|
|
||||||
} else {
|
|
||||||
m = m.PlainText(node.Description)
|
|
||||||
}
|
}
|
||||||
|
m = m.PlainText(node.Description)
|
||||||
m = m.LF()
|
m = m.LF()
|
||||||
|
|
||||||
if len(node.ObjectKeyAttributes) > 0 {
|
if len(node.ObjectKeyAttributes) > 0 {
|
||||||
|
itemName := removePluralForm(node.Title)
|
||||||
|
fieldName := fmt.Sprintf("%s-name", itemName)
|
||||||
m = buildAttributeTable(m, []attributeNode{
|
m = buildAttributeTable(m, []attributeNode{
|
||||||
{Title: fmt.Sprintf("<%s-entry-name>", node.Title), Type: "Map", Description: fmt.Sprintf("Item of the `%s` map", node.Title)},
|
{Title: fieldName, Type: "Map", Description: fmt.Sprintf("The definition of a %s. See %s", itemName, md.Link("_", "#"+fieldName))},
|
||||||
})
|
})
|
||||||
m = m.PlainText("Each item has the following attributes:")
|
|
||||||
m = m.LF()
|
m = m.LF()
|
||||||
|
m = m.H3(fieldName)
|
||||||
m = buildAttributeTable(m, node.ObjectKeyAttributes)
|
m = buildAttributeTable(m, node.ObjectKeyAttributes)
|
||||||
} else if len(node.ArrayItemAttributes) > 0 {
|
} else if len(node.ArrayItemAttributes) > 0 {
|
||||||
m = m.PlainTextf("Each item of `%s` has the following attributes:", node.Title)
|
|
||||||
m = m.LF()
|
m = m.LF()
|
||||||
m = buildAttributeTable(m, node.ArrayItemAttributes)
|
m = buildAttributeTable(m, node.ArrayItemAttributes)
|
||||||
} else if len(node.Attributes) > 0 {
|
} else if len(node.Attributes) > 0 {
|
||||||
|
@ -141,18 +141,28 @@ func buildMarkdown(nodes []rootNode, outputFile, header string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func removePluralForm(s string) string {
|
||||||
|
if strings.HasSuffix(s, "s") {
|
||||||
|
return strings.TrimSuffix(s, "s")
|
||||||
|
}
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
func buildAttributeTable(m *md.Markdown, attributes []attributeNode) *md.Markdown {
|
func buildAttributeTable(m *md.Markdown, attributes []attributeNode) *md.Markdown {
|
||||||
return buildCustomAttributeTable(m, attributes)
|
return buildCustomAttributeTable(m, attributes)
|
||||||
rows := [][]string{}
|
|
||||||
for _, n := range attributes {
|
|
||||||
rows = append(rows, []string{fmt.Sprintf("`%s`", n.Title), n.Type, formatDescription(n.Description)})
|
|
||||||
}
|
|
||||||
m = m.CustomTable(md.TableSet{
|
|
||||||
Header: []string{"Key", "Type", "Description"},
|
|
||||||
Rows: rows,
|
|
||||||
}, md.TableOptions{AutoWrapText: false, AutoFormatHeaders: false})
|
|
||||||
|
|
||||||
return m
|
// Rows below are useful for debugging since it renders the table in a regular markdown format
|
||||||
|
|
||||||
|
// rows := [][]string{}
|
||||||
|
// for _, n := range attributes {
|
||||||
|
// rows = append(rows, []string{fmt.Sprintf("`%s`", n.Title), n.Type, formatDescription(n.Description)})
|
||||||
|
// }
|
||||||
|
// m = m.CustomTable(md.TableSet{
|
||||||
|
// Header: []string{"Key", "Type", "Description"},
|
||||||
|
// Rows: rows,
|
||||||
|
// }, md.TableOptions{AutoWrapText: false, AutoFormatHeaders: false})
|
||||||
|
|
||||||
|
// return m
|
||||||
}
|
}
|
||||||
|
|
||||||
func formatDescription(s string) string {
|
func formatDescription(s string) string {
|
||||||
|
@ -172,7 +182,7 @@ func buildCustomAttributeTable(m *md.Markdown, attributes []attributeNode) *md.M
|
||||||
m = m.LF()
|
m = m.LF()
|
||||||
|
|
||||||
for _, a := range attributes {
|
for _, a := range attributes {
|
||||||
m = m.PlainText(" * - " + a.Title)
|
m = m.PlainText(" * - " + fmt.Sprintf("`%s`", a.Title))
|
||||||
m = m.PlainText(" - " + a.Type)
|
m = m.PlainText(" - " + a.Type)
|
||||||
m = m.PlainText(" - " + formatDescription(a.Description))
|
m = m.PlainText(" - " + formatDescription(a.Description))
|
||||||
m = m.LF()
|
m = m.LF()
|
||||||
|
@ -180,7 +190,7 @@ func buildCustomAttributeTable(m *md.Markdown, attributes []attributeNode) *md.M
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
func getAttributes(props map[string]*jsonschema.Schema, refs map[string]jsonschema.Schema) []attributeNode {
|
func getHumanReadableType(t jsonschema.Type) string {
|
||||||
typesMapping := map[string]string{
|
typesMapping := map[string]string{
|
||||||
"string": "String",
|
"string": "String",
|
||||||
"integer": "Integer",
|
"integer": "Integer",
|
||||||
|
@ -188,11 +198,14 @@ func getAttributes(props map[string]*jsonschema.Schema, refs map[string]jsonsche
|
||||||
"array": "Sequence",
|
"array": "Sequence",
|
||||||
"object": "Map",
|
"object": "Map",
|
||||||
}
|
}
|
||||||
|
return typesMapping[string(t)]
|
||||||
|
}
|
||||||
|
|
||||||
|
func getAttributes(props map[string]*jsonschema.Schema, refs map[string]jsonschema.Schema) []attributeNode {
|
||||||
attributes := []attributeNode{}
|
attributes := []attributeNode{}
|
||||||
for k, v := range props {
|
for k, v := range props {
|
||||||
v = resolveRefs(v, refs)
|
v = resolveRefs(v, refs)
|
||||||
typeString := typesMapping[string(v.Type)]
|
typeString := getHumanReadableType(v.Type)
|
||||||
if typeString == "" {
|
if typeString == "" {
|
||||||
typeString = "Any"
|
typeString = "Any"
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue