-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix bad request handling #179
Conversation
As used in the metadata endpoint we want Swagger to be able to interpret and automatically generate pagination parameters like page, size, and sort.
@@ -106,7 +106,7 @@ public ResponseEntity<Page<HousekeepingPathResponse>> getAllPaths( | |||
@Spec(path = "cleanupTimestamp", params = "deleted_after", spec = GreaterThan.class), | |||
@Spec(path = "creationTimestamp", params = "registered_before", spec = LessThan.class), | |||
@Spec(path = "creationTimestamp", params = "registered_after", spec = GreaterThan.class) }) Specification<HousekeepingPath> spec, | |||
Pageable pageable) { | |||
@ParameterObject Pageable pageable) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added @ParameterObject to the Pageable parameter, this allows Swagger to automatically generate and display pagination parameters (page, size, sort) for /unreferenced-paths. This will make it consistent with /metadata and reduces manual parameter definitions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isn't this for requests params e.g. url/bla?myRequestParam=foo
I thought the Pageable is part of the request body in this API?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Pageable
parameter is populated from url query params. The GET
request won't have a request body but the json format in swagger is misleading . .
The @ParameterObject
will ensure swagger generates better documentation for the query params, we now have separate fields for Page
, Size
& Sort
. It also resolves the Sort
filter issue by making it clearer and ensuring it's optional by default, which wasn’t the case in the JSON format.
We already have this in the /metadata
endpoint so not sure why it wasn't done for this one, you can see how the layout differs between endpoints in swagger.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cool thanks for explaning!
@@ -16,8 +13,7 @@ jobs: | |||
uses: actions/checkout@v2 | |||
with: | |||
fetch-depth: 0 | |||
ref: ${{ github.event.inputs.branch }} | |||
# We need a personal access token to be able to push to a protected branch | |||
ref: main # Hardcoded to main branch |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prior it was possible to push to maven central from any branch which can lead to accidental pushes to maven central
errorResponse.setPath(request.getRequestURI()); | ||
|
||
return new ResponseEntity<>(errorResponse, HttpStatus.BAD_REQUEST); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Handles PropertyReferenceException (e.g., invalid sort parameters) globally and returns a custom BAD_REQUEST error response with details.
beekeeper-api/src/main/java/com/expediagroup/beekeeper/api/error/BeekeeperExceptionHandler.java
Outdated
Show resolved
Hide resolved
beekeeper-api/src/main/java/com/expediagroup/beekeeper/api/error/BeekeeperExceptionHandler.java
Outdated
Show resolved
Hide resolved
beekeeper-api/src/main/java/com/expediagroup/beekeeper/api/error/BeekeeperExceptionHandler.java
Outdated
Show resolved
Hide resolved
beekeeper-api/src/main/java/com/expediagroup/beekeeper/api/error/ErrorResponse.java
Outdated
Show resolved
Hide resolved
...ts/src/test/java/com/expediagroup/beekeeper/integration/api/BeekeeperApiIntegrationTest.java
Outdated
Show resolved
Hide resolved
Testing the request response and the errorResponses
…or/ErrorResponse.java Co-authored-by: Jay Green-Stevens <[email protected]>
…keeper/integration/api/BeekeeperApiIntegrationTest.java Co-authored-by: Jay Green-Stevens <[email protected]>
…or/BeekeeperExceptionHandler.java Co-authored-by: Jay Green-Stevens <[email protected]>
…or/BeekeeperExceptionHandler.java Co-authored-by: Jay Green-Stevens <[email protected]>
…or/BeekeeperExceptionHandler.java Co-authored-by: Jay Green-Stevens <[email protected]>
.timestamp(LocalDateTime.now().toString()) | ||
.status(HttpStatus.BAD_REQUEST.value()) | ||
.error(HttpStatus.BAD_REQUEST.getReasonPhrase()) | ||
.message("Invalid sort parameter: " + exception.getMessage()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be many things right doesn't always have to be invalid sort parameter. maybe we should just set the exception.message()?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, too specific.
I have updated to make it more general .message(exception.getMessage())
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice one!
Fixes #
/unreferenced-paths
endpoint for improved Swagger documentation.