Skip to content

Commit

Permalink
Migrate middleware to their own Go modules
Browse files Browse the repository at this point in the history
Similar to our work with the migration to separate modules for the
`pkg/runtime` and `pkg/types` packages, we can do the same for the
middleware.

This allows us to iterate over these quicker than the underlying code
generator and gives us the opportunity to introduce breaking changes
more easily if appropriate.

These won't be removed until the next major version, but we can mark
them as deprecated to nudge folks to move away from them.
  • Loading branch information
jamietanna committed Sep 17, 2023
1 parent af55078 commit 2d349f4
Show file tree
Hide file tree
Showing 17 changed files with 32 additions and 18 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 260,7 @@ func RegisterHandlersWithOptions(router *gin.Engine, si ServerInterface, options
import (
"github.com/gin-gonic/gin"
"github.com/deepmap/oapi-codegen/examples/petstore-expanded/gin/api"
middleware "github.com/deepmap/oapi-codegen/pkg/gin-middleware"
middleware "github.com/oapi-codegen/gin-middleware"
)

type PetStoreImpl struct {}
Expand Down Expand Up @@ -329,7 329,7 @@ func RegisterHandlersWithOptions(router *iris.Application, si ServerInterface, o
import (
"github.com/kataras/iris/v12"
"github.com/deepmap/oapi-codegen/examples/petstore-expanded/iris/api"
middleware "github.com/deepmap/oapi-codegen/pkg/iris-middleware"
middleware "github.com/oapi-codegen/iris-middleware"
)
```

Expand Down
5 changes: 2 additions & 3 deletions examples/authenticated-api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 35,7 @@ This means that all API endpoints require a JWT bearer token for access, and
without any specific scopes, as denoted by `[]`.

However, we want our `addThing` operation to require a special write permission,
denoted by `things:w`. This is a convention that we use in naming scopes,
denoted by `things:w`. This is a convention that we use in naming scopes,
noun followed by type of access, in this case, `:w` means write. Read permission
is implicit from having a valid JWT.

Expand All @@ -55,8 55,7 @@ instead of implementing too much ourselves. We've chosen to use the excellent
validation, and the [kin-openapi](https://github.com/getkin/kin-openapi/tree/master/openapi3filter)
request filter to help us perform validation.
First, we need to configure our [OapiRequestValidator](https://github.com/deepmap/oapi-codegen/blob/master/pkg/middleware/oapi_validate.go)
to perform authentication:
First, we need to configure our `OapiRequestValidator` to perform authentication:
```go
validator := middleware.OapiRequestValidatorWithOptions(spec,
&middleware.Options{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 7,9 @@ import (
"net/http"
"strings"

"github.com/deepmap/oapi-codegen/pkg/middleware"
"github.com/getkin/kin-openapi/openapi3filter"
"github.com/lestrrat-go/jwx/jwt"
middleware "github.com/oapi-codegen/echo-middleware"
)

// JWSValidator is used to validate JWS payloads and return a JWT if they're
Expand Down
2 changes: 1 addition & 1 deletion examples/authenticated-api/echo/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 7,9 @@ import (
"sync"

"github.com/deepmap/oapi-codegen/examples/authenticated-api/echo/api"
"github.com/deepmap/oapi-codegen/pkg/middleware"
"github.com/getkin/kin-openapi/openapi3filter"
"github.com/labstack/echo/v4"
middleware "github.com/oapi-codegen/echo-middleware"
)

type server struct {
Expand Down
5 changes: 5 additions & 0 deletions examples/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 14,11 @@ require (
github.com/kataras/iris/v12 v12.2.6-0.20230908161203-24ba4e8933b9
github.com/labstack/echo/v4 v4.11.1
github.com/lestrrat-go/jwx v1.2.26
github.com/oapi-codegen/echo-middleware v1.0.1
github.com/oapi-codegen/fiber-middleware v1.0.1
github.com/oapi-codegen/gin-middleware v1.0.1
github.com/oapi-codegen/iris-middleware v1.0.4
github.com/oapi-codegen/nethttp-middleware v1.0.1
github.com/oapi-codegen/runtime v1.0.0
github.com/stretchr/testify v1.8.4
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616
Expand Down
10 changes: 10 additions & 0 deletions examples/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 168,16 @@ github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjY
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9M 97sNutRR1RKhG96O6jWumTTnw=
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf YrPgl8=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/oapi-codegen/echo-middleware v1.0.1 h1:edYGScq1phCcuDoz9AqA9eHX tEI1LNL5PL1lkkQh1k=
github.com/oapi-codegen/echo-middleware v1.0.1/go.mod h1:DBQKRn D/vfXOFbaX5GRwFttoJY64JH6yu pdt7wU3o=
github.com/oapi-codegen/fiber-middleware v1.0.1 h1:DZQA tEsqEMox4pPmc6SJXvDriiWSxc3QiA4UuMwGq4=
github.com/oapi-codegen/fiber-middleware v1.0.1/go.mod h1:UUVrHLPT4Zv7S2U2TCGLXpTx6mfMb613UI Z6F8S5Vk=
github.com/oapi-codegen/gin-middleware v1.0.1 h1:903hkcyMcM/h6ooHS7t/2ad973BY0xvsRNP0EN1B65g=
github.com/oapi-codegen/gin-middleware v1.0.1/go.mod h1:JDMxGX/rErQs2VV0XAVo1sD6sA0EVUMvFSPhgOLt9mE=
github.com/oapi-codegen/iris-middleware v1.0.4 h1: Eoqqbc90qCeBz3Zlzf1xb5xn wfwQihndHlvU/4Meo=
github.com/oapi-codegen/iris-middleware v1.0.4/go.mod h1:D1IAqYMgm5QKbD9R y0j8m xUtiPLMG92iY oos/NXc=
github.com/oapi-codegen/nethttp-middleware v1.0.1 h1:ZWvwfnMU0eloHX1VEJmQscQm3741t0vCm0eSIie1NIo=
github.com/oapi-codegen/nethttp-middleware v1.0.1/go.mod h1:P7xtAvpoqNB 5obR9qRCeefH7YlXWSK3KgPs/9WB8tE=
github.com/oapi-codegen/runtime v1.0.0 h1:P4rqFX5fMFWqRzY9M/3YF9 aPSPPB06IzP2P7oOxrWo=
github.com/oapi-codegen/runtime v1.0.0/go.mod h1:LmCUMQuPB4M/nLXilQXhHw BLZdDb18B34OO356yJ/A=
github.com/pelletier/go-toml/v2 v2.0.9 h1:uH2qQXheeefCCkuBBSLi7jCiSmj3VRh2 Goq2N7Xxu0=
Expand Down
2 changes: 1 addition & 1 deletion examples/petstore-expanded/chi/petstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 13,7 @@ import (
"os"

"github.com/deepmap/oapi-codegen/examples/petstore-expanded/chi/api"
middleware "github.com/deepmap/oapi-codegen/pkg/chi-middleware"
middleware "github.com/oapi-codegen/nethttp-middleware"
"github.com/go-chi/chi/v5"
)

Expand Down
2 changes: 1 addition & 1 deletion examples/petstore-expanded/chi/petstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 8,7 @@ import (
"testing"

"github.com/deepmap/oapi-codegen/examples/petstore-expanded/chi/api"
middleware "github.com/deepmap/oapi-codegen/pkg/chi-middleware"
middleware "github.com/oapi-codegen/nethttp-middleware"
"github.com/deepmap/oapi-codegen/pkg/testutil"
"github.com/go-chi/chi/v5"
"github.com/stretchr/testify/assert"
Expand Down
2 changes: 1 addition & 1 deletion examples/petstore-expanded/echo/petstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 12,9 @@ import (
"os"

"github.com/deepmap/oapi-codegen/examples/petstore-expanded/echo/api"
"github.com/deepmap/oapi-codegen/pkg/middleware"
"github.com/labstack/echo/v4"
echomiddleware "github.com/labstack/echo/v4/middleware"
middleware "github.com/oapi-codegen/echo-middleware"
)

func main() {
Expand Down
2 changes: 1 addition & 1 deletion examples/petstore-expanded/echo/petstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 21,10 @@ import (

"github.com/deepmap/oapi-codegen/examples/petstore-expanded/echo/api"
"github.com/deepmap/oapi-codegen/examples/petstore-expanded/echo/api/models"
"github.com/deepmap/oapi-codegen/pkg/middleware"
"github.com/deepmap/oapi-codegen/pkg/testutil"
"github.com/labstack/echo/v4"
echoMiddleware "github.com/labstack/echo/v4/middleware"
middleware "github.com/oapi-codegen/echo-middleware"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down
2 changes: 1 addition & 1 deletion examples/petstore-expanded/fiber/petstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 14,7 @@ import (
"github.com/gofiber/fiber/v2"

"github.com/deepmap/oapi-codegen/examples/petstore-expanded/fiber/api"
middleware "github.com/deepmap/oapi-codegen/pkg/fiber-middleware"
middleware "github.com/oapi-codegen/fiber-middleware"
)

func main() {
Expand Down
2 changes: 1 addition & 1 deletion examples/petstore-expanded/gin/petstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 15,7 @@ import (
"github.com/gin-gonic/gin"

"github.com/deepmap/oapi-codegen/examples/petstore-expanded/gin/api"
middleware "github.com/deepmap/oapi-codegen/pkg/gin-middleware"
middleware "github.com/oapi-codegen/gin-middleware"
)

func NewGinPetServer(petStore *api.PetStore, port string) *http.Server {
Expand Down
2 changes: 1 addition & 1 deletion examples/petstore-expanded/gorilla/petstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 13,7 @@ import (
"os"

"github.com/deepmap/oapi-codegen/examples/petstore-expanded/gorilla/api"
middleware "github.com/deepmap/oapi-codegen/pkg/chi-middleware"
middleware "github.com/oapi-codegen/nethttp-middleware"
"github.com/gorilla/mux"
)

Expand Down
2 changes: 1 addition & 1 deletion examples/petstore-expanded/gorilla/petstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 8,7 @@ import (
"testing"

"github.com/deepmap/oapi-codegen/examples/petstore-expanded/gorilla/api"
middleware "github.com/deepmap/oapi-codegen/pkg/chi-middleware"
middleware "github.com/oapi-codegen/nethttp-middleware"
"github.com/deepmap/oapi-codegen/pkg/testutil"
"github.com/gorilla/mux"
"github.com/stretchr/testify/assert"
Expand Down
2 changes: 1 addition & 1 deletion examples/petstore-expanded/iris/petstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 12,7 @@ import (
"os"

"github.com/deepmap/oapi-codegen/examples/petstore-expanded/iris/api"
middleware "github.com/deepmap/oapi-codegen/pkg/iris-middleware"
middleware "github.com/oapi-codegen/iris-middleware"
"github.com/kataras/iris/v12"
)

Expand Down
2 changes: 1 addition & 1 deletion examples/petstore-expanded/strict/petstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 13,7 @@ import (
"os"

"github.com/deepmap/oapi-codegen/examples/petstore-expanded/strict/api"
middleware "github.com/deepmap/oapi-codegen/pkg/chi-middleware"
middleware "github.com/oapi-codegen/nethttp-middleware"
"github.com/go-chi/chi/v5"
)

Expand Down
2 changes: 1 addition & 1 deletion examples/petstore-expanded/strict/petstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 8,7 @@ import (
"testing"

"github.com/deepmap/oapi-codegen/examples/petstore-expanded/strict/api"
middleware "github.com/deepmap/oapi-codegen/pkg/chi-middleware"
middleware "github.com/oapi-codegen/nethttp-middleware"
"github.com/deepmap/oapi-codegen/pkg/testutil"
"github.com/go-chi/chi/v5"
"github.com/stretchr/testify/assert"
Expand Down

0 comments on commit 2d349f4

Please sign in to comment.