-
Notifications
You must be signed in to change notification settings - Fork 367
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add hack script to generare reference docs for the Antrea API #1507
Merged
antoninbas
merged 1 commit into
antrea-io:master
from
antoninbas:add-script-to-generate-api-reference-docs
Dec 4, 2020
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"hideMemberFields": [ | ||
"TypeMeta" | ||
], | ||
"hideTypePatterns": [ | ||
"ParseError$", | ||
"List$" | ||
], | ||
"externalPackages": [ | ||
{ | ||
"typeMatchPrefix": "^k8s\\.io/apimachinery/pkg/apis/meta/v1\\.Duration$", | ||
"docsURLTemplate": "https://godoc.org/k8s.io/apimachinery/pkg/apis/meta/v1#Duration" | ||
}, | ||
{ | ||
"typeMatchPrefix": "^k8s\\.io/apimachinery/pkg/types\\.UID$", | ||
"docsURLTemplate": "https://godoc.org/k8s.io/apimachinery/pkg/types#UID" | ||
}, | ||
{ | ||
"typeMatchPrefix": "^k8s\\.io/apimachinery/pkg/util/intstr\\.IntOrString$", | ||
"docsURLTemplate": "https://godoc.org/k8s.io/apimachinery/pkg/util/intstr#IntOrString" | ||
}, | ||
{ | ||
"typeMatchPrefix": "^k8s\\.io/(api|apimachinery/pkg/apis)/", | ||
"docsURLTemplate": "https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.18/#{{lower .TypeIdentifier}}-{{arrIndex .PackageSegments -1}}-{{arrIndex .PackageSegments -2}}" | ||
} | ||
], | ||
"typeDisplayNamePrefixOverrides": { | ||
"k8s.io/api/": "Kubernetes ", | ||
"k8s.io/apimachinery/pkg/apis/": "Kubernetes " | ||
}, | ||
"markdownDisabled": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Copyright 2020 Antrea Authors | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# This script is used to generate the reference docs for the Antrea API, which | ||
# is included in the antrea.io website. | ||
|
||
set -eo pipefail | ||
|
||
OUTPUT=api-reference.html | ||
|
||
TMP_DIR=$(mktemp -d) | ||
|
||
function exit_handler() { | ||
rm -rf $TMP_DIR | ||
} | ||
|
||
trap exit_handler INT EXIT | ||
|
||
git clone --branch antrea https://github.com/antoninbas/gen-crd-api-reference-docs.git $TMP_DIR/refdocs | ||
cd $TMP_DIR/refdocs && go build -o gen && cd - | ||
|
||
BIN=$TMP_DIR/refdocs/gen | ||
|
||
$BIN -config gen-config.json -api-dir github.com/vmware-tanzu/antrea/pkg/apis -out-file $OUTPUT -template-dir template -skip-missing-api-version | ||
|
||
echo "API reference doc generated as $OUTPUT" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
{{ define "members" }} | ||
|
||
{{ range .Members }} | ||
{{ if not (hiddenMember .)}} | ||
<tr> | ||
<td> | ||
<code>{{ fieldName . }}</code></br> | ||
<em> | ||
{{ if linkForType .Type }} | ||
<a href="{{ linkForType .Type}}"> | ||
{{ typeDisplayName .Type }} | ||
</a> | ||
{{ else }} | ||
{{ typeDisplayName .Type }} | ||
{{ end }} | ||
</em> | ||
</td> | ||
<td> | ||
{{ if fieldEmbedded . }} | ||
<p> | ||
(Members of <code>{{ fieldName . }}</code> are embedded into this type.) | ||
</p> | ||
{{ end}} | ||
|
||
{{ if isOptionalMember .}} | ||
<em>(Optional)</em> | ||
{{ end }} | ||
|
||
{{ safe (renderComments .CommentLines) }} | ||
|
||
{{ if and (eq (.Type.Name.Name) "ObjectMeta") }} | ||
Refer to the Kubernetes API documentation for the fields of the | ||
<code>metadata</code> field. | ||
{{ end }} | ||
|
||
{{ if or (eq (fieldName .) "spec") }} | ||
<br/> | ||
<br/> | ||
<table> | ||
{{ template "members" .Type }} | ||
</table> | ||
{{ end }} | ||
</td> | ||
</tr> | ||
{{ end }} | ||
{{ end }} | ||
|
||
{{ end }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
{{ define "packages" }} | ||
|
||
{{ with .packages}} | ||
<p>Packages:</p> | ||
<ul> | ||
{{ range . }} | ||
<li> | ||
<a href="#{{- packageAnchorID . -}}">{{ packageDisplayName . }}</a> | ||
</li> | ||
{{ end }} | ||
</ul> | ||
{{ end}} | ||
|
||
{{ range .packages }} | ||
<h2 id="{{- packageAnchorID . -}}"> | ||
{{- packageDisplayName . -}} | ||
</h2> | ||
|
||
{{ with (index .GoPackages 0 )}} | ||
{{ with .DocComments }} | ||
<p> | ||
{{ safe (renderComments .) }} | ||
</p> | ||
{{ end }} | ||
{{ end }} | ||
|
||
Resource Types: | ||
<ul> | ||
{{- range (visibleTypes (sortedTypes .Types)) -}} | ||
{{ if isExportedType . -}} | ||
<li> | ||
<a href="{{ linkForType . }}">{{ typeDisplayName . }}</a> | ||
</li> | ||
{{- end }} | ||
{{- end -}} | ||
</ul> | ||
|
||
{{ range (visibleTypes (sortedTypes .Types))}} | ||
{{ template "type" . }} | ||
{{ end }} | ||
<hr/> | ||
{{ end }} | ||
|
||
<p><em> | ||
Generated with <code>gen-crd-api-reference-docs</code> | ||
{{ with .gitCommit }} on git commit <code>{{ . }}</code>{{end}}. | ||
</em></p> | ||
|
||
{{ end }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
{{ define "type" }} | ||
|
||
<h3 id="{{ anchorIDForType . }}"> | ||
{{- .Name.Name }} | ||
{{ if eq .Kind "Alias" }}(<code>{{.Underlying}}</code> alias)</p>{{ end -}} | ||
</h3> | ||
{{ with (typeReferences .) }} | ||
<p> | ||
(<em>Appears on:</em> | ||
{{- $prev := "" -}} | ||
{{- range . -}} | ||
{{- if $prev -}}, {{ end -}} | ||
{{ $prev = . }} | ||
<a href="{{ linkForType . }}">{{ typeDisplayName . }}</a> | ||
{{- end -}} | ||
) | ||
</p> | ||
{{ end }} | ||
|
||
|
||
<p> | ||
{{ safe (renderComments .CommentLines) }} | ||
</p> | ||
|
||
{{ if .Members }} | ||
<table> | ||
<thead> | ||
<tr> | ||
<th>Field</th> | ||
<th>Description</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{{ if isExportedType . }} | ||
<tr> | ||
<td> | ||
<code>apiVersion</code></br> | ||
string</td> | ||
<td> | ||
<code> | ||
{{apiGroup .}} | ||
</code> | ||
</td> | ||
</tr> | ||
<tr> | ||
<td> | ||
<code>kind</code></br> | ||
string | ||
</td> | ||
<td><code>{{.Name.Name}}</code></td> | ||
</tr> | ||
{{ end }} | ||
{{ template "members" .}} | ||
</tbody> | ||
</table> | ||
{{ end }} | ||
|
||
{{ end }} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this text looks like something that is K8s API doc related.. im not sure how and where this is used though
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry for the delay, what's your question?
I didn't write this file, I copied it from https://github.com/ahmetb/gen-crd-api-reference-docs as it seems to be how it's meant to be used. My understanding is that this specific part generates a generic description for the
ObjectMeta
fields in API resources. See https://antrea.io/docs/master/api-reference/.