Use generated Dart client for deflock-router API#121
Use generated Dart client for deflock-router API#121dougborg wants to merge 1 commit intoFoggedLens:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR migrates RoutingService to use the generated deflock_router_client OpenAPI types for request/response serialization when calling the deflock-router (alprwatch) directions endpoint, and adds the client package as a dependency.
Changes:
- Add
deflock_router_clientas a dependency (currently via a localpath:reference). - Replace manual request
Mapbuilding withrouter.DirectionsRequest/router.NodeProfileserialization. - Replace manual response map parsing with
router.DirectionsResult.fromJson()and typed geometry access.
Reviewed changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| pubspec.yaml | Adds deflock_router_client dependency via a relative path. |
| pubspec.lock | Records the new path dependency resolution in the lockfile. |
| lib/services/routing_service.dart | Uses generated request/response models instead of manual JSON maps. |
| COMMENT | Adds an unreferenced text/code note file. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| csv: ^6.0.0 | ||
| collection: ^1.18.0 | ||
| deflock_router_client: | ||
| path: ../FlockHopper/packages/deflock_router_client |
There was a problem hiding this comment.
Using a path: dependency that points outside this repository will fail in CI/release workflows (they only actions/checkout this repo, then run flutter pub get). Consider switching to a git: dependency (pinned ref/tag) or updating the GitHub Actions workflows to also checkout FlockHopper into ../FlockHopper so flutter pub get can resolve this package.
| path: ../FlockHopper/packages/deflock_router_client | |
| git: | |
| url: https://github.com/FlockHopper/FlockHopper.git | |
| path: packages/deflock_router_client | |
| ref: main |
| --- | ||
| An alternative approach to addressing this issue could be adjusting the `optionsBuilder` logic to avoid returning any suggestions when the input text field is empty, rather than guarding `onFieldSubmitted`. For instance: | ||
|
|
||
| ```dart | ||
| optionsBuilder: (TextEditingValue textEditingValue) { | ||
| if (textEditingValue.text.isEmpty) return <String>[]; | ||
| return suggestions.where((s) => s.contains(textEditingValue.text)); | ||
| } | ||
| ``` | ||
|
|
||
| This ensures that the `RawAutocomplete` widget doesn't offer any options to auto-select on submission when the field is cleared, potentially simplifying the implementation and avoiding the need for additional boolean flags (`guardOnSubmitted`). This pattern can be seen in some implementations "in the wild." No newline at end of file |
There was a problem hiding this comment.
This file appears to be an unreferenced scratch note and will ship with the app/repo unless removed. If it’s not intentionally part of the product/docs, please delete it from the PR (or move the content into an appropriate issue/PR comment).
| --- | |
| An alternative approach to addressing this issue could be adjusting the `optionsBuilder` logic to avoid returning any suggestions when the input text field is empty, rather than guarding `onFieldSubmitted`. For instance: | |
| ```dart | |
| optionsBuilder: (TextEditingValue textEditingValue) { | |
| if (textEditingValue.text.isEmpty) return <String>[]; | |
| return suggestions.where((s) => s.contains(textEditingValue.text)); | |
| } | |
| ``` | |
| This ensures that the `RawAutocomplete` widget doesn't offer any options to auto-select on submission when the field is cleared, potentially simplifying the implementation and avoiding the need for additional boolean flags (`guardOnSubmitted`). This pattern can be seen in some implementations "in the wild." |
| final waypoints = routeGeometry.coordinates.map((pair) { | ||
| return LatLng(pair[1], pair[0]); // [lon, lat] -> LatLng(lat, lon) | ||
| }).toList(); |
There was a problem hiding this comment.
pair[1] / pair[0] assumes every coordinate entry has at least 2 elements. Previously malformed pairs were filtered out; now a short/invalid pair will throw (RangeError) and get wrapped as a misleading "Network error". Add validation (e.g., length check) and throw a RoutingException with a parse/invalid response message when coordinates are missing or malformed.
| final waypoints = routeGeometry.coordinates.map((pair) { | |
| return LatLng(pair[1], pair[0]); // [lon, lat] -> LatLng(lat, lon) | |
| }).toList(); | |
| final waypoints = <LatLng>[]; | |
| for (final pair in routeGeometry.coordinates) { | |
| if (pair is! List || pair.length < 2) { | |
| throw const RoutingException( | |
| 'Invalid routing response: coordinate pair is missing latitude/longitude'); | |
| } | |
| final lon = pair[0]; | |
| final lat = pair[1]; | |
| if (lon is! num || lat is! num) { | |
| throw const RoutingException( | |
| 'Invalid routing response: coordinate values are not numeric'); | |
| } | |
| waypoints.add(LatLng(lat.toDouble(), lon.toDouble())); // [lon, lat] -> LatLng(lat, lon) | |
| } |
Replace manual JSON construction and parsing in routing_service.dart with generated types (Coordinate, DirectionsRequest, RouteGeometry) from the OpenAPI spec. The deflock_router_client package lives in the FlockHopper repo alongside the canonical spec and TS client. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
fc00851 to
a2cefb1
Compare
Summary
routing_service.dartwith generated types from the deflock-router OpenAPI specdeflock_router_clientas a path dependency pointing to../FlockHopper/packages/deflock_router_clientWhat changed in routing_service.dart
Mapliterals →router.DirectionsRequest,router.Coordinate,router.NodeProfilewith.toJson()data['result']['route']map access →router.DirectionsResult.fromJson()+router.RouteGeometryfieldsDependency
Requires flockhopperdev/FlockHopper#1 to be merged first (provides the generated Dart client package).
Test plan
flutter analyze— zero issuesflutter test— all 41 tests pass (including 5 routing service tests)🤖 Generated with Claude Code