Skip to content

Commit

Permalink
fix: set default globalresponse types in default options
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanhitt committed Dec 16, 2024
1 parent fea421d commit 81a7afc
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,10 @@ func NewServer(options ...func(*Server)) *Server {
WithSerializer(Send),
WithErrorSerializer(SendError),
WithErrorHandler(ErrorHandler),
}
options = append(defaultOptions[:], options...)

// Options set if not provided
options = append(options,
WithGlobalResponseTypes(http.StatusBadRequest, "Bad Request _(validation or deserialization error)_", Response{Type: HTTPError{}}),
WithGlobalResponseTypes(http.StatusInternalServerError, "Internal Server Error _(panics)_", Response{Type: HTTPError{}}),
)
}
options = append(defaultOptions[:], options...)

for _, option := range options {
option(s)
Expand Down Expand Up @@ -205,10 +201,9 @@ func WithCorsMiddleware(corsMiddleware func(http.Handler) http.Handler) func(*Se
// )
func WithGlobalResponseTypes(code int, description string, response Response) func(*Server) {
return func(c *Server) {
c.OpenAPI.globalOpenAPIResponses = append(
c.OpenAPI.globalOpenAPIResponses,
openAPIResponse{Code: code, Description: description, Response: response},
)
WithRouteOptions(
OptionAddResponse(code, description, response),
)(c)
}
}

Expand Down

1 comment on commit 81a7afc

@EwenQuim
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice one!

Please sign in to comment.