-
Notifications
You must be signed in to change notification settings - Fork 2
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
Add pagination to bugsnag and generic api controller #72
Conversation
Codecov Report
@@ Coverage Diff @@
## dev #72 +/- ##
============================================
+ Coverage 47.74% 48.02% +0.27%
- Complexity 325 329 +4
============================================
Files 81 82 +1
Lines 2260 2299 +39
Branches 256 256
============================================
+ Hits 1079 1104 +25
- Misses 1054 1070 +16
+ Partials 127 125 -2
Continue to review full report at Codecov.
|
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.
I will need to test some more. For now, the obvious changes are documenting the request parameters, and there is probably a way to request a subset of the data directly from Mongo and/or Bugsnag.
src/main/java/org/opentripplanner/middleware/controllers/api/ApiController.java
Show resolved
Hide resolved
src/main/java/org/opentripplanner/middleware/controllers/api/BugsnagController.java
Outdated
Show resolved
Hide resolved
src/main/java/org/opentripplanner/middleware/controllers/response/ResponseList.java
Outdated
Show resolved
Hide resolved
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.
Looks good so approving.
String route = HttpUtils.getRequiredQueryParamFromRequest(request, "route", false); | ||
String route = getQueryParamFromRequest(request, "route", false); |
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.
I think using static imports like this might actually be a bad practice. See this perspective here.
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.
What is your recommendation? That we qualify the method call with the util class? I'm fine with that, but we should define an approach for our projects generally on this. Perhaps we should create an issue and handle that in a separate project-wide PR?
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.
Let's discuss with the team together sometime and then if we decide we want to do this, then we can handle all the changes in another PR.
src/main/java/org/opentripplanner/middleware/utils/HttpUtils.java
Outdated
Show resolved
Hide resolved
src/main/java/org/opentripplanner/middleware/utils/HttpUtils.java
Outdated
Show resolved
Hide resolved
src/main/java/org/opentripplanner/middleware/controllers/response/ResponseList.java
Outdated
Show resolved
Hide resolved
responses: | ||
"200": | ||
description: "successful operation" | ||
schema: | ||
$ref: "#/definitions/AdminUser[]" | ||
$ref: "#/definitions/ResponseList" |
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.
I suppose this is a little better than the AdminUser[] type since the definition for that was just an empty object. It might be out of scope for this PR, but it would be nice to have the swagger docs include refs to the proper object in an array.
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.
@evansiroky Note that AdminUser
is a subclass of AbstractUser
, but spark-swagger ignores inherited fields at the time this was implemented. We insert inherited fields into the AdminUser
swagger type using the PublicApiDocGenerator
class.
data: | ||
type: "array" | ||
items: | ||
type: "string" |
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 is going to be incorrect since at the very least the items will be an object. It might be necessary to have separate ResponseList types that include the correct reference to the subclass that they return.
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.
@binh-dam-ibigroup, do you have any thoughts on how to ammend this swagger def?
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 most thorough way to handle this would be to change the document generator class to create a ResponseList_Subtype
object definition for each of the ResponseList
responses we are publishing. We can also try creating a separate descendant of ResponseBody
per @evansiroky's suggestion above and see how spark-swagger handles that.
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.
To follow up on my comment above, you could modify class PublicApiDocsGenerator
to do the following:
- Scan all
ResponseList
return entries in the autogenerated swagger. - For each instance, find the type of the elements in the list from one of the parent elements.
- Generate a custom return type definition that correspond to
ResponseList<type>
- Replace
ResponseList
with the custom type generated above.
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.
Further discussion should be had in #85
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.
See comments
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.
Some light documentation updates, then it should be good to go.
src/main/java/org/opentripplanner/middleware/controllers/api/BugsnagController.java
Outdated
Show resolved
Hide resolved
src/main/java/org/opentripplanner/middleware/controllers/api/ApiController.java
Outdated
Show resolved
Hide resolved
src/main/java/org/opentripplanner/middleware/controllers/api/TripHistoryController.java
Show resolved
Hide resolved
src/main/java/org/opentripplanner/middleware/persistence/TypedPersistence.java
Outdated
Show resolved
Hide resolved
responses: | ||
"200": | ||
description: "successful operation" | ||
schema: | ||
$ref: "#/definitions/AdminUser[]" | ||
$ref: "#/definitions/ResponseList" |
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.
@evansiroky Note that AdminUser
is a subclass of AbstractUser
, but spark-swagger ignores inherited fields at the time this was implemented. We insert inherited fields into the AdminUser
swagger type using the PublicApiDocGenerator
class.
src/main/java/org/opentripplanner/middleware/controllers/api/TripHistoryController.java
Show resolved
Hide resolved
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.
- Build is failing
- PR has merge conflicts
- Figuring out documentation of ResponseList typing seems to be unresolved
Does a dependency need to be updated for the build to pass? |
Codecov Report
@@ Coverage Diff @@
## dev #72 +/- ##
============================================
+ Coverage 47.74% 48.11% +0.36%
- Complexity 325 329 +4
============================================
Files 81 82 +1
Lines 2260 2305 +45
Branches 256 256
============================================
+ Hits 1079 1109 +30
- Misses 1054 1071 +17
+ Partials 127 125 -2
Continue to review full report at Codecov.
|
Checklist
dev
before they can be merged tomaster
)Description
Adds pagination to bugsnag (our dev instance currently returns thousands of records) and the generic API controller. otp-admin-ui PR is ibi-group/otp-admin-ui#23 (still need changes in otp-react-redux)