From d36425e4716645cdf1aca4fd294113dd166ef7b0 Mon Sep 17 00:00:00 2001 From: marco Date: Thu, 7 Mar 2024 23:06:01 +0100 Subject: [PATCH] wip --- Makefile | 14 ++------------ pkg/cti/generate.go | 8 ++++++++ pkg/models/generate.go | 2 +- 3 files changed, 11 insertions(+), 13 deletions(-) create mode 100644 pkg/cti/generate.go diff --git a/Makefile b/Makefile index 6e2a8e73d..e1ff590d8 100644 --- a/Makefile +++ b/Makefile @@ -156,18 +156,6 @@ endif # intentional, empty line $(info ) - -# To update openapi.yaml: -# curl https://crowdsecurity.github.io/cti-api/v2/swagger.yaml > ./pkg/cti/openapi.yaml - -.PHONY: gen-cti -gen-cti: ## Generate CTI client code from the specs - @which oapi-codegen > /dev/null 2>&1 || (echo "oapi-codegen is not installed. You can install it with 'go install github.com/deepmap/oapi-codegen/v2/cmd/oapi-codegen@latest'" && exit 1) - @echo "Generating Go client from OpenAPI spec..." - oapi-codegen -package cti -generate client -o ./pkg/cti/client.go ./pkg/cti/openapi.yaml - oapi-codegen -package cti -generate types -o ./pkg/cti/types.go ./pkg/cti/openapi.yaml - @echo "Client generation complete." - .PHONY: all all: clean test build ## Clean, test and build (requires localstack) @@ -223,6 +211,8 @@ crowdsec: goversion ## Build crowdsec generate: ## Generate code for the database and APIs $(GO) generate ./pkg/database/ent $(GO) generate ./pkg/models + $(GO) generate ./pkg/cti + @echo "Code generation complete." .PHONY: testclean testclean: bats-clean ## Remove test artifacts diff --git a/pkg/cti/generate.go b/pkg/cti/generate.go new file mode 100644 index 000000000..c2210cdd3 --- /dev/null +++ b/pkg/cti/generate.go @@ -0,0 +1,8 @@ +package cti + +// To update openapi.yaml: +// curl https://crowdsecurity.github.io/cti-api/v2/swagger.yaml > ./pkg/cti/openapi.yaml + +//go:generate go run -mod=mod github.com/deepmap/oapi-codegen/v2/cmd/oapi-codegen@v2.1.0 -package=cti -generate client -o ./client.go ./openapi.yaml +//go:generate go run -mod=mod github.com/deepmap/oapi-codegen/v2/cmd/oapi-codegen@v2.1.0 -package=cti -generate types -o ./types.go ./openapi.yaml + diff --git a/pkg/models/generate.go b/pkg/models/generate.go index ccacc409a..45e22944b 100644 --- a/pkg/models/generate.go +++ b/pkg/models/generate.go @@ -1,4 +1,4 @@ package models -//go:generate go run -mod=mod github.com/go-swagger/go-swagger/cmd/swagger@v0.30.5 generate model --spec=./localapi_swagger.yaml --target=../ +//go:generate go run -mod=mod github.com/go-swagger/go-swagger/cmd/swagger@v0.30.5 generate model --spec=./localapi_swagger.yaml --quiet --target=../