Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
235 lines (204 loc) · 11 KB
/
Copy pathMakefile
File metadata and controls
235 lines (204 loc) · 11 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
SHELL = /bin/bash
LD_RELEASE_VERSION ?= 0.0.1-SNAPSHOT
# IMPORTANT: Whenever updating this generator version, check if the ApiClient mustache files need corresponding updates.
# We have copied of these into the swagger-codegen-templates directory. Look for code blocks notated by CUSTOM-START and CUSTOM-END.
# - Go: https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/resources/go/client.mustache
# - Java: https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/ApiClient.mustache
# - Python: https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/resources/python/api_client.mustache
# - Ruby: https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/resources/ruby-client/api_client.mustache
# - Typescript: https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/resources/typescript-axios/apiInner.mustache
GENERATOR_VERSION=7.18.0
GENERATOR_JAR=openapi-generator-cli-${GENERATOR_VERSION}.jar
GENERATOR_DOWNLOAD_URL=https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/${GENERATOR_VERSION}/${GENERATOR_JAR}
OPENAPI_JSON_URL=https://app.launchdarkly.com/api/v2/openapi.json
LATEST_API_VERSION=20240415 # the API version (for the LD-API-Version header value) corresponding to what is specified in this OpenAPI spec
API_TARGETS ?= \
go \
java \
python \
ruby \
typescript-axios
RELEASE_BRANCH ?= main # when we bump a major version, we may need to change this
PREV_RELEASE_BRANCH ?= $(RELEASE_BRANCH) # override this to create a revision of an older branch
RELEASE_TARGETS ?= $(API_TARGETS) # for now, we don't release the docs to repos
RELEASE_SUFFIX ?= # allows the private branch to push to repos with a "-private" suffix
PUBLISH_TARGETS ?= $(RELEASE_TARGETS)
REPO ?= ld-openapi$(RELEASE_SUFFIX)
REPO_USER_URL ?= https://github.com/launchdarkly
TAG ?= $(LD_RELEASE_VERSION)
DOC_TARGETS = \
html \
html2
API_CLIENT_PREFIX = api-client
TARGETS_PATH ?= ./targets
CLIENT_CLONES_PATH ?= ./client-clones
TEMPLATES_PATH ?= ./swagger-codegen-templates
SAMPLES_PATH ?= ./samples
# The following variables define any special command-line parameters that need to be passed
# to openapi-generator for each language/platform.
CODEGEN_PARAMS_go = \
-t $(TEMPLATES_PATH)/go \
--additional-properties=packageName=ldapi \
--additional-properties=disallowAdditionalPropertiesIfNotPresent=false \
--additional-properties=generateInterfaces=true \
--additional-properties=apiNameSuffix=Api \
--additional-properties=email=support@launchdarkly.com \
--additional-properties=developerName=LaunchDarkly \
--additional-properties=developerEmail=support@launchdarkly.com \
--additional-properties=developerOrganization=LaunchDarkly \
--additional-properties=developerOrganizationUrl=https://launchdarkly.com \
--additional-properties=packageVersion=$(firstword $(subst ., ,$(TAG))) \
--additional-properties=launchDarklyApiVersion=${LATEST_API_VERSION}
CODEGEN_PARAMS_java = \
-t $(TEMPLATES_PATH)/java \
--group-id com.launchdarkly \
--api-package com.launchdarkly.api.api \
--model-package com.launchdarkly.api.model \
--additional-properties=disallowAdditionalPropertiesIfNotPresent=false \
--additional-properties=artifactId=api-client \
--additional-properties=email=support@launchdarkly.com \
--additional-properties=developerName=LaunchDarkly \
--additional-properties=developerEmail=support@launchdarkly.com \
--additional-properties=developerOrganization=LaunchDarkly \
--additional-properties=developerOrganizationUrl=https://launchdarkly.com \
--additional-properties=artifactUrl=https://github.com/launchdarkly/api-client-java \
--additional-properties=artifactDescription="Build custom integrations with the LaunchDarkly REST API" \
--additional-properties=scmUrl="https://github.com/launchdarkly/api-client-java" \
--additional-properties=scmConnection='scm:git:git://github.com/launchdarkly/api-client-java.git' \
--additional-properties=scmDeveloperConnection='scm:git:ssh:git@github.com:launchdarkly/api-client-java.git' \
--additional-properties=gradleProperties=systemProp.org.gradle.internal.http.connectionTimeout=300000$$'\n'systemProp.org.gradle.internal.http.socketTimeout=300000$$'\n'org.gradle.jvmargs=-Xss2m \
--additional-properties=launchDarklyApiVersion=${LATEST_API_VERSION}
CODEGEN_PARAMS_python = \
-t $(TEMPLATES_PATH)/python \
--additional-properties=packageName=launchdarkly_api \
--additional-properties=packageVersion=$(TAG) \
--additional-properties=launchDarklyApiVersion=${LATEST_API_VERSION}
# TEMPORARY: axios is pinned to 1.18.1 rather than a floating ^1.13.1 range.
# axios 1.19.0 (2026-07-29) added `declare const axiosResponseDefault: unique symbol`
# to its index.d.ts and refers to it from the public return type of `request()`.
# The symbol is never exported, so tsc cannot name it when it infers the type of
# the generated common.ts `createRequestFunction`, and the client fails to build:
# common.ts(108,14): error TS2527: The inferred type of 'createRequestFunction'
# references an inaccessible 'unique symbol' type. A type annotation is necessary.
# Everything up to and including 1.18.1 builds. This is not fixed upstream:
# openapi-generator master still emits the unannotated function, and 1.19.0 is
# still axios latest.
#
# The real fix is a swagger-codegen-templates/typescript/common.mustache override
# annotating the returned closure — `): Promise<R> =>` plus
# `as Promise<R>` on the axios.request call — which compiles clean against 1.19.0
# and against older axios. Deferred: it adds a fifth template to keep in sync with
# generator upgrades. Revert this pin when that override lands, or when axios
# exports the symbol.
CODEGEN_PARAMS_typescript-axios = \
-t $(TEMPLATES_PATH)/typescript \
--additional-properties=npmName=launchdarkly-api-typescript \
--additional-properties=npmVersion=$(TAG) \
--additional-properties=supportsES6=true \
--additional-properties=axiosVersion=1.18.1 \
--additional-properties=launchDarklyApiVersion=${LATEST_API_VERSION}
CODEGEN_PARAMS_ruby = \
-t $(TEMPLATES_PATH)/ruby \
--additional-properties=moduleName=LaunchDarklyApi \
--additional-properties=gemName=launchdarkly_api \
--additional-properties=gemVersion=$(TAG) \
--additional-properties=launchDarklyApiVersion=${LATEST_API_VERSION}
SAMPLE_FILE_go = main.go
SAMPLE_FILE_python = main.py
SAMPLE_FILE_ruby = main.rb
SAMPLE_FILE_typescript-axios = index.ts
SAMPLE_FORMAT_go = go
SAMPLE_FORMAT_python = python
SAMPLE_FORMAT_ruby = ruby
SAMPLE_FORMAT_typescript-axios = ts
TARGET_OPENAPI_JSON = $(TARGETS_PATH)/openapi.json
CODEGEN = exec java -jar ${GENERATOR_JAR}
all: $(API_TARGETS) $(DOC_TARGETS)
load_prior_targets:
rm -rf $(TARGETS_PATH)
mkdir -p $(TARGETS_PATH)
set -e
cd $(TARGETS_PATH)
git init
$(foreach RELEASE_TARGET, $(RELEASE_TARGETS), \
git submodule add $(REPO_USER_URL)/api-client-$(RELEASE_TARGET)$(RELEASE_SUFFIX) ./api-client-$(RELEASE_TARGET) && git checkout $(PREV_RELEASE_BRANCH) ;)
$(GENERATOR_JAR):
curl -s -L --fail ${GENERATOR_DOWNLOAD_URL} > $@
$(TARGET_OPENAPI_JSON): $(GENERATOR_JAR) $(TARGETS_PATH)
curl -s -L --fail $(OPENAPI_JSON_URL) > $@
$(TARGETS_PATH):
mkdir -p $@
$(API_TARGETS): $(TARGET_OPENAPI_JSON)
$(eval BUILD_DIR := $(TARGETS_PATH)/$(API_CLIENT_PREFIX)-$@)
mkdir -p $(BUILD_DIR) && rm -rf $(BUILD_DIR)/*
$(CODEGEN) generate -i $(TARGET_OPENAPI_JSON) $(CODEGEN_PARAMS_$@) -g $@ --additional-properties=artifactVersion=$(LD_RELEASE_VERSION) --git-host=github.com --git-user-id=launchdarkly --git-repo-id=api-client-$@ -o $(BUILD_DIR)
cp ./LICENSE.txt $(BUILD_DIR)/LICENSE.txt
mkdir -p $(BUILD_DIR)/.github/workflows && cp ./dependency-scan-gha.yml $(BUILD_DIR)/.github/workflows/dependency-scan.yml
mv $(BUILD_DIR)/README.md $(BUILD_DIR)/README-ORIGINAL.md || touch $(BUILD_DIR)/README-ORIGINAL.md
if [ -f "$(SAMPLES_PATH)/$@/$(SAMPLE_FILE_$@)" ]; then \
cat ./README-PREFIX.md > $(BUILD_DIR)/README.md; \
echo -e "View our [sample code](#sample-code) for example usage.\n" >> $(BUILD_DIR)/README.md; \
cat $(BUILD_DIR)/README-ORIGINAL.md >> $(BUILD_DIR)/README.md; \
echo -e "## Sample Code\n" >> $(BUILD_DIR)/README.md; \
echo '```${SAMPLE_FORMAT_$@}' >> $(BUILD_DIR)/README.md; \
cat $(SAMPLES_PATH)/$@/$(SAMPLE_FILE_$@) >> $(BUILD_DIR)/README.md; \
echo '```' >> $(BUILD_DIR)/README.md; \
else \
cat ./README-PREFIX.md $(BUILD_DIR)/README-ORIGINAL.md > $(BUILD_DIR)/README.md; \
fi
rm $(BUILD_DIR)/README-ORIGINAL.md
# Generates all API targets using Docker
targets_docker:
docker run -ti -v `pwd`:/workspace -e LD_RELEASE_VERSION --workdir /workspace \
ldcircleci/openapi-release:1 make all
$(DOC_TARGETS):
$(eval BUILD_DIR := $(TARGETS_PATH)/$@)
mkdir -p $(BUILD_DIR) && rm -rf $(BUILD_DIR)/*
$(CODEGEN) generate -i $(TARGET_OPENAPI_JSON) $(CODEGEN_PARAMS_$@) -g $@ --artifact-version $(LD_RELEASE_VERSION) -o $(BUILD_DIR)
GIT_COMMAND=git
GIT_PUSH_COMMAND=git push
GIT_PUSH_DESC=Publishing updates
push_test: GIT_COMMAND=echo git
push_test: push
push_dry_run: GIT_PUSH_COMMAND=git push --dry-run
push_dry_run: GIT_PUSH_DESC=Simulating the updates we would do
# Without this prerequisite the target is only a set of variable assignments, so
# `make push_dry_run` prints "Nothing to be done" and exits 0 — a rehearsal that
# silently does nothing. push_test has always had it; this one was missing it.
push_dry_run: push
# for each client library, clone the repository and replace the contents with the newly generated client
push:
mkdir $(CLIENT_CLONES_PATH); \
cd $(CLIENT_CLONES_PATH); \
$(foreach RELEASE_TARGET, $(RELEASE_TARGETS), \
echo $(GIT_PUSH_DESC) to the $(RELEASE_TARGET) client repository...; \
$(GIT_COMMAND) clone https://github.com/launchdarkly/api-client-$(RELEASE_TARGET).git || exit 1; \
rm -r api-client-$(RELEASE_TARGET)/*; \
cp -v -r ../$(TARGETS_PATH)/api-client-$(RELEASE_TARGET) .; \
cd api-client-$(RELEASE_TARGET); \
$(GIT_COMMAND) add .; \
$(GIT_COMMAND) status; \
$(GIT_COMMAND) commit --allow-empty -m "Version $(LD_RELEASE_VERSION) automatically generated from $(REPO)."; \
if [ $(RELEASE_TARGET) == "go" ]; then \
$(GIT_COMMAND) tag v$(TAG); \
$(GIT_PUSH_COMMAND) origin v$(TAG); \
else \
$(GIT_COMMAND) tag $(TAG); \
$(GIT_PUSH_COMMAND) origin $(TAG); \
fi; \
$(GIT_PUSH_COMMAND) origin $(RELEASE_BRANCH); \
cd ..; \
) \
build_clients:
./scripts/run-scripts-for-targets.sh ./scripts/build $(VERSION) \
"Building client code" $(BUILD_TARGETS)
publish:
./scripts/run-scripts-for-targets.sh ./scripts/release $(LD_RELEASE_VERSION) \
"Publishing client artifacts" $(PUBLISH_TARGETS)
publish_dry_run:
./scripts/run-scripts-for-targets.sh ./scripts/release-dry-run $(LD_RELEASE_VERSION) \
"Dry run simulation of publishing client artifacts" $(PUBLISH_TARGETS)
clean:
rm -rf $(TARGETS_PATH)
rm -rf $(CLIENT_CLONES_PATH)
.PHONY: $(TARGETS) all build_clients clean load_prior_targets push push_dry_run push_test targets_docker