1

I am generating Kubernetes CRD (Custom Resource Definition) using kubebuilder. Along with CRD, I also need to document the REST endpoints by creating OpenAPI v3 Spec (OAS) file. Is there a way to get this done using kubebuilder? Also does kubebuilder allow us to add sample Request/Response payload details in the .go file so that the generated OAS file is more user friendly?

One option I found is to use curl :/openapi/v3, but maintaining the spec file manually is not sustainable. I want to use kubebuilder generated .go spec file as one source of truth. Any suggestion?

Santi
  • 67
  • 7

1 Answers1

1

Seems to be there is no intended way to generate openapi files. As per this Git Link comment by DirectXMan12 :

KubeBuilder is not intended to generate go openapi files, since they're not useful for CRDs (they're basically only useful for aggregated API servers, and even then you can just bundle in the JSON/YAML form and parse on init).

You can also refer to this Git linkcomment and doc for further information .

Edit : Kubebuilder is generating only CRD and by using controller gen can generate an open API but kubebuilder is still not intended to generate open api. You can use other third party tools like mentioned in this document by Vyom Srivastava.

Hemanth Kumar
  • 2,728
  • 1
  • 4
  • 19
  • In the Git Link, controller-gen tool is referenced and I see that kubebuilder uses it to generate the crd. controller-gen seems to have something for OpenAPI but I don't know if it's relevant or not. This is what I see there: # Generate OpenAPI v3 schemas for API packages and merge them into existing CRD manifests controller-gen schemapatch:manifests=./manifests output:dir=./manifests paths=./pkg/apis/... – Santi May 04 '23 at 20:55
  • Any other recommendation to programmatically generate the OpenAPI spec file then? – Santi May 04 '23 at 20:58
  • @Santi : I have edited the answer and check the edit part. – Hemanth Kumar May 05 '23 at 07:33
  • I don't see a way to generate OAS using controller-gen. Which option to use in controller-gen? As CRD gets generated by kubebuilder, I want to add markers in the .go file to have one source of truth. I have access to Stoplight but looking for a way to generate the OAS file programmatically. @Hemanth – Santi May 05 '23 at 13:35
  • 1
    @Santi : Currently there is no process to generate this OAS file programmatically but you can use third party tools as mentioned in the solution. – Hemanth Kumar May 05 '23 at 13:38