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:
1
.gitignore
vendored
1
.gitignore
vendored
@ -24,6 +24,7 @@ vendor/
|
|||||||
# Docs generated from our openapi repo
|
# Docs generated from our openapi repo
|
||||||
api/cli.yml
|
api/cli.yml
|
||||||
api/cli.gen.yml
|
api/cli.gen.yml
|
||||||
|
api/cli-stripped.gen.yml
|
||||||
api/cli-extras.gen.yml
|
api/cli-extras.gen.yml
|
||||||
|
|
||||||
# GPG private key generated by CI during release.
|
# GPG private key generated by CI during release.
|
||||||
|
@ -8,6 +8,7 @@ declare -r API_DIR="${ROOT_DIR}/api"
|
|||||||
declare -r GENERATED_PATTERN='^// Code generated .* DO NOT EDIT\.$'
|
declare -r GENERATED_PATTERN='^// Code generated .* DO NOT EDIT\.$'
|
||||||
declare -r MERGE_DOCKER_IMG=quay.io/influxdb/swagger-cli
|
declare -r MERGE_DOCKER_IMG=quay.io/influxdb/swagger-cli
|
||||||
declare -r GENERATOR_DOCKER_IMG=openapitools/openapi-generator-cli:v5.1.0
|
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.
|
# Clean up all the generated files in the target directory.
|
||||||
rm -f $(grep -Elr "${GENERATED_PATTERN}" "${API_DIR}")
|
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 \
|
--outfile /api/cli-extras.gen.yml \
|
||||||
--type yaml
|
--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.
|
# Run the generator - This produces many more files than we want to track in git.
|
||||||
docker run --rm -it -u "$(id -u):$(id -g)" \
|
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} \
|
${GENERATOR_DOCKER_IMG} \
|
||||||
generate \
|
generate \
|
||||||
-g go \
|
-g go \
|
||||||
-i /api/cli.gen.yml \
|
-i /api/cli-stripped.gen.yml \
|
||||||
-o /api \
|
-o /api \
|
||||||
-t /api/templates \
|
-t /api/templates \
|
||||||
--additional-properties packageName=api,enumClassPrefix=true,generateInterfaces=true
|
--additional-properties packageName=api,enumClassPrefix=true,generateInterfaces=true
|
||||||
|
15
etc/stripGroupTags.py
Normal file
15
etc/stripGroupTags.py
Normal 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)
|
Reference in New Issue
Block a user