Skip to content
This repository has been archived by the owner on Jul 10, 2024. It is now read-only.

Commit

Permalink
SUBMARINE-687. Create bash script to auto-generate typescript-sdk and…
Browse files Browse the repository at this point in the history
… fix minor bugs

### What is this PR for?
It is a sub-task under [SUBMARINE-686. [Umbrella] Intergrate swagger to frontend](https://issues.apache.org/jira/projects/SUBMARINE/issues/SUBMARINE-686?filter=allopenissues)
1. To integrate swagger to the frontend, I wrote a script to auto-generate typescript-angular sdk.
2. Fix bug in `gen-sdk.sh`
3. Improve doc

### How should this be tested?
https://github.com/ByronHsu/submarine/actions/runs/386715559
### What type of PR is it?
[Improvement]

### What is the Jira issue?
https://issues.apache.org/jira/projects/SUBMARINE/issues/SUBMARINE-687

Author: ByronHsu <[email protected]>

Closes #464 from ByronHsu/SUBMARINE-687 and squashes the following commits:

dc8adbd [ByronHsu] Remove comments
f7a8468 [ByronHsu] create gen-ts-sdk and fix minor bugs
  • Loading branch information
ByronHsu authored and xunliu committed Dec 1, 2020
1 parent 78fe362 commit 18b58f9
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
1 change: 1 addition & 0 deletions dev-support/pysubmarine/gen-sdk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ submarine_dist_exists=$(find -L "${SUBMARINE_PROJECT_PATH}/submarine-dist/target
if [[ -z "${submarine_dist_exists}" ]]; then
cd "${SUBMARINE_PROJECT_PATH}"
mvn clean package -DskipTests
cd "$FWDIR" # go back to FWDIR after packaging
fi

echo "Generating openAPI 3.0 definition file ..."
Expand Down
55 changes: 55 additions & 0 deletions dev-support/pysubmarine/gen-ts-sdk.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/usr/bin/env bash
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

FWDIR="$(cd "$(dirname "$0")"; pwd)"
cd "$FWDIR"

SUBMARINE_PROJECT_PATH="$FWDIR/../.."
SWAGGER_JAR_URL="https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/4.3.1/openapi-generator-cli-4.3.1.jar"
SWAGGER_CODEGEN_JAR="openapi-generator-cli.jar"
SWAGGER_CODEGEN_CONF="swagger_config.json"
SWAGGER_CODEGEN_FILE="openapi.json"
SDK_OUTPUT_PATH="sdk/typescript-angular"

submarine_dist_exists=$(find -L "${SUBMARINE_PROJECT_PATH}/submarine-dist/target" -name "submarine-dist-*.tar.gz")
# Build source code if the package doesn't exist.
if [[ -z "${submarine_dist_exists}" ]]; then
cd "${SUBMARINE_PROJECT_PATH}"
mvn clean package -DskipTests
cd "$FWDIR" # go back to FWDIR after packaging
fi

echo "Generating openAPI 3.0 definition file ..."
# TODO(pingsutw): generate openapi.json without starting submarine server
bash ${SUBMARINE_PROJECT_PATH}/submarine-dist/target//submarine-dist-*/submarine-dist-*/bin/submarine-daemon.sh start getMysqlJar
sleep 5
rm openapi.json
wget http://localhost:8080/v1/openapi.json
bash ${SUBMARINE_PROJECT_PATH}/submarine-dist/target//submarine-dist-*/submarine-dist-*/bin/submarine-daemon.sh stop

openapi_generator_cli_exists=$(find -L "${FWDIR}" -name "openapi-generator-cli*")
if [[ -z "${openapi_generator_cli_exists}" ]]; then
echo "Downloading the swagger-codegen JAR package ..."
wget -O "${SWAGGER_CODEGEN_JAR}" "${SWAGGER_JAR_URL}"
fi

echo "Generating typescript-angular SDK for Submarine ..."
rm -r sdk/
java -jar ${SWAGGER_CODEGEN_JAR} generate \
-i "${SWAGGER_CODEGEN_FILE}" \
-g typescript-angular \
-o ${SDK_OUTPUT_PATH} \
-c ${SWAGGER_CODEGEN_CONF}
2 changes: 1 addition & 1 deletion docs/submarine-sdk/pysubmarine/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ pytest --cov=submarine -vs -m "e2e"
> Before run this command in local, you should make sure the submarine server is running.
### Generate python SDK from swagger
We use [swagger-codegen](https://swagger.io/docs/open-source-tools/swagger-codegen/)
We use [open-api generator](https://openapi-generator.tech/docs/installation/#jar)
to generate pysubmarine client API that used to communicate with submarine server.

If change below files, please run `./dev-support/pysubmarine/gen-sdk.sh`
Expand Down

0 comments on commit 18b58f9

Please sign in to comment.