Skip to content

Instantly share code, notes, and snippets.

@misebox
Created April 11, 2024 11:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save misebox/50a7cf988cab3bc329954c64a8b8dc62 to your computer and use it in GitHub Desktop.
Save misebox/50a7cf988cab3bc329954c64a8b8dc62 to your computer and use it in GitHub Desktop.
openapi.jsonからapiclientを生成する
#!/bin/bash -xe
# リポジトリルートへ移動
cd $(dirname $0)/..
# up API server
docker compose up -d --build --wait --quiet-pull api
# openapi.jsonの保存先
mkdir -p common/openapi
# compose.yamlのAPIサーバーのポートを変更した場合は、ここも変更する
curl -o common/openapi/openapi.json http://localhost:8000/_/openapi.json
# api clientコードの一時出力先
mkdir -p ./tmp/generated
rm -rf ./tmp/generated
# api client出力
docker run --rm \
-v "$(pwd)/common/openapi:/local" \
-v "$(pwd)/tmp/generated:/output" \
openapitools/openapi-generator-cli:v7.3.0 \
generate \
-i /local/openapi.json \
-g typescript-axios \
-o /output
# API Client コードを設置する場所
mkdir -p ./web/src
rm -rf ./web/src/generated
mv ./tmp/generated ./web/src/generated
rm ./web/src/generated/git_push.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment