This repository has been archived by the owner on Dec 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Makefile
83 lines (62 loc) · 2.21 KB
/
Makefile
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
.PHONY: all clean patch pull generate codegen move-workflow build_client
CURRENT_UID := $(shell id -u)
CURRENT_GID := $(shell id -g)
##
# Preliminary definitions
##
# Openapi equinix metal spec
OPENAPI_URL=https://api.equinix.com/metal/v1/api-docs
# git repo : equinix metal-java sdk
GIT_ORG=equinix-labs
GIT_REPO=metal-java
PACKAGE_VERSION=$(shell cat version)
# Equinix Metal OAS 3.0.0
OPENAPI_CONFIG:=spec/oas3.config.json
OPENAPI_GENERATED_CLIENT=equinix-openapi-metal/
CRI=docker # nerdctl
SPEC_BASE_URL:=https://api.equinix.com/metal/v1/api-docs
SPEC_ROOT_FILE:=openapi3.yaml
PATCHED_SPEC_ENTRY_POINT=spec/oas3.patched/openapi/public/${SPEC_ROOT_FILE}
PATCHED_SPEC_OUTPUT_DIR=spec/oas3.stitched/
SPEC_FETCHER=${CRI} run --rm -u ${CURRENT_UID}:${CURRENT_GID} -v $(CURDIR):/workdir --entrypoint sh mikefarah/yq:4.35.1 script/download_spec.sh
SPEC_DIR_FETCHED_FILE=spec/oas3.fetched/
SPEC_DIR_PATCHED_FILE=spec/oas3.patched/
# Patches
SPEC_FETCHED_PATCHES=patches/spec.fetched.json
##
# openapi-generator-cli - docker
##
OPENAPI_CODEGEN_IMAGE=openapitools/openapi-generator-cli:v7.0.0
DOCKER_OPENAPI=${CRI} run --rm -u ${CURRENT_UID}:${CURRENT_GID} -v $(CURDIR):/local ${OPENAPI_CODEGEN_IMAGE}
all: pull fetch patch generate
generate: clean codegen move-workflow build_client
pull:
${CRI} pull ${OPENAPI_CODEGEN_IMAGE}
codegen:
${DOCKER_OPENAPI} generate \
--http-user-agent "${GIT_REPO}/${PACKAGE_VERSION}" \
-p artifactVersion=${PACKAGE_VERSION} \
-i /local/${PATCHED_SPEC_ENTRY_POINT} \
-g java \
-c /local/${OPENAPI_CONFIG} \
-o /local/${OPENAPI_GENERATED_CLIENT} \
--git-repo-id ${GIT_REPO} \
--git-user-id ${GIT_ORG}
##
# Utility functions
##
fetch:
${SPEC_FETCHER} ${SPEC_BASE_URL} ${SPEC_DIR_FETCHED_FILE}/openapi/public ${SPEC_ROOT_FILE}
clean:
rm -rf ${OPENAPI_GENERATED_CLIENT}
# executing patch apply shell script
patch:
rm -rf ${SPEC_DIR_PATCHED_FILE}
cp -r ${SPEC_DIR_FETCHED_FILE} ${SPEC_DIR_PATCHED_FILE}
for diff in $(shell find ${SPEC_FETCHED_PATCHES} -name \*.patch | sort -n); do \
patch --no-backup-if-mismatch -N -t -p1 -i $$diff; \
done
move-workflow:
cp -r internal/workflow equinix-openapi-metal/src/main/java/com/equinix/
build_client:
cd ${OPENAPI_GENERATED_CLIENT}; mvn clean package