This commit is contained in:
marco 2024-03-07 23:06:01 +01:00
parent b210b0f233
commit d36425e471
3 changed files with 11 additions and 13 deletions

View file

@ -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

8
pkg/cti/generate.go Normal file
View file

@ -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

View file

@ -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=../