-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add validation to the serviceJourney Transmodel API endpoint #6559
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
base: dev-2.x
Are you sure you want to change the base?
Changes from 2 commits
3a60232
00e4dc4
36fec83
45193a1
3a04547
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -108,4 +108,15 @@ public static <T> List<T> toList(@Nullable Collection<T> args) { | |||
} | ||||
return args.stream().filter(Objects::nonNull).toList(); | ||||
} | ||||
|
||||
/** | ||||
* Null-safe handling of a collection of strings. Returns null if the incoming collection is null. | ||||
* Null and empty elements are filtered out. | ||||
*/ | ||||
public static List<String> toStringList(@Nullable Collection<String> args) { | ||||
eibakke marked this conversation as resolved.
Show resolved
Hide resolved
|
||||
if (args == null) { | ||||
return null; | ||||
} | ||||
return args.stream().filter(Objects::nonNull).filter(s -> !s.isEmpty()).toList(); | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think in general it's best to be strict and not have special handling for empty strings and other edge cases. Cleaning user data hides bugs in the clients where they should be fixed. If a user says they want the service journeys with private codes What do you think about that? The null filtering is fine though, we probably need this since we for some reason allowed the elements to be null. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the opposite of what @vpaturet expressed in #6545 (comment) I tend to agree with Vincent here, that empty strings should be ignored ie. treated the same as nulls. This also matches how the mapIDsToDomain method handles empty (or even blank strings), using OpenTripPlanner/utils/src/main/java/org/opentripplanner/utils/lang/StringUtils.java Line 25 in e8e9a77
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry for the slow response here! I must say that I disagree with treating empty strings as nulls. If we need to do it for backwards compatability I can see the point, but in this case it looks like we are making the api less strict than previously. The stricter we make the api and the less special cases we add the easier it will be to maintain. We had a short discussion around this on the developer meeting two weeks ago, and I think the consensus was to avoid special handling for empty strings unless it's needed for compatability reasons. |
||||
} | ||||
} |
Uh oh!
There was an error while loading. Please reload this page.