Skip to content

Commit

Permalink
Add pkg.go.dev links to deprecation warnings
Browse files Browse the repository at this point in the history
So they're more actionable, as the previous setup didn't quite make it
possible to link directly through to replacing symbol.
  • Loading branch information
jamietanna committed Oct 24, 2023
1 parent eb5e119 commit 81b4e34
Show file tree
Hide file tree
Showing 20 changed files with 124 additions and 124 deletions.
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
issues:
exclude:
- '.*This has been replaced by github.com/oapi-codegen/runtime.*'
- '.*This has been replaced by https://pkg.go.dev/github.com/oapi-codegen/runtime.*'
16 changes: 8 additions & 8 deletions pkg/chi-middleware/oapi_validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ import (

// ErrorHandler is called when there is an error in validation
//
// Deprecated: This has been replaced by github.com/oapi-codegen/nethttp-middleware#ErrorHandler
// Deprecated: This has been replaced by https://pkg.go.dev/github.com/oapi-codegen/nethttp-middleware#ErrorHandler
type ErrorHandler func(w http.ResponseWriter, message string, statusCode int)

// MultiErrorHandler is called when oapi returns a MultiError type
//
// Deprecated: This has been replaced by github.com/oapi-codegen/nethttp-middleware#
// Deprecated: This has been replaced by https://pkg.go.dev/github.com/oapi-codegen/nethttp-middleware#
type MultiErrorHandler func(openapi3.MultiError) (int, error)

// Options to customize request validation, openapi3filter specified options will be passed through.
//
// Deprecated: This has been replaced by github.com/oapi-codegen/nethttp-middleware#Options
// Deprecated: This has been replaced by https://pkg.go.dev/github.com/oapi-codegen/nethttp-middleware#Options
type Options struct {
Options openapi3filter.Options
ErrorHandler ErrorHandler
Expand All @@ -40,15 +40,15 @@ type Options struct {
// OapiRequestValidator Creates middleware to validate request by swagger spec.
// This middleware is good for net/http either since go-chi is 100% compatible with net/http.
//
// Deprecated: This has been replaced by github.com/oapi-codegen/nethttp-middleware#OapiRequestValidator
// Deprecated: This has been replaced by https://pkg.go.dev/github.com/oapi-codegen/nethttp-middleware#OapiRequestValidator
func OapiRequestValidator(swagger *openapi3.T) func(next http.Handler) http.Handler {
return OapiRequestValidatorWithOptions(swagger, nil)
}

// OapiRequestValidatorWithOptions Creates middleware to validate request by swagger spec.
// This middleware is good for net/http either since go-chi is 100% compatible with net/http.
//
// Deprecated: This has been replaced by github.com/oapi-codegen/nethttp-middleware#OapiRequestValidatorWithOptions
// Deprecated: This has been replaced by https://pkg.go.dev/github.com/oapi-codegen/nethttp-middleware#OapiRequestValidatorWithOptions
func OapiRequestValidatorWithOptions(swagger *openapi3.T, options *Options) func(next http.Handler) http.Handler {
if swagger.Servers != nil && (options == nil || !options.SilenceServersWarning) {
log.Println("WARN: OapiRequestValidatorWithOptions called with an OpenAPI spec that has `Servers` set. This may lead to an HTTP 400 with `no matching operation was found` when sending a valid request, as the validator performs `Host` header validation. If you're expecting `Host` header validation, you can silence this warning by setting `Options.SilenceServersWarning = true`. See https://github.com/deepmap/oapi-codegen/issues/882 for more information.")
Expand Down Expand Up @@ -82,7 +82,7 @@ func OapiRequestValidatorWithOptions(swagger *openapi3.T, options *Options) func
// validateRequest is called from the middleware above and actually does the work
// of validating a request.
//
// Deprecated: This has been replaced by github.com/oapi-codegen/nethttp-middleware#validateRequest
// Deprecated: This has been replaced by https://pkg.go.dev/github.com/oapi-codegen/nethttp-middleware#validateRequest
func validateRequest(r *http.Request, router routers.Router, options *Options) (int, error) {

// Find route
Expand Down Expand Up @@ -131,7 +131,7 @@ func validateRequest(r *http.Request, router routers.Router, options *Options) (
// attempt to get the MultiErrorHandler from the options. If it is not set,
// return a default handler
//
// Deprecated: This has been replaced by github.com/oapi-codegen/nethttp-middleware#getMultiErrorHandlerFromOptions
// Deprecated: This has been replaced by https://pkg.go.dev/github.com/oapi-codegen/nethttp-middleware#getMultiErrorHandlerFromOptions
func getMultiErrorHandlerFromOptions(options *Options) MultiErrorHandler {
if options == nil {
return defaultMultiErrorHandler
Expand All @@ -148,7 +148,7 @@ func getMultiErrorHandlerFromOptions(options *Options) MultiErrorHandler {
// of all the errors. This method is called if there are no other
// methods defined on the options.
//
// Deprecated: This has been replaced by github.com/oapi-codegen/nethttp-middleware#defaultMultiErrorHandler
// Deprecated: This has been replaced by https://pkg.go.dev/github.com/oapi-codegen/nethttp-middleware#defaultMultiErrorHandler
func defaultMultiErrorHandler(me openapi3.MultiError) (int, error) {
return http.StatusBadRequest, me
}
22 changes: 11 additions & 11 deletions pkg/fiber-middleware/oapi_validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type ctxKeyUserData struct{}

// OapiValidatorFromYamlFile creates a validator middleware from a YAML file path
//
// Deprecated: This has been replaced by github.com/oapi-codegen/fiber-middleware#OapiValidatorFromYamlFile
// Deprecated: This has been replaced by https://pkg.go.dev/github.com/oapi-codegen/fiber-middleware#OapiValidatorFromYamlFile
func OapiValidatorFromYamlFile(path string) (fiber.Handler, error) {

data, err := os.ReadFile(path)
Expand All @@ -45,25 +45,25 @@ func OapiValidatorFromYamlFile(path string) (fiber.Handler, error) {
// to make sure that they conform to the given OAPI 3.0 specification. When
// OAPI validation fails on the request, we return an HTTP/400 with error message
//
// Deprecated: This has been replaced by github.com/oapi-codegen/fiber-middleware#OapiRequestValidator
// Deprecated: This has been replaced by https://pkg.go.dev/github.com/oapi-codegen/fiber-middleware#OapiRequestValidator
func OapiRequestValidator(swagger *openapi3.T) fiber.Handler {
return OapiRequestValidatorWithOptions(swagger, nil)
}

// ErrorHandler is called when there is an error in validation
//
// Deprecated: This has been replaced by github.com/oapi-codegen/fiber-middleware#ErrorHandler
// Deprecated: This has been replaced by https://pkg.go.dev/github.com/oapi-codegen/fiber-middleware#ErrorHandler
type ErrorHandler func(c *fiber.Ctx, message string, statusCode int)

// MultiErrorHandler is called when oapi returns a MultiError type
//
// Deprecated: This has been replaced by github.com/oapi-codegen/fiber-middleware#MultiErrorHandler
// Deprecated: This has been replaced by https://pkg.go.dev/github.com/oapi-codegen/fiber-middleware#MultiErrorHandler
type MultiErrorHandler func(openapi3.MultiError) error

// Options to customize request validation. These are passed through to
// openapi3filter.
//
// Deprecated: This has been replaced by github.com/oapi-codegen/fiber-middleware#Options
// Deprecated: This has been replaced by https://pkg.go.dev/github.com/oapi-codegen/fiber-middleware#Options
type Options struct {
Options openapi3filter.Options
ErrorHandler ErrorHandler
Expand All @@ -74,7 +74,7 @@ type Options struct {

// OapiRequestValidatorWithOptions creates a validator from a swagger object, with validation options
//
// Deprecated: This has been replaced by github.com/oapi-codegen/fiber-middleware#OapiRequestValidatorWithOptions
// Deprecated: This has been replaced by https://pkg.go.dev/github.com/oapi-codegen/fiber-middleware#OapiRequestValidatorWithOptions
func OapiRequestValidatorWithOptions(swagger *openapi3.T, options *Options) fiber.Handler {

router, err := gorillamux.NewRouter(swagger)
Expand Down Expand Up @@ -102,7 +102,7 @@ func OapiRequestValidatorWithOptions(swagger *openapi3.T, options *Options) fibe
// ValidateRequestFromContext is called from the middleware above and actually does the work
// of validating a request.
//
// Deprecated: This has been replaced by github.com/oapi-codegen/fiber-middleware#
// Deprecated: This has been replaced by https://pkg.go.dev/github.com/oapi-codegen/fiber-middleware#
func ValidateRequestFromContext(c *fiber.Ctx, router routers.Router, options *Options) error {

r, err := adaptor.ConvertRequest(c, false)
Expand Down Expand Up @@ -172,7 +172,7 @@ func ValidateRequestFromContext(c *fiber.Ctx, router routers.Router, options *Op
// GetFiberContext gets the fiber context from within requests. It returns
// nil if not found or wrong type.
//
// Deprecated: This has been replaced by github.com/oapi-codegen/fiber-middleware#GetFiberContext
// Deprecated: This has been replaced by https://pkg.go.dev/github.com/oapi-codegen/fiber-middleware#GetFiberContext
func GetFiberContext(c context.Context) *fiber.Ctx {
iface := c.Value(ctxKeyFiberContext{})
if iface == nil {
Expand All @@ -186,15 +186,15 @@ func GetFiberContext(c context.Context) *fiber.Ctx {
return nil
}

// Deprecated: This has been replaced by github.com/oapi-codegen/fiber-middleware#GetUserData
// Deprecated: This has been replaced by https://pkg.go.dev/github.com/oapi-codegen/fiber-middleware#GetUserData
func GetUserData(c context.Context) interface{} {
return c.Value(ctxKeyUserData{})
}

// getMultiErrorHandlerFromOptions attempts to get the MultiErrorHandler from the options. If it is not set,
// return a default handler
//
// Deprecated: This has been replaced by github.com/oapi-codegen/fiber-middleware#getMultiErrorHandlerFromOptions
// Deprecated: This has been replaced by https://pkg.go.dev/github.com/oapi-codegen/fiber-middleware#getMultiErrorHandlerFromOptions
func getMultiErrorHandlerFromOptions(options *Options) MultiErrorHandler {
if options == nil {
return defaultMultiErrorHandler
Expand All @@ -210,7 +210,7 @@ func getMultiErrorHandlerFromOptions(options *Options) MultiErrorHandler {
// defaultMultiErrorHandler returns a StatusBadRequest (400) and a list
// of all the errors. This method is called if there are no other
// methods defined on the options.
// Deprecated: This has been replaced by github.com/oapi-codegen/fiber-middleware#defaultMultiErrorHandler
// Deprecated: This has been replaced by https://pkg.go.dev/github.com/oapi-codegen/fiber-middleware#defaultMultiErrorHandler
func defaultMultiErrorHandler(me openapi3.MultiError) error {
return fmt.Errorf("multiple errors encountered: %s", me)
}
20 changes: 10 additions & 10 deletions pkg/gin-middleware/oapi_validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const (

// OapiValidatorFromYamlFile creates a validator middleware from a YAML file path
//
// Deprecated: This has been replaced by github.com/oapi-codegen/gin-middleware#OapiValidatorFromYamlFile
// Deprecated: This has been replaced by https://pkg.go.dev/github.com/oapi-codegen/gin-middleware#OapiValidatorFromYamlFile
func OapiValidatorFromYamlFile(path string) (gin.HandlerFunc, error) {
data, err := os.ReadFile(path)
if err != nil {
Expand All @@ -56,25 +56,25 @@ func OapiValidatorFromYamlFile(path string) (gin.HandlerFunc, error) {
// to make sure that they conform to the given OAPI 3.0 specification. When
// OAPI validation fails on the request, we return an HTTP/400 with error message
//
// Deprecated: This has been replaced by github.com/oapi-codegen/gin-middleware#OapiRequestValidator
// Deprecated: This has been replaced by https://pkg.go.dev/github.com/oapi-codegen/gin-middleware#OapiRequestValidator
func OapiRequestValidator(swagger *openapi3.T) gin.HandlerFunc {
return OapiRequestValidatorWithOptions(swagger, nil)
}

// ErrorHandler is called when there is an error in validation
//
// Deprecated: This has been replaced by github.com/oapi-codegen/gin-middleware#ErrorHandler
// Deprecated: This has been replaced by https://pkg.go.dev/github.com/oapi-codegen/gin-middleware#ErrorHandler
type ErrorHandler func(c *gin.Context, message string, statusCode int)

// MultiErrorHandler is called when oapi returns a MultiError type
//
// Deprecated: This has been replaced by github.com/oapi-codegen/gin-middleware#MultiErrorHandler
// Deprecated: This has been replaced by https://pkg.go.dev/github.com/oapi-codegen/gin-middleware#MultiErrorHandler
type MultiErrorHandler func(openapi3.MultiError) error

// Options to customize request validation. These are passed through to
// openapi3filter.
//
// Deprecated: This has been replaced by github.com/oapi-codegen/gin-middleware#Options
// Deprecated: This has been replaced by https://pkg.go.dev/github.com/oapi-codegen/gin-middleware#Options
type Options struct {
ErrorHandler ErrorHandler
Options openapi3filter.Options
Expand All @@ -87,7 +87,7 @@ type Options struct {

// OapiRequestValidatorWithOptions creates a validator from a swagger object, with validation options
//
// Deprecated: This has been replaced by github.com/oapi-codegen/gin-middleware#OapiRequestValidatorWithOptions
// Deprecated: This has been replaced by https://pkg.go.dev/github.com/oapi-codegen/gin-middleware#OapiRequestValidatorWithOptions
func OapiRequestValidatorWithOptions(swagger *openapi3.T, options *Options) gin.HandlerFunc {
if swagger.Servers != nil && (options == nil || !options.SilenceServersWarning) {
log.Println("WARN: OapiRequestValidatorWithOptions called with an OpenAPI spec that has `Servers` set. This may lead to an HTTP 400 with `no matching operation was found` when sending a valid request, as the validator performs `Host` header validation. If you're expecting `Host` header validation, you can silence this warning by setting `Options.SilenceServersWarning = true`. See https://github.com/deepmap/oapi-codegen/issues/882 for more information.")
Expand Down Expand Up @@ -124,7 +124,7 @@ func OapiRequestValidatorWithOptions(swagger *openapi3.T, options *Options) gin.
// ValidateRequestFromContext is called from the middleware above and actually does the work
// of validating a request.
//
// Deprecated: This has been replaced by github.com/oapi-codegen/gin-middleware#ValidateRequestFromContext
// Deprecated: This has been replaced by https://pkg.go.dev/github.com/oapi-codegen/gin-middleware#ValidateRequestFromContext
func ValidateRequestFromContext(c *gin.Context, router routers.Router, options *Options) error {
req := c.Request
route, pathParams, err := router.FindRoute(req)
Expand Down Expand Up @@ -188,7 +188,7 @@ func ValidateRequestFromContext(c *gin.Context, router routers.Router, options *
// GetGinContext gets the echo context from within requests. It returns
// nil if not found or wrong type.
//
// Deprecated: This has been replaced by github.com/oapi-codegen/gin-middleware#GetGinContext
// Deprecated: This has been replaced by https://pkg.go.dev/github.com/oapi-codegen/gin-middleware#GetGinContext
func GetGinContext(c context.Context) *gin.Context {
iface := c.Value(GinContextKey)
if iface == nil {
Expand All @@ -208,7 +208,7 @@ func GetUserData(c context.Context) interface{} {
// attempt to get the MultiErrorHandler from the options. If it is not set,
// return a default handler
//
// Deprecated: This has been replaced by github.com/oapi-codegen/gin-middleware#getMultiErrorHandlerFromOptions
// Deprecated: This has been replaced by https://pkg.go.dev/github.com/oapi-codegen/gin-middleware#getMultiErrorHandlerFromOptions
func getMultiErrorHandlerFromOptions(options *Options) MultiErrorHandler {
if options == nil {
return defaultMultiErrorHandler
Expand All @@ -225,7 +225,7 @@ func getMultiErrorHandlerFromOptions(options *Options) MultiErrorHandler {
// of all of the errors. This method is called if there are no other
// methods defined on the options.
//
// Deprecated: This has been replaced by github.com/oapi-codegen/gin-middleware#defaultMultiErrorHandler
// Deprecated: This has been replaced by https://pkg.go.dev/github.com/oapi-codegen/gin-middleware#defaultMultiErrorHandler
func defaultMultiErrorHandler(me openapi3.MultiError) error {
return fmt.Errorf("multiple errors encountered: %s", me)
}
Loading

0 comments on commit 81b4e34

Please sign in to comment.