-
Notifications
You must be signed in to change notification settings - Fork 122
Expand file tree
/
Copy pathgen-client
More file actions
executable file
·54 lines (44 loc) · 1.96 KB
/
Copy pathgen-client
File metadata and controls
executable file
·54 lines (44 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/bash
set -eou pipefail
OPENAPI_FILE_PATH=api/gen/openapi_schema.json
SWAGGER_FILE_PATH=api/gen/merged_swagger.json
GITMONO_FILE_PATH=api/gen/gitmono.json
GITMONO_OPENAPI_URL="${GITMONO_OPENAPI_URL:-http://localhost:8000/api/openapi.json}"
# Fetch mono OpenAPI, pretty-print, and replace the checked-in dump
echo "Fetching OpenAPI from ${GITMONO_OPENAPI_URL} ..."
tmp_openapi="$(mktemp)"
trap 'rm -f "${tmp_openapi}"' EXIT
curl -fsS "${GITMONO_OPENAPI_URL}" -o "${tmp_openapi}"
node -e "
const fs = require('fs');
const src = process.argv[1];
const dest = process.argv[2];
const json = JSON.parse(fs.readFileSync(src, 'utf8'));
fs.writeFileSync(dest, JSON.stringify(json, null, 2) + '\n');
console.log('Updated ' + dest);
" "${tmp_openapi}" "${GITMONO_FILE_PATH}"
# swagger-typescript-api does not work with ES Modules which is required for our prettier v3 plugins
# and swagger-typescript-api automatically detects and runs prettier on generated files
mv .prettierrc.json .prettierrc_temp.json
# (cd api && bundle exec rake apigen:merge_swagger)
OUT=./gen node api/merge-swagger.js
# generate client types (v13+ requires the `generate` subcommand)
# NOTE: do not use --module-name-first-tag — STA v13 groups by OpenAPI tags and drops
# the `v1` module that legacyApiClient.v1.* call sites depend on. Path index 1 yields
# `v1` for /api/v1/*, and organizations/users/… for /v1/organizations|users/…
pnpm swagger-typescript-api generate \
--extract-request-params \
--extract-request-body \
--extract-response-body \
--extract-response-error \
--module-name-index 1 \
--templates script/swagger-templates \
--path $SWAGGER_FILE_PATH \
--output ./packages/types/ \
--name generated.ts
# remove swagger docs so we only check in the generated client types
# rm $SWAGGER_FILE_PATH
# Put .prettierrc.json back
mv .prettierrc_temp.json .prettierrc.json
# format generated files
pnpm prettier --config .prettierrc.json --write ./packages/types/generated.ts ./$OPENAPI_FILE_PATH