Skip to content

Use generated Dart client for deflock-router API#121

Open
dougborg wants to merge 1 commit intoFoggedLens:mainfrom
dougborg:feat/use-generated-router-client
Open

Use generated Dart client for deflock-router API#121
dougborg wants to merge 1 commit intoFoggedLens:mainfrom
dougborg:feat/use-generated-router-client

Conversation

@dougborg
Copy link
Collaborator

Summary

  • Replace manual JSON construction and parsing in routing_service.dart with generated types from the deflock-router OpenAPI spec
  • Add deflock_router_client as a path dependency pointing to ../FlockHopper/packages/deflock_router_client

What changed in routing_service.dart

  • Request building: manual Map literals → router.DirectionsRequest, router.Coordinate, router.NodeProfile with .toJson()
  • Response parsing: manual data['result']['route'] map access → router.DirectionsResult.fromJson() + router.RouteGeometry fields
  • Same HTTP transport, timeout handling, and error handling preserved

Dependency

Requires flockhopperdev/FlockHopper#1 to be merged first (provides the generated Dart client package).

Test plan

  • flutter analyze — zero issues
  • flutter test — all 41 tests pass (including 5 routing service tests)
  • Request body shape unchanged (verified via test that captures serialized body)

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings February 18, 2026 16:27
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

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_client as a dependency (currently via a local path: reference).
  • Replace manual request Map building with router.DirectionsRequest / router.NodeProfile serialization.
  • 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
Copy link

Copilot AI Feb 18, 2026

Choose a reason for hiding this comment

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

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.

Suggested change
path: ../FlockHopper/packages/deflock_router_client
git:
url: https://github.com/FlockHopper/FlockHopper.git
path: packages/deflock_router_client
ref: main

Copilot uses AI. Check for mistakes.
Comment on lines +1 to +11
---
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
Copy link

Copilot AI Feb 18, 2026

Choose a reason for hiding this comment

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

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).

Suggested change
---
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."

Copilot uses AI. Check for mistakes.
Comment on lines +109 to +111
final waypoints = routeGeometry.coordinates.map((pair) {
return LatLng(pair[1], pair[0]); // [lon, lat] -> LatLng(lat, lon)
}).toList();
Copy link

Copilot AI Feb 18, 2026

Choose a reason for hiding this comment

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

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.

Suggested change
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)
}

Copilot uses AI. Check for mistakes.
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>
@dougborg dougborg force-pushed the feat/use-generated-router-client branch from fc00851 to a2cefb1 Compare February 25, 2026 17:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants