Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
mmetc committed Mar 7, 2024
1 parent b210b0f commit d36425e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
14 changes: 2 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions pkg/cti/generate.go
Original file line number Diff line number Diff line change
@@ -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/[email protected] -package=cti -generate client -o ./client.go ./openapi.yaml
//go:generate go run -mod=mod github.com/deepmap/oapi-codegen/v2/cmd/[email protected] -package=cti -generate types -o ./types.go ./openapi.yaml

2 changes: 1 addition & 1 deletion pkg/models/generate.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package models

//go:generate go run -mod=mod github.com/go-swagger/go-swagger/cmd/[email protected] generate model --spec=./localapi_swagger.yaml --target=../
//go:generate go run -mod=mod github.com/go-swagger/go-swagger/cmd/[email protected] generate model --spec=./localapi_swagger.yaml --quiet --target=../

0 comments on commit d36425e

Please sign in to comment.