diff --git a/src/main/java/org/opentripplanner/apis/gtfs/datafetchers/LegImpl.java b/src/main/java/org/opentripplanner/apis/gtfs/datafetchers/LegImpl.java index 9ec83a4bf67..fd37a221bdd 100644 --- a/src/main/java/org/opentripplanner/apis/gtfs/datafetchers/LegImpl.java +++ b/src/main/java/org/opentripplanner/apis/gtfs/datafetchers/LegImpl.java @@ -9,6 +9,8 @@ import org.opentripplanner.apis.gtfs.GraphQLRequestContext; import org.opentripplanner.apis.gtfs.generated.GraphQLDataFetchers; import org.opentripplanner.apis.gtfs.generated.GraphQLTypes; +import org.opentripplanner.apis.gtfs.generated.GraphQLTypes.GraphQLLegType; +import org.opentripplanner.apis.gtfs.mapping.LegTypeMapper; import org.opentripplanner.apis.gtfs.mapping.NumberMapper; import org.opentripplanner.ext.restapi.mapping.LocalDateMapper; import org.opentripplanner.ext.ridehailing.model.RideEstimate; @@ -262,6 +264,12 @@ public DataFetcher trip() { return environment -> getSource(environment).getTrip(); } + @Override + public DataFetcher type() { + return environment -> + LegTypeMapper.map(getSource(environment)); + } + @Override public DataFetcher walkingBike() { return environment -> getSource(environment).getWalkingBike(); diff --git a/src/main/java/org/opentripplanner/apis/gtfs/generated/GraphQLDataFetchers.java b/src/main/java/org/opentripplanner/apis/gtfs/generated/GraphQLDataFetchers.java index 67944543580..849f72359f7 100644 --- a/src/main/java/org/opentripplanner/apis/gtfs/generated/GraphQLDataFetchers.java +++ b/src/main/java/org/opentripplanner/apis/gtfs/generated/GraphQLDataFetchers.java @@ -524,6 +524,8 @@ public interface GraphQLLeg { public DataFetcher trip(); + public DataFetcher type(); + public DataFetcher walkingBike(); } diff --git a/src/main/java/org/opentripplanner/apis/gtfs/generated/GraphQLTypes.java b/src/main/java/org/opentripplanner/apis/gtfs/generated/GraphQLTypes.java index 67051444cdf..779da54f07c 100644 --- a/src/main/java/org/opentripplanner/apis/gtfs/generated/GraphQLTypes.java +++ b/src/main/java/org/opentripplanner/apis/gtfs/generated/GraphQLTypes.java @@ -1268,6 +1268,12 @@ public void setGraphQLOriginModesWithParentStation( } } + public enum GraphQLLegType { + FLEX, + SCHEDULED_TRANSIT, + STREET, + } + public static class GraphQLLocalDateRangeInput { private java.time.LocalDate end; diff --git a/src/main/java/org/opentripplanner/apis/gtfs/generated/graphql-codegen.yml b/src/main/java/org/opentripplanner/apis/gtfs/generated/graphql-codegen.yml index 29490a28b78..bede062cfdd 100644 --- a/src/main/java/org/opentripplanner/apis/gtfs/generated/graphql-codegen.yml +++ b/src/main/java/org/opentripplanner/apis/gtfs/generated/graphql-codegen.yml @@ -125,4 +125,5 @@ config: FareMedium: org.opentripplanner.model.fare.FareMedium#FareMedium RiderCategory: org.opentripplanner.model.fare.RiderCategory#RiderCategory StopPosition: org.opentripplanner.apis.gtfs.model.StopPosition#StopPosition + LegType: org.opentripplanner.apis.gtfs.generated.GraphQLTypes.GraphQLLegType diff --git a/src/main/java/org/opentripplanner/apis/gtfs/mapping/LegTypeMapper.java b/src/main/java/org/opentripplanner/apis/gtfs/mapping/LegTypeMapper.java new file mode 100644 index 00000000000..7e7ba16bb46 --- /dev/null +++ b/src/main/java/org/opentripplanner/apis/gtfs/mapping/LegTypeMapper.java @@ -0,0 +1,22 @@ +package org.opentripplanner.apis.gtfs.mapping; + +import javax.annotation.Nonnull; +import org.opentripplanner.apis.gtfs.generated.GraphQLTypes; +import org.opentripplanner.ext.flex.FlexibleTransitLeg; +import org.opentripplanner.model.plan.Leg; +import org.opentripplanner.model.plan.ScheduledTransitLeg; +import org.opentripplanner.model.plan.StreetLeg; + +public class LegTypeMapper { + + + @Nonnull + public static GraphQLTypes.GraphQLLegType map(Leg source) { + return switch (source) { + case StreetLeg ignored -> GraphQLTypes.GraphQLLegType.STREET; + case FlexibleTransitLeg ignored -> GraphQLTypes.GraphQLLegType.FLEX; + case ScheduledTransitLeg ignored -> GraphQLTypes.GraphQLLegType.SCHEDULED_TRANSIT; + default -> throw new IllegalStateException("Unhandled leg type: " + source); + }; + } +} diff --git a/src/main/resources/org/opentripplanner/apis/gtfs/schema.graphqls b/src/main/resources/org/opentripplanner/apis/gtfs/schema.graphqls index 927af19f8b1..4b56973784a 100644 --- a/src/main/resources/org/opentripplanner/apis/gtfs/schema.graphqls +++ b/src/main/resources/org/opentripplanner/apis/gtfs/schema.graphqls @@ -741,6 +741,8 @@ type Leg { transitLeg: Boolean "For transit legs, the trip that is used for traversing the leg. For non-transit legs, `null`." trip: Trip + "What the type of the leg is." + type: LegType! "Whether this leg is walking with a bike." walkingBike: Boolean } @@ -2886,6 +2888,18 @@ enum ItineraryFilterDebugProfile { OFF } +enum LegType { + """ + Leg is on a flexible trip that uses flexible time windows, areas or groups of stops. This may or may not be classed + as transit, depending the type of service. + """ + FLEX + "Leg is on a transit vehicle like bus, train or ferry which follows a published schedule, potentially with added real time information." + SCHEDULED_TRANSIT + "Leg traverses the street network, for example by walking to a stop, using a rental scooter or driving." + STREET +} + "Identifies whether this stop represents a stop or station." enum LocationType { ENTRANCE diff --git a/src/test/resources/org/opentripplanner/apis/gtfs/expectations/plan-extended.json b/src/test/resources/org/opentripplanner/apis/gtfs/expectations/plan-extended.json index ea58480be8e..d3e5b16392f 100644 --- a/src/test/resources/org/opentripplanner/apis/gtfs/expectations/plan-extended.json +++ b/src/test/resources/org/opentripplanner/apis/gtfs/expectations/plan-extended.json @@ -17,6 +17,7 @@ "walkTime" : 20, "legs" : [ { + "type" : "STREET", "mode" : "WALK", "start" : { "scheduledTime" : "2020-02-02T11:00:00Z", @@ -67,6 +68,7 @@ "accessibilityScore" : null }, { + "type" : "SCHEDULED_TRANSIT", "mode" : "BUS", "start" : { "scheduledTime" : "2020-02-02T10:51:00Z", @@ -157,6 +159,7 @@ "accessibilityScore" : null }, { + "type" : "SCHEDULED_TRANSIT", "mode" : "RAIL", "start" : { "scheduledTime" : "2020-02-02T11:20:00Z", @@ -267,6 +270,7 @@ "accessibilityScore" : null }, { + "type" : "STREET", "mode" : "CAR", "start" : { "scheduledTime" : "2020-02-02T11:50:00Z", diff --git a/src/test/resources/org/opentripplanner/apis/gtfs/queries/plan-extended.graphql b/src/test/resources/org/opentripplanner/apis/gtfs/queries/plan-extended.graphql index 76bf8aa84e0..54931aee84a 100644 --- a/src/test/resources/org/opentripplanner/apis/gtfs/queries/plan-extended.graphql +++ b/src/test/resources/org/opentripplanner/apis/gtfs/queries/plan-extended.graphql @@ -26,6 +26,7 @@ walkDistance walkTime legs { + type mode start { scheduledTime