Skip to content

Commit

Permalink
mk(generate): add OpenAPI generation
Browse files Browse the repository at this point in the history
Signed-off-by: Mike Beaumont <[email protected]>
  • Loading branch information
michaelbeaumont committed Sep 20, 2023
1 parent 04c3981 commit e9e6d76
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion mk/dependencies/deps.lock
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3bcba4e63538e069f7d03297dff78125582730dc
69f69317d27266bf487ee42fdf83f52880d614f2
4 changes: 3 additions & 1 deletion mk/dependencies/go-deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ for i in \
sigs.k8s.io/controller-tools/cmd/controller-gen@$(go list -f '{{.Version}}' -m sigs.k8s.io/controller-tools) \
github.com/mikefarah/yq/[email protected] \
github.com/norwoodj/helm-docs/cmd/[email protected] \
golang.stackrox.io/kube-linter/cmd/[email protected]; do
golang.stackrox.io/kube-linter/cmd/[email protected] \
github.com/deepmap/oapi-codegen/cmd/[email protected] \
; do
echo "install go dep: ${i}"
GOBIN=${OUTPUT_BIN_DIR} go install "${i}" &
done
Expand Down
9 changes: 7 additions & 2 deletions mk/generate.mk
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ clean/protos: ## Dev: Remove auto-generated Protobuf files
find $(PROTO_DIRS) -name '*.pb.validate.go' -delete

.PHONY: generate
generate: generate/protos $(if $(findstring ./api,$(PROTO_DIRS)),resources/type generate/builtin-crds) generate/policies $(EXTRA_GENERATE_DEPS_TARGETS) ## Dev: Run all code generation
generate: generate/protos $(if $(findstring ./api,$(PROTO_DIRS)),resources/type generate/builtin-crds) generate/policies generate/oas $(EXTRA_GENERATE_DEPS_TARGETS) ## Dev: Run all code generation

$(POLICY_GEN):
cd $(KUMA_DIR) && go build -o ./build/tools-${GOOS}-${GOARCH}/policy-gen/generator ./tools/policy-gen/generator/main.go
Expand Down Expand Up @@ -94,8 +94,13 @@ generate/kumapolicy-gen/%: $(POLICY_GEN) generate/dirs/%
$(POLICY_GEN) plugin-file --plugin-dir $(POLICIES_DIR)/$* --gomodule $(GO_MODULE) && \
$(POLICY_GEN) helpers --plugin-dir $(POLICIES_DIR)/$* --gomodule $(GO_MODULE)

endpoints = $(foreach dir,$(shell find api/openapi/specs -type f | sort),$(basename $(dir)))

generate/oas:
$(POLICY_GEN) k8s-resource --plugin-dir pkg/api-server/specs/types/$* --gomodule $(GO_MODULE)
for endpoint in $(endpoints); do \
DEST=$${endpoint#"api/openapi/specs"}; \
PATH=$(CI_TOOLS_BIN_DIR):$$PATH oapi-codegen -config api/openapi/openapi.cfg.yaml -o api/openapi/types/$$(dirname $${DEST}})/zz_generated.$$(basename $${DEST}).go $${endpoint}.yaml; \
done

generate/dirs/%:
for version in $(foreach dir,$(wildcard $(POLICIES_DIR)/$*/api/*),$(notdir $(dir))); do \
Expand Down

0 comments on commit e9e6d76

Please sign in to comment.