Generates a Swagger (openapiv2) document for Custom Resource Definitions (CRDs) installed and accessed through kube-apiserver. The generated swagger is the same document that you would get from the openapiv2 endpoint on a cluster, except the returned swagger document only includes paths and definitions used by the provided CRDs.
The application performs the following steps to accomplish this
- Gets the requested CRD files either from a local or remote file location.
- Starts a new K3s docker container.
- Creates the requested CRDs in the new cluster
- Retrieves a swagger 2.0 doc from the cluster.
- Removes all paths and references not related to the requested CRDs
- Outputs the new filtered swagger.json
go install github.com/kevinjoiner/crd-swagger
- golang
- docker
Generates a Swagger (openapiv2) document for Custom Resource Definitions (CRDs) installed and accessed through kube-apiserver.
Usage:
crd-swagger [flags]
Flags:
--cluster-port string port to bind kubeapi-server to on the host machine (default "6443")
-f, --files string location to find input CRD file/files, either a file path or a remote URL
-h, --help help for crd-swagger
-o, --output-file string location to output the generate swagger doc (if unset stdout is used)
-p, --pretty-print print the output json with formatted with newlines and indentations
-r, --recurse if files is a directory recursively search for all CRDs
--silent do not print any log messages
Generate swagger.json from a local Yaml file with readable new lines and indents
crd-swagger -o swagger.json -p -f ./crds.yaml
Generate rancher-swagger.json from remote gist
crd-swagger -o rancher-swagger.json -f https://gist.githubusercontent.com/KevinJoiner/088b29a495c3043fd59d8673ef6c7c05/raw