Skip to content

Commit 57a36b5

Browse files
committed
skip empty messages and services
1 parent 3707518 commit 57a36b5

File tree

4 files changed

+937
-77
lines changed

4 files changed

+937
-77
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ protodoc generates Protocol Buffer documentation.
99
go get -v -u github.com/coreos/protodoc
1010
1111
protodoc ./parse/testdata \
12-
--language-options="Go,C++,Java,Python" \
12+
--languages="Go,C++,Java,Python" \
1313
--title="testdata" \
1414
--target-path="./sample.md"
1515
```

parse/markdown.go

Lines changed: 59 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,20 @@ func (p *Proto) Markdown(title, fpath string, lopts ...string) error {
3434
buf.WriteString(svs.Description)
3535
buf.WriteString("\n\n")
3636
}
37-
hd1 := "| Method | Request Type | Response Type | Description |"
38-
hd2 := "| ------ | ------------ | ------------- | ----------- |"
39-
buf.WriteString(hd1 + "\n")
40-
buf.WriteString(hd2 + "\n")
4137

42-
for _, elem := range svs.Methods {
43-
line := fmt.Sprintf("| %s | `%s` | `%s` | %s |", elem.Name, elem.RequestType, elem.ResponseType, elem.Description)
44-
buf.WriteString(line + "\n")
38+
if len(svs.Methods) > 0 {
39+
hd1 := "| Method | Request Type | Response Type | Description |"
40+
hd2 := "| ------ | ------------ | ------------- | ----------- |"
41+
buf.WriteString(hd1 + "\n")
42+
buf.WriteString(hd2 + "\n")
43+
for _, elem := range svs.Methods {
44+
line := fmt.Sprintf("| %s | `%s` | `%s` | %s |", elem.Name, elem.RequestType, elem.ResponseType, elem.Description)
45+
buf.WriteString(line + "\n")
46+
}
47+
} else {
48+
buf.WriteString("Empty method.\n")
4549
}
50+
4651
buf.WriteString("\n\n<br>\n\n")
4752
}
4853

@@ -52,55 +57,61 @@ func (p *Proto) Markdown(title, fpath string, lopts ...string) error {
5257
buf.WriteString(msg.Description)
5358
buf.WriteString("\n\n")
5459
}
55-
hd1 := "| Field | Description | Type |"
56-
hd2 := "| ----- | ----------- | ---- |"
57-
for _, lopt := range lopts {
58-
hd1 += fmt.Sprintf(" %s |", lopt)
59-
ds := strings.Repeat("-", len(lopt))
60-
if len(ds) < 3 {
61-
ds = "---"
62-
}
63-
hd2 += fmt.Sprintf(" %s |", ds)
64-
}
65-
buf.WriteString(hd1 + "\n")
66-
buf.WriteString(hd2 + "\n")
67-
for _, elem := range msg.Fields {
68-
ts := elem.ProtoType.String()
69-
if elem.UserDefinedProtoType != "" {
70-
ts = elem.UserDefinedProtoType
71-
}
72-
if elem.Repeated {
73-
ts = "(slice of) " + ts
74-
}
75-
line := fmt.Sprintf("| %s | %s | %s |", elem.Name, elem.Description, ts)
60+
61+
if len(msg.Fields) > 0 {
62+
hd1 := "| Field | Description | Type |"
63+
hd2 := "| ----- | ----------- | ---- |"
7664
for _, lopt := range lopts {
65+
hd1 += fmt.Sprintf(" %s |", lopt)
66+
ds := strings.Repeat("-", len(lopt))
67+
if len(ds) < 3 {
68+
ds = "---"
69+
}
70+
hd2 += fmt.Sprintf(" %s |", ds)
71+
}
72+
buf.WriteString(hd1 + "\n")
73+
buf.WriteString(hd2 + "\n")
74+
for _, elem := range msg.Fields {
75+
ts := elem.ProtoType.String()
7776
if elem.UserDefinedProtoType != "" {
78-
line += " |"
79-
continue
77+
ts = elem.UserDefinedProtoType
8078
}
81-
formatSt := " %s |"
8279
if elem.Repeated {
83-
formatSt = " (slice of) %s |"
80+
ts = "(slice of) " + ts
8481
}
85-
switch lopt {
86-
case "C++":
87-
line += fmt.Sprintf(formatSt, elem.ProtoType.Cpp())
88-
case "Java":
89-
line += fmt.Sprintf(formatSt, elem.ProtoType.Java())
90-
case "Python":
91-
line += fmt.Sprintf(formatSt, elem.ProtoType.Python())
92-
case "Go":
93-
line += fmt.Sprintf(formatSt, elem.ProtoType.Go())
94-
case "Ruby":
95-
line += fmt.Sprintf(formatSt, elem.ProtoType.Ruby())
96-
case "C#":
97-
line += fmt.Sprintf(formatSt, elem.ProtoType.Csharp())
98-
default:
99-
return fmt.Errorf("%q is unknown (must be C++, Java, Python, Go, Ruby, C#)", lopt)
82+
line := fmt.Sprintf("| %s | %s | %s |", elem.Name, elem.Description, ts)
83+
for _, lopt := range lopts {
84+
if elem.UserDefinedProtoType != "" {
85+
line += " |"
86+
continue
87+
}
88+
formatSt := " %s |"
89+
if elem.Repeated {
90+
formatSt = " (slice of) %s |"
91+
}
92+
switch lopt {
93+
case "C++":
94+
line += fmt.Sprintf(formatSt, elem.ProtoType.Cpp())
95+
case "Java":
96+
line += fmt.Sprintf(formatSt, elem.ProtoType.Java())
97+
case "Python":
98+
line += fmt.Sprintf(formatSt, elem.ProtoType.Python())
99+
case "Go":
100+
line += fmt.Sprintf(formatSt, elem.ProtoType.Go())
101+
case "Ruby":
102+
line += fmt.Sprintf(formatSt, elem.ProtoType.Ruby())
103+
case "C#":
104+
line += fmt.Sprintf(formatSt, elem.ProtoType.Csharp())
105+
default:
106+
return fmt.Errorf("%q is unknown (must be C++, Java, Python, Go, Ruby, C#)", lopt)
107+
}
100108
}
109+
buf.WriteString(line + "\n")
101110
}
102-
buf.WriteString(line + "\n")
111+
} else {
112+
buf.WriteString("Empty field.\n")
103113
}
114+
104115
buf.WriteString("\n\n<br>\n\n")
105116
}
106117

parse/testdata/README.md

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,7 @@
114114

115115
##### message `AuthDisableRequest`
116116

117-
| Field | Description | Type | Go | Java | Python | C++ |
118-
| ----- | ----------- | ---- | --- | ---- | ------ | --- |
117+
Empty field.
119118

120119

121120
<br>
@@ -131,8 +130,7 @@
131130

132131
##### message `AuthEnableRequest`
133132

134-
| Field | Description | Type | Go | Java | Python | C++ |
135-
| ----- | ----------- | ---- | --- | ---- | ------ | --- |
133+
Empty field.
136134

137135

138136
<br>
@@ -166,8 +164,7 @@
166164

167165
##### message `AuthRoleDeleteRequest`
168166

169-
| Field | Description | Type | Go | Java | Python | C++ |
170-
| ----- | ----------- | ---- | --- | ---- | ------ | --- |
167+
Empty field.
171168

172169

173170
<br>
@@ -183,8 +180,7 @@
183180

184181
##### message `AuthRoleGetRequest`
185182

186-
| Field | Description | Type | Go | Java | Python | C++ |
187-
| ----- | ----------- | ---- | --- | ---- | ------ | --- |
183+
Empty field.
188184

189185

190186
<br>
@@ -219,8 +215,7 @@
219215

220216
##### message `AuthRoleRevokeRequest`
221217

222-
| Field | Description | Type | Go | Java | Python | C++ |
223-
| ----- | ----------- | ---- | --- | ---- | ------ | --- |
218+
Empty field.
224219

225220

226221
<br>
@@ -292,8 +287,7 @@
292287

293288
##### message `AuthUserGetRequest`
294289

295-
| Field | Description | Type | Go | Java | Python | C++ |
296-
| ----- | ----------- | ---- | --- | ---- | ------ | --- |
290+
Empty field.
297291

298292

299293
<br>
@@ -328,8 +322,7 @@
328322

329323
##### message `AuthUserRevokeRequest`
330324

331-
| Field | Description | Type | Go | Java | Python | C++ |
332-
| ----- | ----------- | ---- | --- | ---- | ------ | --- |
325+
Empty field.
333326

334327

335328
<br>
@@ -345,8 +338,7 @@
345338

346339
##### message `AuthenticateRequest`
347340

348-
| Field | Description | Type | Go | Java | Python | C++ |
349-
| ----- | ----------- | ---- | --- | ---- | ------ | --- |
341+
Empty field.
350342

351343

352344
<br>
@@ -399,8 +391,7 @@ Compaction compacts the kv store upto a given revision. All superseded keys with
399391

400392
##### message `DefragmentRequest`
401393

402-
| Field | Description | Type | Go | Java | Python | C++ |
403-
| ----- | ----------- | ---- | --- | ---- | ------ | --- |
394+
Empty field.
404395

405396

406397
<br>
@@ -436,16 +427,14 @@ Compaction compacts the kv store upto a given revision. All superseded keys with
436427

437428
##### message `EmptyResponse`
438429

439-
| Field | Description | Type | Go | Java | Python | C++ |
440-
| ----- | ----------- | ---- | --- | ---- | ------ | --- |
430+
Empty field.
441431

442432

443433
<br>
444434

445435
##### message `HashRequest`
446436

447-
| Field | Description | Type | Go | Java | Python | C++ |
448-
| ----- | ----------- | ---- | --- | ---- | ------ | --- |
437+
Empty field.
449438

450439

451440
<br>
@@ -580,8 +569,7 @@ An InternalRaftRequest is the union of all requests which can be sent via raft.
580569

581570
##### message `MemberListRequest`
582571

583-
| Field | Description | Type | Go | Java | Python | C++ |
584-
| ----- | ----------- | ---- | --- | ---- | ------ | --- |
572+
Empty field.
585573

586574

587575
<br>
@@ -752,8 +740,7 @@ An InternalRaftRequest is the union of all requests which can be sent via raft.
752740

753741
##### message `SnapshotRequest`
754742

755-
| Field | Description | Type | Go | Java | Python | C++ |
756-
| ----- | ----------- | ---- | --- | ---- | ------ | --- |
743+
Empty field.
757744

758745

759746
<br>
@@ -771,8 +758,7 @@ An InternalRaftRequest is the union of all requests which can be sent via raft.
771758

772759
##### message `StatusRequest`
773760

774-
| Field | Description | Type | Go | Java | Python | C++ |
775-
| ----- | ----------- | ---- | --- | ---- | ------ | --- |
761+
Empty field.
776762

777763

778764
<br>

0 commit comments

Comments
 (0)