This repository has been archived by the owner on May 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 39
Generate OpenAPI Specs #243
Open
zoidyzoidzoid
wants to merge
8
commits into
bookingcom:master
Choose a base branch
from
zoidyzoidzoid:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>
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:
Then generate a Typescript client using the following
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>
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>
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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: