Skip to content
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

Tool that supports automatically generating API documentation #5615

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

Catherine-monk
Copy link

Introduction

Tool that supports automatically generating API documentation.

Implementation Method

  1. Generate OpenAPI definitions using openapi-gen: The openapi-gen tool generates Go template code containing OpenAPI definitions from comment information. By adding a specific annotation +k8s:openapigen=true in the doc.go file, openapi-gen will scan all types in the package to generate OpenAPI definitions, which are stored in the zz_generated.openapi.go file.

  2. Generate OpenAPI Specification:
    Write generate-swagger.go referencing the generated OpenAPI definitions (zz_generated.openapi.go) to create the OpenAPI specification (swagger.json). The swagger.json file contains all the OpenAPI definition information of the apiserver.

Contents of generateswagger.go include:

  • Create a Schema object for type registration and object instantiation.
  • Create a REST Mapper for converting between GVR (Group Version Resource) and GVK (Group Version Kind).
  • Add specific mappings for various Kubeedge resources.
  • Set the information for the OpenAPI specification.

Usage

First, run ./apidoc/tools/generate-openapi.sh to generate the OpenAPI definitions, then execute ./apidoc/tools/update-swagger-docs.sh to generate the OpenAPI specification.

@kubeedge-bot kubeedge-bot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label May 15, 2024
Copy link
Collaborator

@Shelley-BaoYue Shelley-BaoYue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please using make verify to update the vendor/LICENSES/crds...
1 execute make verify
2 push the modified file

@Shelley-BaoYue
Copy link
Collaborator

Please using make verify to update the vendor/LICENSES/crds... 1 execute make verify 2 push the modified file

friendly remind : )

@kubeedge-bot kubeedge-bot added size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. and removed size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels May 29, 2024
@kubeedge-bot kubeedge-bot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels May 30, 2024
--input-dirs "k8s.io/apiextensions-apiserver/pkg/apis" \
--input-dirs "k8s.io/kubernetes/pkg/apis" \
--input-dirs "k8s.io/apimachinery/pkg/version" \
--input-dirs "k8s.io/apimachinery/pkg/api/resource" \
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't need to generate k8s API

"k8s.io/client-go/kubernetes/scheme"
"k8s.io/klog/v2"
"k8s.io/kube-openapi/pkg/common"
"k8s.io/kube-openapi/pkg/validation/spec"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sort the import

},
Resources: []lib.ResourceWithNamespaceScoped{
// Define resources and their namespace scoped and resource mapping correspondingly
{GVR: appsv1alpha1.SchemeGroupVersion.WithResource("edgeapplications"), NamespaceScoped: false},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

edgeapplications namespaceScope should not be false. And other apis should also be checked.

mkdir "$folder_name"
fi

go run ${KUBEEDGE_ROOT}/apidoc/tools/generate-swagger.go > ${KUBEEDGE_ROOT}/apidoc/generated/swagger/swagger.json
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why swagger.json in this PR is empty?

---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.6.2
creationTimestamp: null
controller-gen.kubebuilder.io/version: v0.14.0
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we must upgrade controller-gen tool in this PR? If not, remove it, If so, we need another separate PR to upgrade controller-gen.

@@ -136,4 +136,4 @@ function cleanup {

:copy:to:destination

cleanup
#cleanup
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this #

@@ -28,7 +28,6 @@ import (

type DevicesV1beta1Interface interface {
RESTClient() rest.Interface
DevicesGetter
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why remove DeviceGetter?

@@ -24,8 +24,6 @@ import (

// Interface provides access to all the informers in this group version.
type Interface interface {
// Devices returns a DeviceInformer.
Devices() DeviceInformer
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why remove Device Interface?

if ! test -f "${GOFILE}" ; then
echo "Error: Go file not found." && exit 1
fi
OUTPUT_FILE="${KUBEEDGE_ROOT}/vendor/k8s.io/kube-openapi/cmd/openapi-gen"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using go install k8s.io/kube-openapi/cmd/openapi-gen

@kubeedge-bot kubeedge-bot added size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. and removed size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Jun 4, 2024
Signed-off-by: guolinsheng <15079795005@163.com>
Signed-off-by: guolinsheng <15079795005@163.com>
@Catherine-monk Catherine-monk reopened this Jun 4, 2024
@kubeedge-bot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
To complete the pull request process, please assign shelley-baoyue after the PR has been reviewed.
You can assign the PR to them by writing /assign @shelley-baoyue in a comment when ready.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

1 similar comment
@kubeedge-bot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
To complete the pull request process, please assign shelley-baoyue after the PR has been reviewed.
You can assign the PR to them by writing /assign @shelley-baoyue in a comment when ready.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kubeedge-bot kubeedge-bot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Jun 4, 2024
Signed-off-by: guolinsheng <15079795005@163.com>
@kubeedge-bot kubeedge-bot removed the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Jun 4, 2024
@kubeedge-bot kubeedge-bot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Jun 4, 2024
Signed-off-by: guolinsheng <15079795005@163.com>
@Shelley-BaoYue Shelley-BaoYue added this to the v1.18 milestone Jun 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants