This is an automated email from the ASF dual-hosted git repository. djencks pushed a commit to branch release-1.4.x in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit 2e59c983b5c95e7e8954e1d7b34af15139023eb6 Author: David Jencks <djen...@apache.org> AuthorDate: Thu Jan 20 20:47:52 2022 -0800 Generate api documentation similarly to later versions. update gen_crd_api script/config to use go run and asciidoc config add /github.com to .gitignore, it's similar to /vendor use AsciiDoc API templates --- .gitignore | 1 + script/gen_crd/gen-crd-api-config.json | 22 ++++++++++++++ script/gen_crd/gen-kamelets-crd-api-config.json | 26 +++++++++++++++++ script/gen_crd/gen_crd_api.sh | 39 +++++++++++++++++++++++++ script/gen_crd/template/members.tpl | 30 +++++++++++++++++++ script/gen_crd/template/pkg.tpl | 32 ++++++++++++++++++++ script/gen_crd/template/type.tpl | 32 ++++++++++++++++++++ script/gen_doc.sh | 6 +++- 8 files changed, 187 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 4698207..0d4d8b1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ # Go vendor /vendor +/github.com # Binary files /kamel diff --git a/script/gen_crd/gen-crd-api-config.json b/script/gen_crd/gen-crd-api-config.json new file mode 100644 index 0000000..1a6ae0d --- /dev/null +++ b/script/gen_crd/gen-crd-api-config.json @@ -0,0 +1,22 @@ +{ + "hideMemberFields": [ + "TypeMeta", + "baseErrorHandler" + ], + "hideTypePatterns": [ + "ParseError$", + "List$" + ], + "externalPackages": [ + { + "typeMatchPrefix": "^k8s\\.io/(api|apimachinery/pkg/apis)/", + "docsURLTemplate": "https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.20/#{{lower .TypeIdentifier}}-{{arrIndex .PackageSegments -1}}-{{arrIndex .PackageSegments -2}}" + } + ], + "typeDisplayNamePrefixOverrides": { + "k8s.io/api/": "Kubernetes ", + "k8s.io/apimachinery/pkg/apis/": "Kubernetes " + }, + "markdownDisabled": true, + "asciiDoc": true +} diff --git a/script/gen_crd/gen-kamelets-crd-api-config.json b/script/gen_crd/gen-kamelets-crd-api-config.json new file mode 100644 index 0000000..0e67016 --- /dev/null +++ b/script/gen_crd/gen-kamelets-crd-api-config.json @@ -0,0 +1,26 @@ +{ + "hideMemberFields": [ + "TypeMeta", + "baseErrorHandler" + ], + "hideTypePatterns": [ + "ParseError$", + "List$" + ], + "externalPackages": [ + { + "typeMatchPrefix": "^k8s\\.io/(api|apimachinery/pkg/apis)/", + "docsURLTemplate": "https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.20/#{{lower .TypeIdentifier}}-{{arrIndex .PackageSegments -1}}-{{arrIndex .PackageSegments -2}}" + }, + { + "typeMatchPrefix": "^github\\.com/apache/camel-k/pkg/apis/camel/v1\\.", + "docsURLTemplate": "xref:apis/camel-k.adoc#_camel_apache_org_v1_{{.TypeIdentifier}}" + } + ], + "typeDisplayNamePrefixOverrides": { + "k8s.io/api/": "Kubernetes ", + "k8s.io/apimachinery/pkg/apis/": "Kubernetes " + }, + "markdownDisabled": true, + "asciiDoc": true +} diff --git a/script/gen_crd/gen_crd_api.sh b/script/gen_crd/gen_crd_api.sh new file mode 100755 index 0000000..f4d696f --- /dev/null +++ b/script/gen_crd/gen_crd_api.sh @@ -0,0 +1,39 @@ +#!/bin/sh + +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You 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. + +location=$(dirname $0) +rootdir=$location/../.. +crd_file_camel=$rootdir/docs/modules/ROOT/partials/apis/camel-k-crds.adoc +crd_file_kamelets=$rootdir/docs/modules/ROOT/partials/apis/kamelets-crds.adoc + +echo "Generating CRD API documentation..." +# to run a local copy use something like +#go run /Users/david/projects/camel/gen-crd-api-reference-docs/main.go \ +#you will probably need to comment out use of blackfriday. +go run github.com/djencks/gen-crd-api-reference-docs@7400a10b36d7cfa7563ea48ce0df15a9d4c2de87 \ + -config $location/gen-crd-api-config.json \ + -template-dir $location/template \ + -api-dir "github.com/apache/camel-k/pkg/apis/camel/v1" \ + -out-file $crd_file_camel + +go run github.com/djencks/gen-crd-api-reference-docs@7400a10b36d7cfa7563ea48ce0df15a9d4c2de87 \ + -config $location/gen-kamelets-crd-api-config.json \ + -template-dir $location/template \ + -api-dir "github.com/apache/camel-k/pkg/apis/camel/v1alpha1" \ + -out-file $crd_file_kamelets + +echo "Generating CRD API documentation... Done." diff --git a/script/gen_crd/template/members.tpl b/script/gen_crd/template/members.tpl new file mode 100644 index 0000000..5771f11 --- /dev/null +++ b/script/gen_crd/template/members.tpl @@ -0,0 +1,30 @@ +{{ define "members" -}} + +{{ range .Members -}} + {{- if not (hiddenMember .) -}} +|`{{ fieldName . }}` + +{{ if linkForType .Type -}} + {{- if isLocalType .Type -}} +*xref:{{ linkForType .Type}}[{{ asciiDocAttributeEscape (typeDisplayName .Type) }}]* + {{- else -}} +*{{ linkForType .Type}}[{{ asciiDocAttributeEscape (typeDisplayName .Type) }}]* + {{- end -}} +{{- else -}} + {{- typeDisplayName .Type -}} +{{- end }} +|{{ if fieldEmbedded . -}} +(Members of `{{ fieldName . }}` are embedded into this type.) +{{- end }} +{{ if isOptionalMember . -}} +*(Optional)* +{{- end }} + +{{ renderComments .CommentLines }} + +{{ if and (eq (.Type.Name.Name) "ObjectMeta") -}} +Refer to the Kubernetes API documentation for the fields of the `metadata` field. +{{ end -}} +{{- end -}} +{{- end -}} + +{{- end }} diff --git a/script/gen_crd/template/pkg.tpl b/script/gen_crd/template/pkg.tpl new file mode 100644 index 0000000..c0cb3b4 --- /dev/null +++ b/script/gen_crd/template/pkg.tpl @@ -0,0 +1,32 @@ +{{ define "packages" -}} +{{ range .packages -}} + +[#{{ packageAnchorID . }}] +== {{ packageDisplayName . }} + + {{- with (index .GoPackages 0 ) -}} + {{- with .DocComments }} + +{{ renderComments . }} + {{- end -}} + {{- end }} + +== Resource Types + + {{- range (visibleTypes (sortedTypes .Types)) -}} + {{- if isExportedType . -}} + {{- template "type" . }} + {{- end -}} + {{- end }} + +== Internal Types + + {{- range (visibleTypes (sortedTypes .Types)) -}} + {{- if not (isExportedType .) -}} + {{- template "type" . }} + {{- end -}} + {{- end -}} + +{{- end -}} + +{{- end }} diff --git a/script/gen_crd/template/type.tpl b/script/gen_crd/template/type.tpl new file mode 100644 index 0000000..d6f0dcf --- /dev/null +++ b/script/gen_crd/template/type.tpl @@ -0,0 +1,32 @@ +{{ define "type" }} + +[#{{ anchorIDForType . }}] +=== {{ .Name.Name }}{{ if eq .Kind "Alias" }}(`{{.Underlying}}` alias){{ end }} +{{- with (typeReferences .) }} + +*Appears on:* +{{ range . }} +* <<{{ linkForType . }}, {{ typeDisplayName . }}>> +{{- end -}} +{{- end }} + +{{ renderComments .CommentLines }} +{{ if .Members }} +[cols="2,2a",options="header"] +|=== +|Field +|Description +{{ if isExportedType . }} +|`apiVersion` + +string +|`{{apiGroup .}}` + +|`kind` + +string +|`{{.Name.Name}}` +{{- end }} +{{ template "members" . }} +|=== +{{- end -}} + +{{- end -}} diff --git a/script/gen_doc.sh b/script/gen_doc.sh index 95ad4c9..d5f8371 100755 --- a/script/gen_doc.sh +++ b/script/gen_doc.sh @@ -18,7 +18,11 @@ location=$(dirname $0) rootdir=$location/.. -echo "Generating traits documentation..." +echo "Generating API documentation..." +$location/gen_crd/gen_crd_api.sh +echo "Generating API documentation... done!" +echo "Generating traits documentation..." cd $rootdir go run ./cmd/util/doc-gen --input-dirs ./pkg/trait --input-dirs ./addons/master --input-dirs ./addons/threescale --input-dirs ./addons/tracing +echo "Generating traits documentation... done!" \ No newline at end of file