diff --git a/.gitignore b/.gitignore index 2374b94..7b97163 100644 --- a/.gitignore +++ b/.gitignore @@ -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. diff --git a/etc/generate-openapi.sh b/etc/generate-openapi.sh index 7dfb140..f794583 100755 --- a/etc/generate-openapi.sh +++ b/etc/generate-openapi.sh @@ -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 diff --git a/etc/stripGroupTags.py b/etc/stripGroupTags.py new file mode 100644 index 0000000..ebba202 --- /dev/null +++ b/etc/stripGroupTags.py @@ -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) \ No newline at end of file