Skip to content

Commit 457cb46

Browse files
committed
Make headings past h6 bold
Fixes #1
1 parent 3baa56f commit 457cb46

File tree

4 files changed

+181
-13
lines changed

4 files changed

+181
-13
lines changed

ref.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package main
22

33
import (
44
"encoding/json"
5-
"fmt"
65
"io"
76
"log"
87
"net/http"
@@ -14,11 +13,6 @@ import (
1413
"github.com/xeipuuv/gojsonpointer"
1514
)
1615

17-
func dumpSchema(schem *schema) {
18-
b, _ := json.MarshalIndent(schem, "", " ")
19-
fmt.Println(string(b))
20-
}
21-
2216
// resolveSchema recursively resolves schemas.
2317
func resolveSchema(schem *schema, dir string, root *simplejson.Json) (*schema, error) {
2418
for _, prop := range schem.Properties {

schema.go

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package main
33
import (
44
"bytes"
55
"encoding/json"
6-
"errors"
76
"fmt"
87
"io"
98
"io/ioutil"
@@ -14,8 +13,6 @@ import (
1413
"github.com/olekukonko/tablewriter"
1514
)
1615

17-
var errCrossSchemaReference = errors.New("cross-schema reference")
18-
1916
type schema struct {
2017
ID string `json:"$id,omitempty"`
2118
Ref string `json:"$ref,omitempty"`
@@ -62,7 +59,7 @@ func (s schema) Markdown(level int) string {
6259
var buf bytes.Buffer
6360

6461
if s.Title != "" {
65-
fmt.Fprintln(&buf, strings.Repeat("#", level)+" "+s.Title)
62+
fmt.Fprintln(&buf, makeHeading(s.Title, level))
6663
fmt.Fprintln(&buf)
6764
}
6865

@@ -72,7 +69,7 @@ func (s schema) Markdown(level int) string {
7269
}
7370

7471
if len(s.Properties) > 0 {
75-
fmt.Fprintln(&buf, strings.Repeat("#", level+1)+" Properties")
72+
fmt.Fprintln(&buf, makeHeading("Properties", level+1))
7673
fmt.Fprintln(&buf)
7774
}
7875

@@ -82,12 +79,24 @@ func (s schema) Markdown(level int) string {
8279
fmt.Fprintln(&buf)
8380

8481
for _, obj := range findDefinitions(&s) {
85-
fmt.Fprintf(&buf, obj.Markdown(level+1))
82+
fmt.Fprint(&buf, obj.Markdown(level+1))
8683
}
8784

8885
return buf.String()
8986
}
9087

88+
func makeHeading(heading string, level int) string {
89+
if level < 0 {
90+
return heading
91+
}
92+
93+
if level <= 6 {
94+
return strings.Repeat("#", level) + " " + heading
95+
}
96+
97+
return fmt.Sprintf("**%s**", heading)
98+
}
99+
91100
func findDefinitions(s *schema) []*schema {
92101
// Gather all properties of object type so that we can generate the
93102
// properties for them recursively.

schema_test.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ func TestSchema(t *testing.T) {
1616
schemaTests := []struct {
1717
name string
1818
schema string
19+
level int
1920
}{
2021
{name: "address", schema: "address.schema.json"},
2122
{name: "arrays", schema: "arrays.schema.json"},
@@ -24,6 +25,7 @@ func TestSchema(t *testing.T) {
2425
{name: "card", schema: "card.schema.json"},
2526
{name: "geographical-location", schema: "geographical-location.schema.json"},
2627
{name: "ref-hell", schema: "ref-hell.schema.json"},
28+
{name: "deep-headings", schema: "ref-hell.schema.json", level: 5},
2729
}
2830

2931
for _, tt := range schemaTests {
@@ -40,7 +42,12 @@ func TestSchema(t *testing.T) {
4042
}
4143

4244
var buf bytes.Buffer
43-
buf.WriteString(schema.Markdown(1))
45+
46+
if tt.level > 0 {
47+
buf.WriteString(schema.Markdown(tt.level))
48+
} else {
49+
buf.WriteString(schema.Markdown(1))
50+
}
4451

4552
gp := filepath.Join("testdata", strings.Replace(t.Name()+".golden", "/", "_", -1))
4653
if *update {
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
A representation of a person, company, organization, or place
2+
3+
###### Properties
4+
5+
| Property | Type | Required | Description |
6+
|--------------|-------------------------|----------|-------------|
7+
| `fruits` | [object](#fruits)[] | No | |
8+
| `vegetables` | [object](#vegetables)[] | No | |
9+
10+
###### fruits
11+
12+
**Properties**
13+
14+
| Property | Type | Required | Description |
15+
|----------|-----------------|----------|---------------------------------------------------------------|
16+
| `adr` | [object](#adr) | No | An address similar to http://microformats.org/wiki/h-card |
17+
| `cal` | [object](#cal) | No | A representation of an event |
18+
| `card` | [object](#card) | No | A representation of a person, company, organization, or place |
19+
20+
**adr**
21+
22+
An address similar to http://microformats.org/wiki/h-card
23+
24+
**Properties**
25+
26+
| Property | Type | Required | Description |
27+
|--------------------|--------|----------|-------------|
28+
| `country-name` | string | **Yes** | |
29+
| `locality` | string | **Yes** | |
30+
| `region` | string | **Yes** | |
31+
| `extended-address` | string | No | |
32+
| `post-office-box` | string | No | |
33+
| `postal-code` | string | No | |
34+
| `street-address` | string | No | |
35+
36+
**cal**
37+
38+
A representation of an event
39+
40+
**Properties**
41+
42+
| Property | Type | Required | Description |
43+
|---------------|----------------|----------|----------------------------|
44+
| `dtstart` | string | **Yes** | Event starting time |
45+
| `summary` | string | **Yes** | |
46+
| `category` | string | No | |
47+
| `description` | string | No | |
48+
| `dtend` | string | No | Event ending time |
49+
| `duration` | string | No | Event duration |
50+
| `geo` | [object](#geo) | No | A geographical coordinate. |
51+
| `location` | string | No | |
52+
| `rdate` | string | No | Recurrence date |
53+
| `rrule` | string | No | Recurrence rule |
54+
| `url` | string | No | |
55+
56+
**geo**
57+
58+
A geographical coordinate.
59+
60+
**Properties**
61+
62+
| Property | Type | Required | Description |
63+
|-------------|--------|----------|-------------|
64+
| `latitude` | number | **Yes** | |
65+
| `longitude` | number | **Yes** | |
66+
67+
**card**
68+
69+
A representation of a person, company, organization, or place
70+
71+
**Properties**
72+
73+
| Property | Type | Required | Description |
74+
|-------------------|------------------|----------|-----------------------------------------------------------|
75+
| `familyName` | string | **Yes** | |
76+
| `givenName` | string | **Yes** | |
77+
| `additionalName` | string[] | No | |
78+
| `adr` | [object](#adr) | No | An address similar to http://microformats.org/wiki/h-card |
79+
| `bday` | string | No | |
80+
| `email` | [object](#email) | No | |
81+
| `fn` | string | No | Formatted Name |
82+
| `geo` | [object](#geo) | No | A geographical coordinate. |
83+
| `honorificPrefix` | string[] | No | |
84+
| `honorificSuffix` | string[] | No | |
85+
| `logo` | string | No | |
86+
| `nickname` | string | No | |
87+
| `org` | [object](#org) | No | |
88+
| `photo` | string | No | |
89+
| `role` | string | No | |
90+
| `sound` | string | No | |
91+
| `tel` | [object](#tel) | No | |
92+
| `title` | string | No | |
93+
| `tz` | string | No | |
94+
| `url` | string | No | |
95+
96+
**adr**
97+
98+
An address similar to http://microformats.org/wiki/h-card
99+
100+
**Properties**
101+
102+
| Property | Type | Required | Description |
103+
|--------------------|--------|----------|-------------|
104+
| `country-name` | string | **Yes** | |
105+
| `locality` | string | **Yes** | |
106+
| `region` | string | **Yes** | |
107+
| `extended-address` | string | No | |
108+
| `post-office-box` | string | No | |
109+
| `postal-code` | string | No | |
110+
| `street-address` | string | No | |
111+
112+
**email**
113+
114+
**Properties**
115+
116+
| Property | Type | Required | Description |
117+
|----------|--------|----------|-------------|
118+
| `type` | string | No | |
119+
| `value` | string | No | |
120+
121+
**geo**
122+
123+
A geographical coordinate.
124+
125+
**Properties**
126+
127+
| Property | Type | Required | Description |
128+
|-------------|--------|----------|-------------|
129+
| `latitude` | number | **Yes** | |
130+
| `longitude` | number | **Yes** | |
131+
132+
**org**
133+
134+
**Properties**
135+
136+
| Property | Type | Required | Description |
137+
|--------------------|--------|----------|-------------|
138+
| `organizationName` | string | No | |
139+
| `organizationUnit` | string | No | |
140+
141+
**tel**
142+
143+
**Properties**
144+
145+
| Property | Type | Required | Description |
146+
|----------|--------|----------|-------------|
147+
| `type` | string | No | |
148+
| `value` | string | No | |
149+
150+
###### vegetables
151+
152+
**Properties**
153+
154+
| Property | Type | Required | Description |
155+
|--------------|---------|----------|----------------------------|
156+
| `veggieLike` | boolean | **Yes** | Do I like this vegetable? |
157+
| `veggieName` | string | **Yes** | The name of the vegetable. |
158+

0 commit comments

Comments
 (0)