Skip to content

Commit d470527

Browse files
authored
feat: added tag stripping step to openapi generation to fix codegen (#428)
* feat: added tag stripping step to openapi generation to fix codegen * fix: run tag removal in docker container * fix: ignore cli generated yaml
1 parent c44d2f2 commit d470527

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ vendor/
2424
# Docs generated from our openapi repo
2525
api/cli.yml
2626
api/cli.gen.yml
27+
api/cli-stripped.gen.yml
2728
api/cli-extras.gen.yml
2829

2930
# GPG private key generated by CI during release.

etc/generate-openapi.sh

+7-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ declare -r API_DIR="${ROOT_DIR}/api"
88
declare -r GENERATED_PATTERN='^// Code generated .* DO NOT EDIT\.$'
99
declare -r MERGE_DOCKER_IMG=quay.io/influxdb/swagger-cli
1010
declare -r GENERATOR_DOCKER_IMG=openapitools/openapi-generator-cli:v5.1.0
11+
declare -r TAG_STRIP_IMG=python:3.9-alpine3.15
1112

1213
# Clean up all the generated files in the target directory.
1314
rm -f $(grep -Elr "${GENERATED_PATTERN}" "${API_DIR}")
@@ -28,14 +29,19 @@ docker run --rm -it -u "$(id -u):$(id -g)" \
2829
--outfile /api/cli-extras.gen.yml \
2930
--type yaml
3031

32+
# Strip certain tags to prevent duplicated and conflicting codegen.
33+
docker run --rm -it -u "$(id -u):$(id -g)" \
34+
-v "${ROOT_DIR}":/api \
35+
${TAG_STRIP_IMG} \
36+
sh -c "python3 /api/etc/stripGroupTags.py /api/api/cli.gen.yml > /api/api/cli-stripped.gen.yml"
3137

3238
# Run the generator - This produces many more files than we want to track in git.
3339
docker run --rm -it -u "$(id -u):$(id -g)" \
3440
-v "${API_DIR}":/api \
3541
${GENERATOR_DOCKER_IMG} \
3642
generate \
3743
-g go \
38-
-i /api/cli.gen.yml \
44+
-i /api/cli-stripped.gen.yml \
3945
-o /api \
4046
-t /api/templates \
4147
--additional-properties packageName=api,enumClassPrefix=true,generateInterfaces=true

etc/stripGroupTags.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import sys
2+
import re
3+
4+
blacklist = [
5+
"Data I/O endpoints",
6+
"Security and access endpoints",
7+
"System information endpoints"
8+
]
9+
10+
if __name__ == "__main__":
11+
with open(sys.argv[1]) as f:
12+
data = f.read()
13+
blItems = "|".join(blacklist)
14+
data = re.sub(f"- +({blItems})", "", data)
15+
print(data)

0 commit comments

Comments
 (0)