Skip to content
This repository has been archived by the owner on May 3, 2022. It is now read-only.

Generate OpenAPI Specs #243

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

Conversation

zoidyzoidzoid
Copy link

Some of the 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 on kube-openapi: 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 this PR adds similar stuff to Shipper.

gen-openapi-spec uses the generated openapi_generated.go module that is
generated via the openapi-gen command, to generate a swagger.json

The following commits:

  • add the code to generate openapi_generated.go
  • add the code to generate swagger.json from openapi_generated.go

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 <zoidbergwill@gmail.com>
Generated with:
go run ./hack/gen-openapi-spec/main.go v1alpha1 > api/openapi-spec/swagger.json

Signed-off-by: William Stewart <zoidbergwill@gmail.com>
@zoidyzoidzoid
Copy link
Author

So with the related swagger.json, in kubernetes-client/gen I can do the following:

Create a file called shipper_settings.sh in the openapi directory with the following contents:

export KUBERNETES_BRANCH="master"
export CLIENT_VERSION="1.0.0b1"
export PACKAGE_NAME="shipper-client"
export USERNAME="zoidbergwill"
export REPOSITORY="shipper"

Then generate a Typescript client using the following

./typescript.sh shipper-client shipper_settings.sh  

And I should be able to use it with kubernetes-client/javascript, by doing something like:

const k8s = require('@kubernetes/client-node');
const shipper = require('@booking/shipper-client');

const kc = new k8s.KubeConfig();
kc.loadFromDefault();

const k8sApi = kc.makeApiClient(shipper.V1alpha1Api);

Added these by hand, not 100% sure how to add them to generation.

Signed-off-by: William Stewart <zoidbergwill@gmail.com>
@zoidyzoidzoid
Copy link
Author

So in my last commit I manually added some other k8s.io types that we use. I don't know how to get them into our generated openAPI code. I'll investigate what argo is doing.

https:/github.com/bookingcom/shipper/blob/master/pkg/apis/shipper/v1alpha1/types.go?expand=1#L6-L7

Signed-off-by: William Stewart <zoidbergwill@gmail.com>
Maybe this shouldn't go in the final PR that is merged.

Also probably blocked by other 0.9 PR updating dependencies
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant