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
This commit is contained in:
Andrew Depke 2022-07-26 13:02:19 -06:00 committed by GitHub
parent c44d2f232b
commit d470527e43
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 1 deletions

1
.gitignore vendored
View File

@ -24,6 +24,7 @@ vendor/
# Docs generated from our openapi repo
api/cli.yml
api/cli.gen.yml
api/cli-stripped.gen.yml
api/cli-extras.gen.yml
# GPG private key generated by CI during release.

View File

@ -8,6 +8,7 @@ declare -r API_DIR="${ROOT_DIR}/api"
declare -r GENERATED_PATTERN='^// Code generated .* DO NOT EDIT\.$'
declare -r MERGE_DOCKER_IMG=quay.io/influxdb/swagger-cli
declare -r GENERATOR_DOCKER_IMG=openapitools/openapi-generator-cli:v5.1.0
declare -r TAG_STRIP_IMG=python:3.9-alpine3.15
# Clean up all the generated files in the target directory.
rm -f $(grep -Elr "${GENERATED_PATTERN}" "${API_DIR}")
@ -28,6 +29,11 @@ docker run --rm -it -u "$(id -u):$(id -g)" \
--outfile /api/cli-extras.gen.yml \
--type yaml
# Strip certain tags to prevent duplicated and conflicting codegen.
docker run --rm -it -u "$(id -u):$(id -g)" \
-v "${ROOT_DIR}":/api \
${TAG_STRIP_IMG} \
sh -c "python3 /api/etc/stripGroupTags.py /api/api/cli.gen.yml > /api/api/cli-stripped.gen.yml"
# Run the generator - This produces many more files than we want to track in git.
docker run --rm -it -u "$(id -u):$(id -g)" \
@ -35,7 +41,7 @@ docker run --rm -it -u "$(id -u):$(id -g)" \
${GENERATOR_DOCKER_IMG} \
generate \
-g go \
-i /api/cli.gen.yml \
-i /api/cli-stripped.gen.yml \
-o /api \
-t /api/templates \
--additional-properties packageName=api,enumClassPrefix=true,generateInterfaces=true

15
etc/stripGroupTags.py Normal file
View File

@ -0,0 +1,15 @@
import sys
import re
blacklist = [
"Data I/O endpoints",
"Security and access endpoints",
"System information endpoints"
]
if __name__ == "__main__":
with open(sys.argv[1]) as f:
data = f.read()
blItems = "|".join(blacklist)
data = re.sub(f"- +({blItems})", "", data)
print(data)