<p>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?</p>
<p>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?</p>

Santi
<p>Seems to be there is no intended way to generate openapi files. As per this <a href="https://github.com/kubernetes-sigs/kubebuilder/issues/1129#issuecomment-546508941" rel="nofollow noreferrer">Git Link comment</a> by  DirectXMan12 :</p>
<blockquote>
<p>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).</p>
</blockquote>
<p>You can also refer to this <a href="https://github.com/kubernetes-sigs/kubebuilder/issues/1231#issuecomment-571374228" rel="nofollow noreferrer">Git linkcomment</a> and <a href="https://book-v1.book.kubebuilder.io/beyond_basics/generating_documentation.html" rel="nofollow noreferrer">doc</a> for further information .</p>
<p>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 <a href="https://nordicapis.com/7-open-source-openapi-documentation-generators/" rel="nofollow noreferrer">document</a> by Vyom Srivastava.</p>
