Skip to content

Commit 9f25fb9

Browse files
committed
Improve apiref with experimental and ignored CRD description
1 parent 8f9ee2c commit 9f25fb9

File tree

8 files changed

+109
-0
lines changed

8 files changed

+109
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,5 @@ go.work.sum
5757
.venv/
5858
release/
5959
site-src/reference/spec.md
60+
site-src/reference/specx.md
61+

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,12 @@ api-ref-docs:
198198
crd-ref-docs \
199199
--source-path=${PWD}/apis \
200200
--config=crd-ref-docs.yaml \
201+
--templates-dir=${PWD}/hack/crd-ref-templates/ \
201202
--renderer=markdown \
202203
--output-path=${PWD}/site-src/reference/spec.md
203204
crd-ref-docs \
204205
--source-path=${PWD}/apisx \
205206
--config=crd-ref-docs.yaml \
207+
--templates-dir=${PWD}/hack/crd-ref-templates/ \
206208
--renderer=markdown \
207209
--output-path=${PWD}/site-src/reference/specx.md

hack/crd-ref-templates/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
The templates contained in this directory were copied from https://github.com/elastic/crd-ref-docs/tree/master/templates/markdown
2+
and had the following modifications:
3+
4+
- `type.tpl` - Adds an "experimental" marker in case the API field is marked as "experimental"
5+
- `type_members.tpl` - Removes the text between tags `<gateway:util:excludeFromCRD></gateway:util:excludeFromCRD>`
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{{- define "gvDetails" -}}
2+
{{- $gv := . -}}
3+
4+
## {{ $gv.GroupVersionString }}
5+
6+
{{ $gv.Doc }}
7+
8+
{{- if $gv.Kinds }}
9+
### Resource Types
10+
{{- range $gv.SortedKinds }}
11+
- {{ $gv.TypeForKind . | markdownRenderTypeLink }}
12+
{{- end }}
13+
{{ end }}
14+
15+
{{ range $gv.SortedTypes }}
16+
{{ template "type" . }}
17+
{{ end }}
18+
19+
{{- end -}}

hack/crd-ref-templates/gv_list.tpl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{{- define "gvList" -}}
2+
{{- $groupVersions := . -}}
3+
4+
# API Reference
5+
6+
## Packages
7+
{{- range $groupVersions }}
8+
- {{ markdownRenderGVLink . }}
9+
{{- end }}
10+
11+
{{ range $groupVersions }}
12+
{{ template "gvDetails" . }}
13+
{{ end }}
14+
15+
{{- end -}}

hack/crd-ref-templates/type.tpl

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{{- define "type" -}}
2+
{{- $type := . -}}
3+
{{- if markdownShouldRenderType $type -}}
4+
5+
#### {{ $type.Name }}
6+
7+
{{ if $type.IsAlias }}_Underlying type:_ _{{ markdownRenderTypeLink $type.UnderlyingType }}_{{ end }}
8+
9+
{{ $type.Doc }}
10+
11+
{{ if $type.Validation -}}
12+
_Validation:_
13+
{{- range $type.Validation }}
14+
- {{ . }}
15+
{{- end }}
16+
{{- end }}
17+
18+
{{ if $type.References -}}
19+
_Appears in:_
20+
{{- range $type.SortedReferences }}
21+
- {{ markdownRenderTypeLink . }}
22+
{{- end }}
23+
{{- end }}
24+
25+
{{ if $type.Members -}}
26+
| Field | Description | Default | Validation |
27+
| --- | --- | --- | --- |
28+
{{ if $type.GVK -}}
29+
| `apiVersion` _string_ | `{{ $type.GVK.Group }}/{{ $type.GVK.Version }}` | | |
30+
| `kind` _string_ | `{{ $type.GVK.Kind }}` | | |
31+
{{ end -}}
32+
33+
{{ range $type.Members -}}
34+
| `{{ .Name }}` {{- if contains "<gateway:experimental>" .Doc }} **Experimental** {{ end -}} _{{ markdownRenderType .Type }}_ | {{ template "type_members" . }} | {{ markdownRenderDefault .Default }} | {{ range .Validation -}} {{ markdownRenderFieldDoc . }} <br />{{ end }} |
35+
{{ end -}}
36+
37+
{{ end -}}
38+
39+
{{ if $type.EnumValues -}}
40+
| Field | Description |
41+
| --- | --- |
42+
{{ range $type.EnumValues -}}
43+
| `{{ .Name }}` | {{ markdownRenderFieldDoc .Doc }} |
44+
{{ end -}}
45+
{{ end -}}
46+
47+
48+
{{- end -}}
49+
{{- end -}}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{{- define "type_members" -}}
2+
{{- $field := . -}}
3+
{{- if eq $field.Name "metadata" -}}
4+
Refer to Kubernetes API documentation for fields of `metadata`.
5+
{{- else -}}
6+
{{- $cleanDoc := regexReplaceAllLiteral "(?s)<gateway:util:excludeFromCRD>.*?</gateway:util:excludeFromCRD>" $field.Doc "" -}}
7+
{{ markdownRenderFieldDoc $cleanDoc }}
8+
{{- end -}}
9+
{{- end -}}

hack/mkdocs/generate.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,13 @@ go install github.com/elastic/crd-ref-docs
3232
${GOBIN}/crd-ref-docs \
3333
--source-path=${PWD}/apis \
3434
--config=crd-ref-docs.yaml \
35+
--templates-dir=${PWD}/hack/crd-ref-templates/ \
3536
--renderer=markdown \
3637
--output-path=${PWD}/site-src/reference/spec.md
38+
39+
${GOBIN}/crd-ref-docs \
40+
--source-path=${PWD}/apisx \
41+
--config=crd-ref-docs.yaml \
42+
--templates-dir=${PWD}/hack/crd-ref-templates/ \
43+
--renderer=markdown \
44+
--output-path=${PWD}/site-src/reference/specx.md

0 commit comments

Comments
 (0)