Skip to content

Commit

Permalink
fixed generate_api.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
Bobgy committed Feb 9, 2021
1 parent ec1d7b8 commit 50cb605
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 77 deletions.
7 changes: 7 additions & 0 deletions backend/api/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ go_proto_library(
],
)

go_library(
name = "go_default_library",
embed = [":go_client_go_proto"],
importpath = "github.com/kubeflow/pipelines/backend/api/go_client",
visibility = ["//visibility:public"],
)

protoc_gen_swagger(
name = "api_swagger",
proto = ":go_client_proto",
Expand Down
1 change: 0 additions & 1 deletion backend/api/auth.proto
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package api;

import "google/api/annotations.proto";
import "google/protobuf/empty.proto";
import "backend/api/error.proto";
import "protoc-gen-swagger/options/annotations.proto";

option (grpc.gateway.protoc_gen_swagger.options.openapiv2_swagger) = {
Expand Down
19 changes: 13 additions & 6 deletions backend/api/generate_api.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,11 @@ if [ -z "$VERSION" ]; then
echo "ERROR: $REPO_ROOT/VERSION is empty"
exit 1
fi
TMP_DIR="$(mktemp -d)"

BAZEL_BINDIR=$(bazel info bazel-bin)
GENERATED_GO_PROTO_FILES="${BAZEL_BINDIR}/backend/api/api_generated_go_sources/src/github.com/kubeflow/pipelines/backend/api/go_client/*.go"

# Reference: https://goswagger.io/install.html
SWAGGER_GO_VERSION=v0.18.0
SWAGGER_GO_IMAGE="quay.io/goswagger/swagger:${SWAGGER_GO_VERSION}"
docker pull "${SWAGGER_GO_IMAGE}"
SWAGGER_CMD="docker run --rm -it --user $(id -u):$(id -g) -e GOPATH=$HOME/go:/go -v $HOME:$HOME -w $(pwd) ${SWAGGER_GO_IMAGE}"

# TODO this script should be able to be run from anywhere, not just within .../backend/api/

# Delete currently generated code.
Expand All @@ -47,6 +42,8 @@ rm -r -f ${DIR}/go_client/*
# Build .pb.go and .gw.pb.go files from the proto sources.
bazel build //backend/api:api_generated_go_sources

mkdir -p ${DIR}/go_client

# Copy the generated files into the source tree and add license.
for f in $GENERATED_GO_PROTO_FILES; do
target=${DIR}/go_client/$(basename ${f})
Expand All @@ -67,6 +64,16 @@ jq -s '
.info.license = { "name": "Apache 2.0", "url": "https://raw.githubusercontent.com/kubeflow/pipelines/master/LICENSE" }
' ${DIR}/swagger/{run,job,pipeline,experiment,pipeline.upload,healthz}.swagger.json > "${DIR}/swagger/kfp_api_single_file.swagger.json"

# Reference: https://goswagger.io/install.html
SWAGGER_GO_VERSION=v0.18.0
pushd "${TMP_DIR}"
curl -LO "https://github.com/go-swagger/go-swagger/releases/download/${SWAGGER_GO_VERSION}/swagger_linux_amd64"
chmod +x swagger_linux_amd64
SWAGGER_CMD="${TMP_DIR}/swagger_linux_amd64"
popd

mkdir -p ${DIR}/go_http_client

# Generate Go HTTP client from the swagger files.
${SWAGGER_CMD} generate client \
-f ${DIR}/swagger/job.swagger.json \
Expand Down
72 changes: 36 additions & 36 deletions backend/api/go_client/auth.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 1 addition & 34 deletions backend/api/swagger/auth.swagger.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 50cb605

Please sign in to comment.