-
Notifications
You must be signed in to change notification settings - Fork 212
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
Seeking advice for generating openapi spec for CRD #13
Comments
There are two parts in OpenAPI generation and handling: 1- Generating a model from a go type. This should be possible with this library. Look at my answer to this stackoverflow thread. 2- Creating the OpenAPI spec from the model generated in 1. You need to also add routing and call the builder package. For CRD those operation are standard k8s CRUD operations. I would like to see we add support for CRD OpenAPI spec to kubernetes then you can get the spec from kubernetes. But you can also provide the CRUD operation by hand or copy one of the other API object spec and plug in your model in it. 3- When you got your OpenAPI spec then you should be able to generate a client using https://github.com/kubernetes-client/gen. After generation you may need to copy the useful utilities from the language repo. For example for python this is the repo. |
Thanks a lot @mbohlool ! I will give it a try and see how it goes. |
@mbohlool , I was able to generate openapi spec from appscode/voyager project. generated spec: https://github.com/appscode/voyager/blob/master/apis/voyager/v1beta1/openapi_generated.go Generator command: https://github.com/appscode/voyager/blob/0370feff31c1012c3e94a52bb4218136ca6e4a42/hack/codegen.sh#L51 I am not sure what is the next step? How do I serve this spec so that swagger generators can access them? |
This generates only models. You need to provide a route list to Basically you only did step 1 in my previous comment and you need to proceed to step 2 and 3. |
In case others can benefit from this, I wasn't able to get this to work using only kube-openapi. Instead I constructed the go-openapi which generates this: |
@jessesuen your swagger.json is missing the api call information. To generate client that information will be needed. |
I have figured out how to get this to work. Here is my working demo: https://github.com/tamalsaha/kube-openapi-generator |
Some of the modern Kubernetes clients use clients generated from a swagger.json kubernetes-client/javascript uses kubernetes-client/gen which uses OpenApiTools/openapi-generator and kubernetes/kubernetes/api/openapi-spec/swagger.json There are open/closed/rotten/ignored issues all over the place about making these easier to use with CRDs. Wrongly closed issue on kubernetes-client/javascript: kubernetes-client/javascript#341 Open issue on kubernetes-client/gen: kubernetes-client/gen#121 It seems like kubernetes/kube-openapi is one of the repos working on solving the main part of this problem, generating the Go code to make it easy to generate a swagger.json I found the following Argo code via the following issue: kubernetes/kube-openapi#13 https://github.com/argoproj/argo/blob/master/hack/gen-openapi-spec/main.go https://github.com/argoproj/argo/blob/master/pkg/apis/workflow/v1alpha1/openapi_generated.go#L14:6 https://github.com/kubernetes/kube-openapi/blob/master/cmd/openapi-gen/openapi-gen.go So I'm working on adding similar stuff to Shipper. gen-openapi-spec uses the generated openapi_generated.go module that is generated via the openapi-gen command. The following commit adds the code to generate openapi_generated.go Signed-off-by: William Stewart <[email protected]>
…tes#13 Fixes kubernetes#13 Added golangci and go report card badges Signed-off-by: Frederic BIDON <[email protected]>
Completed test for ServeError with nil Error, as discussed in kubernetes#13
@mbohlool , is there an example on how to use this generator to generate/serve open api spec for CRDs from GO types?
From kubernetes-client/java#96, I am looking for ways to generate non-Go client for CRDs.
Any help is much appreciated!
The text was updated successfully, but these errors were encountered: