diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3467674..0da0575 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,25 +1,12 @@ -name: Build project -on: [ push, pull_request ] +name: CI +on: + push: {} + pull_request: {} + workflow_dispatch: {} +permissions: + contents: read jobs: build: - name: Build - runs-on: ubuntu-latest - strategy: - fail-fast: false - # perform matrix testing to give us an earlier insight into issues with different versions of supported major versions of Go - matrix: - version: - - "1.20" - - "1.21" - - "1.22" - steps: - - name: Check out source code - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 - - - name: Set up Go - uses: actions/setup-go@0aaccfd150d50ccaeb58ebd88d36e91967a5f35b # v5 - with: - go-version: ${{ matrix.version }} - - - name: Test - run: make test + uses: oapi-codegen/actions/.github/workflows/ci.yml@75566d848d25021f137594c947f26171094fb511 # v0.5.0 + with: + lint_versions: '["1.25"]' diff --git a/.github/workflows/generate.yml b/.github/workflows/generate.yml deleted file mode 100644 index 1552de8..0000000 --- a/.github/workflows/generate.yml +++ /dev/null @@ -1,28 +0,0 @@ -name: Ensure generated files are up-to-date -on: [ push, pull_request ] -jobs: - build: - name: Build - runs-on: ubuntu-latest - strategy: - fail-fast: false - # perform matrix testing to give us an earlier insight into issues with different versions of supported major versions of Go - matrix: - version: - - "1.20" - - "1.21" - - "1.22" - steps: - - name: Check out source code - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 - - - name: Set up Go - uses: actions/setup-go@0aaccfd150d50ccaeb58ebd88d36e91967a5f35b # v5 - with: - go-version: ${{ matrix.version }} - - - name: Run `make generate` - run: make generate - - - name: Check for no untracked files - run: git status && git diff-index --quiet HEAD -- diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml deleted file mode 100644 index 33d68cf..0000000 --- a/.github/workflows/lint.yml +++ /dev/null @@ -1,25 +0,0 @@ -name: Lint project -on: [push, pull_request] -jobs: - build: - name: Build - runs-on: ubuntu-latest - strategy: - fail-fast: false - # perform matrix testing to give us an earlier insight into issues with different versions of supported major versions of Go - matrix: - version: - - "1.20" - - "1.21" - - "1.22" - steps: - - name: Check out source code - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 - - - name: Set up Go - uses: actions/setup-go@0aaccfd150d50ccaeb58ebd88d36e91967a5f35b # v5 - with: - go-version: ${{ matrix.version }} - - - name: Run `make lint-ci` - run: make lint-ci diff --git a/.github/workflows/tidy.yml b/.github/workflows/tidy.yml deleted file mode 100644 index fff71a2..0000000 --- a/.github/workflows/tidy.yml +++ /dev/null @@ -1,28 +0,0 @@ -name: Ensure `go mod tidy` has been run -on: [ push, pull_request ] -jobs: - build: - name: Build - runs-on: ubuntu-latest - strategy: - fail-fast: false - # perform matrix testing to give us an earlier insight into issues with different versions of supported major versions of Go - matrix: - version: - - "1.20" - - "1.21" - - "1.22" - steps: - - name: Check out source code - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 - - - name: Set up Go - uses: actions/setup-go@0aaccfd150d50ccaeb58ebd88d36e91967a5f35b # v5 - with: - go-version: ${{ matrix.version }} - - - name: Install `tidied` - run: go install gitlab.com/jamietanna/tidied@latest - - - name: Check for no untracked files - run: tidied -verbose diff --git a/Makefile b/Makefile index e83b8bc..08ecfaa 100644 --- a/Makefile +++ b/Makefile @@ -1,32 +1,44 @@ GOBASE=$(shell pwd) GOBIN=$(GOBASE)/bin -help: - @echo "This is a helper makefile for oapi-codegen" - @echo "Targets:" - @echo " generate: regenerate all generated files" - @echo " test: run all tests" - @echo " gin_example generate gin example server code" - @echo " tidy tidy go mod" - $(GOBIN)/golangci-lint: - curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOBIN) v1.55.2 + curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOBIN) v2.10.1 .PHONY: tools tools: $(GOBIN)/golangci-lint lint: tools + # run the root module explicitly, to prevent recursive calls by re-invoking `make ...` top-level $(GOBIN)/golangci-lint run ./... + # then, for all child modules, use a module-managed `Makefile` + git ls-files '**/*go.mod' -z | xargs -0 -I{} bash -xc 'cd $$(dirname {}) && env GOBIN=$(GOBIN) make lint' lint-ci: tools - $(GOBIN)/golangci-lint run ./... --out-format=github-actions --timeout=5m + # for the root module, explicitly run the step, to prevent recursive calls + $(GOBIN)/golangci-lint run ./... --output.text.path=stdout --timeout=5m + # then, for all child modules, use a module-managed `Makefile` + git ls-files '**/*go.mod' -z | xargs -0 -I{} bash -xc 'cd $$(dirname {}) && env GOBIN=$(GOBIN) make lint-ci' generate: + # for the root module, explicitly run the step, to prevent recursive calls go generate ./... + # then, for all child modules, use a module-managed `Makefile` + git ls-files '**/*go.mod' -z | xargs -0 -I{} bash -xc 'cd $$(dirname {}) && make generate' test: + # for the root module, explicitly run the step, to prevent recursive calls go test -cover ./... + # then, for all child modules, use a module-managed `Makefile` + git ls-files '**/*go.mod' -z | xargs -0 -I{} bash -xc 'cd $$(dirname {}) && make test' tidy: - @echo "tidy..." + # for the root module, explicitly run the step, to prevent recursive calls go mod tidy + # then, for all child modules, use a module-managed `Makefile` + git ls-files '**/*go.mod' -z | xargs -0 -I{} bash -xc 'cd $$(dirname {}) && make tidy' + +tidy-ci: + # for the root module, explicitly run the step, to prevent recursive calls + tidied -verbose + # then, for all child modules, use a module-managed `Makefile` + git ls-files '**/*go.mod' -z | xargs -0 -I{} bash -xc 'cd $$(dirname {}) && make tidy-ci' diff --git a/strictmiddleware/echo-v5/Makefile b/strictmiddleware/echo-v5/Makefile new file mode 100644 index 0000000..943292b --- /dev/null +++ b/strictmiddleware/echo-v5/Makefile @@ -0,0 +1,32 @@ +MINIMUM_GO_MINOR := 25 +CURRENT_GO_MINOR := $(shell go version | awk '{split($$3,a,"."); print a[2]+0}') +GO_VERSION_OK := $(shell [ $(CURRENT_GO_MINOR) -ge $(MINIMUM_GO_MINOR) ] && echo yes || echo no) + +ifeq ($(GO_VERSION_OK),yes) + +lint: + $(GOBIN)/golangci-lint run ./... + +lint-ci: + $(GOBIN)/golangci-lint run ./... --output.text.path=stdout --timeout=5m + +generate: + go generate ./... + +test: + go test -cover ./... + +tidy: + go mod tidy + +tidy-ci: + tidied -verbose + +else + +SKIP_MSG := @echo "Skipping echo-v5: requires Go 1.$(MINIMUM_GO_MINOR)+ (have $$(go version | awk '{print $$3}'))" + +lint lint-ci generate test tidy tidy-ci: + $(SKIP_MSG) + +endif diff --git a/strictmiddleware/echo-v5/go.mod b/strictmiddleware/echo-v5/go.mod new file mode 100644 index 0000000..7847547 --- /dev/null +++ b/strictmiddleware/echo-v5/go.mod @@ -0,0 +1,5 @@ +module github.com/oapi-codegen/runtime/strictmiddleware/echo-v5 + +go 1.25.0 + +require github.com/labstack/echo/v5 v5.0.4 diff --git a/strictmiddleware/echo-v5/go.sum b/strictmiddleware/echo-v5/go.sum new file mode 100644 index 0000000..eb618a9 --- /dev/null +++ b/strictmiddleware/echo-v5/go.sum @@ -0,0 +1,14 @@ +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/labstack/echo/v5 v5.0.4 h1:ll3I/O8BifjMztj9dD1vx/peZQv8cR2CTUdQK6QxGGc= +github.com/labstack/echo/v5 v5.0.4/go.mod h1:SyvlSdObGjRXeQfCCXW/sybkZdOOQZBmpKF0bvALaeo= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= +github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= +golang.org/x/net v0.49.0 h1:eeHFmOGUTtaaPSGNmjBKpbng9MulQsJURQUAfUwY++o= +golang.org/x/net v0.49.0/go.mod h1:/ysNB2EvaqvesRkuLAyjI1ycPZlQHM3q01F02UY/MV8= +golang.org/x/text v0.33.0 h1:B3njUFyqtHDUI5jMn1YIr5B0IE2U0qck04r6d4KPAxE= +golang.org/x/text v0.33.0/go.mod h1:LuMebE6+rBincTi9+xWTY8TztLzKHc/9C1uBCG27+q8= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/strictmiddleware/echo-v5/main.go b/strictmiddleware/echo-v5/main.go new file mode 100644 index 0000000..e7e41d2 --- /dev/null +++ b/strictmiddleware/echo-v5/main.go @@ -0,0 +1,7 @@ +package echo + +import "github.com/labstack/echo/v5" + +type StrictEchoHandlerFunc func(ctx *echo.Context, request interface{}) (response interface{}, err error) + +type StrictEchoMiddlewareFunc func(f StrictEchoHandlerFunc, operationID string) StrictEchoHandlerFunc