Skip to content

Commit 5d21c29

Browse files
committed
Rework API reference generator
This PR reworks the generator for API references: - Generalize the writer and reorganize packages and modules; - Add new generator for producing HTML result directly; - Fixed swagger definition that missed SchedulingClass definition. With this revised version: - We fix the problem of example code display which no longer occupy 45% of the screen; - The dependency on node JS; - The improper use of Go Template is gone; - The dependency on a docker image which team doesn't own is gone. The current "brodocs" way of reference generation is still there. We can remove it later when we are satisfied with this new "native" generator. To use the old "brodocs" generator, do `make brodocsapi` instead of `make api`.
1 parent 857109f commit 5d21c29

32 files changed

+3916
-1899
lines changed

Makefile

+4-1
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,12 @@ copycli: cli
4545
cp $(CLISRC)/node_modules/jquery/dist/jquery.min.js $(CLIDST)/node_modules/jquery/dist/jquery.min.js
4646
cp $(CLISRCFONT)/css/font-awesome.min.css $(CLIDSTFONT)/css/font-awesome.min.css
4747

48+
brodocsapi: cleanapi
49+
go run gen-apidocs/main.go --config-dir=gen-apidocs/generators --munge-groups=false --backend=brodocs
50+
docker run -v $(shell pwd)/gen-apidocs/generators/includes:/source -v $(shell pwd)/gen-apidocs/generators/build:/build -v $(shell pwd)/gen-apidocs/generators/:/manifest pwittrock/brodocs
51+
4852
api: cleanapi
4953
go run gen-apidocs/main.go --config-dir=gen-apidocs/generators --munge-groups=false
50-
docker run -v $(shell pwd)/gen-apidocs/generators/includes:/source -v $(shell pwd)/gen-apidocs/generators/build:/build -v $(shell pwd)/gen-apidocs/generators/:/manifest pwittrock/brodocs
5154

5255
# Build kube component docs
5356
cleancomp:

gen-apidocs/generators/api/api_version.go renamed to gen-apidocs/generators/api/api.go

+27-6
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,35 @@ package api
1818

1919
import (
2020
"regexp"
21+
"strings"
2122
)
2223

23-
type ApiVersion string
24+
func (a ApiGroup) String() string {
25+
return string(a)
26+
}
27+
28+
func (a ApiGroups) Len() int { return len(a) }
29+
func (a ApiGroups) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
30+
func (a ApiGroups) Less(i, j int) bool {
31+
// "apps" group APIs are newer than "extensions" group APIs
32+
if a[i].String() == "apps" && a[j].String() == "extensions" {
33+
return false
34+
}
35+
if a[j].String() == "apps" && a[i].String() == "extensions" {
36+
return true
37+
}
38+
return strings.Compare(a[i].String(), a[j].String()) < 0
39+
}
40+
41+
func (a ApiVersions) Len() int { return len(a) }
42+
func (a ApiVersions) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
43+
func (a ApiVersions) Less(i, j int) bool {
44+
return a[i].LessThan(a[j])
45+
}
46+
47+
func (k ApiKind) String() string {
48+
return string(k)
49+
}
2450

2551
func (this ApiVersion) LessThan(that ApiVersion) bool {
2652
re := regexp.MustCompile("(v\\d+)(alpha|beta|)(\\d*)")
@@ -52,14 +78,9 @@ func (this ApiVersion) LessThan(that ApiVersion) bool {
5278
}
5379
// The string with the higher number comes first (or in the case of alpha/beta, beta comes first)
5480
if v1 != v2 {
55-
//fmt.Printf("Less than %v (%s %s) this: %s %v that: %s %v\n", v1 < v2, v1, v2, this, thisMatches, that, thatMatches)
5681
return v1 > v2
5782
}
5883
}
5984

60-
// They have the same value
6185
return false
6286
}
63-
func (a ApiVersion) String() string {
64-
return string(a)
65-
}

gen-apidocs/generators/api/api_group.go

-48
This file was deleted.

gen-apidocs/generators/api/api_kind.go

-23
This file was deleted.

0 commit comments

Comments
 (0)