-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjustfile
More file actions
110 lines (96 loc) · 3.77 KB
/
Copy pathjustfile
File metadata and controls
110 lines (96 loc) · 3.77 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
set shell := ["bash", "-uc"]
remote_url := "https://raw.githubusercontent.com/shapediver/OpenApiSpecifications"
remote_tag_prefix := "gb_v2"
remote_file_name := "geometry_backend_v2.yaml"
spec_file := "oas_spec.yaml"
target_dir := "./out"
sdk_client_dir := "./packages/sdk.geometry-api-sdk-v2/src/client/"
# Path of the local OAS repository.
oas_repo := "../OpenApiSpecifications/"
# Resolve the installed OpenAPI generator command at runtime.
_openapi-generator-command:
#!/usr/bin/env bash
if command -v openapi-generator-cli >/dev/null 2>&1; then
echo openapi-generator-cli
elif command -v openapi-generator >/dev/null 2>&1; then
echo openapi-generator
else
echo "Neither openapi-generator-cli (npm) nor openapi-generator (brew) is installed." >&2
exit 1
fi
# Generate the TypeScript client from the OpenAPI specification.
generate version:
# Ensure that the generator is installed.
just --quiet _openapi-generator-command >/dev/null
# Stop when repo is dirty
test -z "$(git diff --shortstat)"
# Either link local file or fetch the requested version of the specification.
if [ "{{version}}" == "local" ]; then \
\cp "{{oas_repo}}/geometry_backend_v2.yaml" "{{spec_file}}" ; \
else \
curl -f \
"{{remote_url}}/{{remote_tag_prefix}}%40{{version}}/{{remote_file_name}}" \
-o "{{spec_file}}" ; \
fi
# Generate the TypeScript client.
mkdir -p "{{target_dir}}"
"$(just --quiet _openapi-generator-command)" generate \
--generate-alias-as-model \
--additional-properties=\
disallowAdditionalPropertiesIfNotPresent=false,\
enumPropertyNaming=UPPERCASE,\
paramNaming=camelCase,\
supportsES6=false \
-i "{{spec_file}}" \
-g typescript-axios \
-o "{{target_dir}}" || { \
rm -rf "{{target_dir}}"; \
exit 1; \
}
# Replace old client with new one.
rm -rf "{{sdk_client_dir}}" || :
mkdir -p "{{sdk_client_dir}}"
mv "{{target_dir}}/api.ts" "{{sdk_client_dir}}"
mv "{{target_dir}}/base.ts" "{{sdk_client_dir}}"
mv "{{target_dir}}/common.ts" "{{sdk_client_dir}}"
mv "{{target_dir}}/configuration.ts" "{{sdk_client_dir}}"
mv "{{target_dir}}/index.ts" "{{sdk_client_dir}}"
# Apply manual modifications to the generated DTO files.
just _post-generation
# Clean up.
rm -rf "{{target_dir}}"
# Commit changes.
if [ "{{version}}" != "local" ]; then \
git add -A . ; \
git commit -m "Generate spec version {{version}}" ; \
fi
# Tests the TypeScript client generation with the current version of the checked out OAS repo.
test-generator:
"$(just --quiet _openapi-generator-command)" generate \
--generate-alias-as-model \
--additional-properties=\
disallowAdditionalPropertiesIfNotPresent=false,\
enumPropertyNaming=UPPERCASE,\
paramNaming=camelCase,\
supportsES6=false \
--dry-run \
-i "{{oas_repo}}/geometry_backend_v2.yaml" \
-g typescript-axios
# Steps to be executed after the generation of the TypeScript client.
_post-generation:
#!/usr/bin/env bash
# Replace client BaseAPI import in api.ts with custom BaseAPI implementation.
pattern="^import \{(.*)BaseAPI,?\s?(.*)\} from '.\/base';$"
replacement="import \{\1\2\} from '.\/base';"
added_line="import \{ BaseAPI \} from '..\/base';"
case $(uname -s) in
Linux)
sed -ri "s/${pattern}/${replacement}\n${added_line}/g" \
"packages/sdk.geometry-api-sdk-v2/src/client/api.ts"
;;
Darwin)
sed -ri '' "s/${pattern}/${replacement}\n${added_line}/g" \
"packages/sdk.geometry-api-sdk-v2/src/client/api.ts"
;;
*) exit 1 ;;
esac