-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile.metalv1
75 lines (60 loc) · 2.47 KB
/
Makefile.metalv1
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
.PHONY: all pull fetch patch generate clean codegen mod docs move-other patch-post fmt test stage
include Makefile
PACKAGE_NAME=metalv1
SPEC_BASE_URL:=https://api.equinix.com/metal/v1/api-docs
SPEC_ROOT_FILE:=openapi3.yaml
CODE_DIR=equinix/services/${PACKAGE_NAME}
TEMPLATE_DIR=${TEMPLATE_BASE_DIR}/${PACKAGE_NAME}
SPEC_FETCHED_DIR=${SPEC_BASE_DIR}/${PACKAGE_NAME}/oas3.fetched
SPEC_PATCH_DIR=${SPEC_BASE_DIR}/${PACKAGE_NAME}/patches
SPEC_PATCHED_DIR=${SPEC_BASE_DIR}/${PACKAGE_NAME}/oas3.patched
SPEC_STITCHED_DIR=${SPEC_BASE_DIR}/${PACKAGE_NAME}/oas3.stitched
all: pull fetch patch generate stage
generate: clean codegen patch-post fmt test
pull:
${CRI} pull ${OPENAPI_IMAGE}
fetch:
${SPEC_FETCHER} ${SPEC_BASE_URL} ${SPEC_FETCHED_DIR} ${SPEC_ROOT_FILE}
patch:
rm -rf ${SPEC_PATCHED_DIR}
cp -r ${SPEC_FETCHED_DIR} ${SPEC_PATCHED_DIR}
# TODO: fetch the merged (single-file) spec
# instead of merging it here
${OPENAPI_GENERATOR} generate \
-i /local/${SPEC_PATCHED_DIR}/${SPEC_ROOT_FILE} \
-g openapi-yaml \
-p skipOperationExample=true -p outputFile=${SPEC_ROOT_FILE} \
-o /local/${SPEC_PATCHED_DIR}
rm -rf ${SPEC_PATCHED_DIR}/.openapi-generator* \
${SPEC_PATCHED_DIR}/README.md \
${SPEC_PATCHED_DIR}/components \
${SPEC_PATCHED_DIR}/paths
for diff in $(shell set -x; find ${SPEC_PATCH_DIR} -name '*.patch' | sort -n); do \
patch --no-backup-if-mismatch -N -t -p1 -i $$diff; \
done
script/patch_metal_spec.py ${SPEC_PATCHED_DIR}/${SPEC_ROOT_FILE} ${SPEC_PATCHED_DIR}/${SPEC_ROOT_FILE}
patch-post:
# patch is idempotent, always starting with the generated files
for diff in $(shell find patches/post -name \*.patch | sort -n); do \
patch --no-backup-if-mismatch -N -t -p1 -i $$diff; \
done
clean:
rm -rf $(CODE_DIR)
codegen:
${OPENAPI_GENERATOR} generate -g python \
--package-name equinix.services.${PACKAGE_NAME} \
--http-user-agent "${USER_AGENT}" \
-p packageVersion=${PACKAGE_VERSION} \
--git-user-id ${GIT_ORG} \
--git-repo-id ${GIT_REPO} \
`# TODO: re-enable the config file option so that generated code follows OpenAPI standards; this is only disabled to provide an upgrade path for metal-python` \
`# -c /local/config/openapi-generator.json` \
`# TODO: remove this when the config file is re-enabled` \
-p generateSourceCodeOnly=true \
-t /local/${TEMPLATE_DIR} \
-o /local/ \
-i /local/${SPEC_PATCHED_DIR}/${SPEC_ROOT_FILE}
validate:
${OPENAPI_GENERATOR} validate \
--recommend \
-i /local/${SPEC_PATCHED_DIR}/${SPEC_ROOT_FILE}