-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopenapi.mk
More file actions
83 lines (78 loc) · 2.95 KB
/
Copy pathopenapi.mk
File metadata and controls
83 lines (78 loc) · 2.95 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
OPENAPI_CONVERTER_VERSION = v1.0.5
##@ Openapi
openapi/update/spec: check/installed/curl install/yq ## Download spec and convert to json
##~ SPEC_URL=URL - URL to download spec
##~ OUT_PATH=PATH - output file
@if [ -z "$$SPEC_URL" ]; then \
echo -e "${RED_COLOR}Spec url not passed with env SPEC_URL${NO_COLOR}"; \
exit 1; \
fi; \
if [ -z "$$OUT_PATH" ]; then \
echo -e "${RED_COLOR}Out spec file not passed with env OUT_PATH${NO_COLOR}"; \
exit 1; \
fi; \
dir_path="$$(dirname "$$OUT_PATH")"; \
if ! dir_path="$$(realpath "$$dir_path")"; then \
echo -e "${RED_COLOR}Cannot get real path for $$OUT_PATH${NO_COLOR}"; \
exit 1; \
fi; \
if [ ! -d "$$dir_path" ]; then \
echo -e "${RED_COLOR}$$dir_path out put dir is not exists${NO_COLOR}"; \
exit 1; \
fi; \
set -Eeuo pipefail; \
yaml_tmp="$$(mktemp)"; \
curl -sSfLo "$$yaml_tmp" "$$SPEC_URL"; \
cat "$$yaml_tmp" | "$(YQ_BIN_FULL)" -o=json -r . > "$(OUT_PATH)"
openapi/convert/to/v3: check/installed/docker check/installed/curl ## Convert opeanapi spec v2 to v3
##~ INPUT_SPEC=PATH - Path to v2 spec
##~ OUT_SPEC_PATH=PATH - Output v3 spec file
@if [ -z "$$INPUT_SPEC" ]; then \
echo -e "${RED_COLOR}Input spec path not passed with env INPUT_SPEC${NO_COLOR}"; \
exit 1; \
fi; \
if [ ! -f "$$INPUT_SPEC" ]; then \
echo -e "${RED_COLOR}Input spec $$INPUT_SPEC is not file${NO_COLOR}"; \
exit 1; \
fi; \
if [ -z "$$OUT_SPEC_PATH" ]; then \
echo -e "${RED_COLOR}Out spec path not passed with env OUT_SPEC_PATH${NO_COLOR}"; \
exit 1; \
fi; \
dir_path="$$(dirname "$$OUT_SPEC_PATH")"; \
if ! dir_path="$$(realpath "$$dir_path")"; then \
echo -e "${RED_COLOR}Cannot get real path for $$OUT_SPEC_PATH${NO_COLOR}"; \
exit 1; \
fi; \
if [ ! -d "$$dir_path" ]; then \
echo -e "${RED_COLOR}$$dir_path out put dir is not exists${NO_COLOR}"; \
exit 1; \
fi; \
if ! cid="$$(docker run --rm -d -p 26080:8080 --name swagger-converter swaggerapi/swagger-converter:$(OPENAPI_CONVERTER_VERSION))"; then \
echo -e "${RED}Converter container should not start${NO_COLOR}"; \
exit 1; \
fi; \
echo "Converter container $$cid available on http://127.0.0.1:26080 Sleep 10s for init..."; \
sleep 10; \
is_error=""; \
if ! curl -X POST \
--fail \
--data "@$(INPUT_SPEC)" \
-H "Content-Type: application/yaml" \
-H 'Accept: application/json' \
http://127.0.0.1:26080/api/convert > $(OUT_SPEC_PATH) ; \
then \
is_error="true"; \
echo -e "${RED}Convert failed${NO_COLOR}"; \
fi; \
echo "Stop converter container $$cid ..."; \
if ! docker stop "$$cid"; then \
is_error="true"; \
echo -e "${RED}Container $$cid was not stopped!${NO_COLOR}"; \
fi; \
if [ "$$is_error" = "true" ]; then \
exit 1; \
fi
_OPENAPI_ROOT_DIR:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
openapi/check/gitignore: export GITIGNORES_WITH_REQUIRED_RULES = $(_OPENAPI_ROOT_DIR)/makefile-common/.gitignore
openapi/check/gitignore: check/common/gitignore ## Check that .gitignore up to date with makefile-inc/common