Skip to content
This repository was archived by the owner on Jun 28, 2024. It is now read-only.

Commit 80d0a29

Browse files
committed
add Makefile tasks for linting and removing dupe request models
Signed-off-by: Marques Johansson <[email protected]>
1 parent 785e369 commit 80d0a29

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

Makefile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ GIT_REPO=gometal
1010
PACKAGE_MAJOR=v1
1111

1212
SWAGGER=docker run --rm -v $(CURDIR):/local ${IMAGE}
13+
GOLANGCI_LINT=golangci-lint
1314

1415
all: pull fetch patch gen
1516

@@ -38,3 +39,22 @@ gen:
3839
--git-repo-id ${GIT_REPO} \
3940
-o /local/${PACKAGE_MAJOR} \
4041
-i /local/${SPEC_PATCHED_FILE}
42+
43+
# https://github.com/OpenAPITools/openapi-generator/issues/741#issuecomment-569791780
44+
remove-dupe-requests: ## Removes duplicate Request structs from the generated code
45+
@for struct in $$(grep -h 'type .\{1,\} struct' $(PACKAGE_MAJOR)/*.go | grep Request | sort | uniq -c | grep -v '^ 1' | awk '{print $$3}'); do \
46+
for f in $$(/bin/ls $(PACKAGE_MAJOR)/*.go); do \
47+
if grep -qF "type $${struct} struct" "$${f}"; then \
48+
if eval "test -z \$${$${struct}}"; then \
49+
echo "skipping first appearance of $${struct} in file $${f}"; \
50+
eval "export $${struct}=1"; \
51+
else \
52+
echo "removing dupe $${struct} from file $${f}"; \
53+
tr '\n' '\r' <"$${f}" | sed 's~// '"$${struct}"'.\{1,\}type '"$${struct}"' struct {[^}]\{1,\}}~~' | tr '\r' '\n' >"$${f}.tmp"; \
54+
mv -f "$${f}.tmp" "$${f}"; \
55+
fi; \
56+
fi \
57+
done \
58+
done
59+
lint:
60+
@$(GOLANGCI_LINT) run -v --no-config --fast=false --fix --disable-all --enable goimports $(PACKAGE_MAJOR)

0 commit comments

Comments
 (0)