From fc4d01d33fdac6fdab7ca9c0db4fb82d599f82f0 Mon Sep 17 00:00:00 2001 From: Ian Wagner Date: Wed, 4 Sep 2024 02:34:28 +0900 Subject: [PATCH 1/7] Add a bunch of missing descriptions, models, and requirements --- openapi.yaml | 288 +++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 257 insertions(+), 31 deletions(-) diff --git a/openapi.yaml b/openapi.yaml index 981593c..1d5fbbb 100644 --- a/openapi.yaml +++ b/openapi.yaml @@ -103,40 +103,58 @@ components: $ref: '#/components/schemas/Route' Route: type: object + required: + - distance + - duration + - geometry + - legs properties: distance: type: number format: double - description: The distance traveled by the route, in double meters. + description: The distance traveled by the route, in meters. duration: type: number format: double - description: The estimated travel time, in double number of seconds. - geometry: - type: object + description: The estimated travel time, in number of seconds. + geometry: # FIXME + type: string + description: >- + An encoded polyline (https://developers.google.com/maps/documentation/utilities/polylinealgorithm). weight: type: number format: double + description: >- + The total cost of the route computed by the routing engine. + This is a Valhalla extension to the OSRM spec. weight_name: type: string + description: The costing model used for the route. This is an extension from Valhalla-based routers. legs: type: array items: $ref: '#/components/schemas/RouteLeg' RouteLeg: type: object + required: + - distance + - duration + - steps properties: distance: type: number format: double - description: The distance traveled by the route, in double meters. + description: The distance traveled by the route, in meters. duration: type: number format: double - description: The estimated travel time, in double number of seconds. + description: The estimated travel time, in number of seconds. weight: type: number format: double + description: >- + The total cost of the leg computed by the routing engine. + This is a Valhalla extension to the OSRM spec. summary: type: string steps: @@ -148,21 +166,30 @@ components: via_waypoints: type: array nullable: true - default: null - description: A Mapbox and Valhalla extension which indicates which waypoints are passed through rather than creating a new leg. + description: >- + Indicates which waypoints are passed through rather than creating a new leg. + This is a Valhalla extension to the OSRM spec. items: $ref: '#/components/schemas/ViaWaypoint' RouteStep: type: object + description: >- + A maneuver such as a turn or merge, followed by travel along a single road or path. + required: + - distance + - duration + - geometry + - mode + - maneuver properties: distance: type: number format: double - description: The distance traveled by the route, in double meters. + description: The distance traveled by the route, in meters. duration: type: number format: double - description: The estimated travel time, in double number of seconds. + description: The estimated travel time, in number of seconds. geometry: type: object weight: @@ -170,16 +197,22 @@ components: format: double name: type: string + description: "The name of the segment (ex: road) being traversed" ref: type: string + description: A reference number of code for the segment being traversed. pronunciation: type: string + description: >- + Pronunciation of the name (if available). + The format of this varies by implementation/vendor. destinations: type: object exits: type: object mode: type: string + description: The mode of travel. maneuver: $ref: '#/components/schemas/StepManeuver' intersections: @@ -188,21 +221,32 @@ components: $ref: '#/components/schemas/Intersection' rotary_name: type: string + description: The name of the traffic circle. rotary_pronunciation: type: string + description: >- + Pronunciation of the rotary name (if available). + The format of this varies by implementation/vendor. driving_side: type: string enum: - left - right + description: The side of the road on which driving is legal for this step. voiceInstructions: type: array items: $ref: '#/components/schemas/VoiceInstruction' + description: >- + A list of announcements which should be spoken at various points along the maneuver. + This is a Valhalla extension to the OSRM spec. bannerInstructions: type: array items: $ref: '#/components/schemas/BannerInstruction' + description: >- + A list of announcements which should be displayed prominently on screen at various points along the maneuver. + This is a Valhalla extension to the OSRM spec. Annotation: type: object properties: @@ -211,21 +255,29 @@ components: items: type: number format: double - description: The distance, in metres, between each pair of coordinates + description: The distance, in meters, between each pair of coordinates. duration: type: array items: type: number format: double - description: The duration between each pair of coordinates, in seconds + description: The duration between each pair of coordinates, in seconds. datasources: type: array items: type: integer + description: >- + The index of the datasource for the speed between each pair of coordinates. + 0 is the default profile. + Other values are supplied via --segment-speed-file to osrm-contract. + This is OSRM-specific and not supported by most other routers. nodes: type: array items: type: integer + description: >- + The OSM node ID for each coordinate along the route (excluding the first/last user-supplied coordinates). + This is not included in Valhalla-derived routers. weight: type: array items: @@ -235,59 +287,160 @@ components: items: type: number format: double - metadata: - type: object - properties: - datasource_names: - type: array - items: + description: >- + The estimated speed of travel between each pair of coordinates in meters/sec. + maxspeed: + type: array + items: + type: object + properties: + speed: + type: integer + unit: type: string + enum: + - km/h + - mph + description: >- + The unit of measure for the speed. + Always included if speed is present. + unknown: + type: boolean + description: True if the speed limit is not known. + none: + type: boolean + description: "True if there is no explicit speed limit (ex: some Autobahn sections)" + description: >- + The speed limit between the pair of coordinates. + Available in Valhalla-derived routers. StepManeuver: type: object + required: + - location + - bearing_before + - bearing_after + - type properties: location: - type: array - items: - type: number - format: double + $ref: '#/components/schemas/Coordinate' + instruction: + type: string + description: >- + A human-readable instruction for the maneuver. + This is a Valhalla extension to the OSRM spec. bearing_before: type: integer + description: >- + The clockwise angle from true north to the direction of travel immediately before the maneuver. bearing_after: type: integer + description: >- + The clockwise angle from true north to the direction of travel immediately after the maneuver. type: type: string + enum: + - turn + - new name + - depart + - arrive + - merge + - ramp + - on ramp + - off ramp + - fork + - end of road + - use lane + - continue + - roundabout + - rotary + - roundabout turn + - notification modifier: type: string + enum: + - uturn + - sharp right + - slight right + - straight + - slight left + - left + - sharp left + description: >- + An optional value indicating the directional change of the maneuver + (further clarifying type). exit: type: integer + description: The exit number to take (for roundabouts, rotaries, and number of intersections). Intersection: type: object + description: >- + Detailed information about intersections that the route traverses. + For every step, the first intersection is at the location of the maneuver. + Additional intersections will be provided for every road or path traversed + until the next step. properties: location: - type: array - items: - type: number - format: double + $ref: '#/components/schemas/Coordinate' bearings: type: array items: type: integer + description: >- + A list of bearing values that are available for travel through the intersection. classes: type: array items: type: string + enum: + - toll + - ferry + - restricted + - motorway + - tunnel + description: The classes of roads exiting the intersection. entry: type: array items: type: boolean + description: >- + A list of entry flags, which map 1:1 to the bearings. + A value of true indicates that the respective road could be entered on a valid route. + False indicates that the turn onto the respective road would violate a restriction. in: type: integer + description: >- + An index into bearings/entry array. + Used to calculate the bearing just before the turn. + Namely, the clockwise angle from true north to the direction of travel + immediately before the maneuver/passing the intersection. + Bearings are given relative to the intersection. + To get the bearing in the direction of driving, the bearing has to be rotated by a value of 180. + The value is not supplied for depart maneuvers. out: type: integer + description: >- + An index into bearings/entry array. + Used to calculate the bearing just after the turn. + Namely, the clockwise angle from true north to the direction of travel + immediately after the maneuver/passing the intersection. + This is not supplied for arrive maneuvers. lanes: type: array items: $ref: '#/components/schemas/Lane' + description: >- + Available turn lanes at the intersection. + May be omitted if no lane information is available for the intersection. + admin_index: + type: integer + description: >- + The index into the admin boundaries list on the route leg. + This is an extension that is not available on OSRM and may not be present on all Mapbox responses. + duration: + type: integer + description: >- + The estimated duration, in seconds, to traverse the intersection. + This is a Valhalla extension to the OSRM spec. VoiceInstruction: type: object required: @@ -297,10 +450,15 @@ components: distanceAlongGeometry: type: number format: double + description: How far (in meters) from the upcoming maneuver the instruction should be announced. announcement: type: string + description: The plain-text announcement. ssmlAnnouncement: type: string + description: >- + The announcement in Speech Synthesis Markup Language (SSML). + Supported TTS engines include Amazon Polly and Apple's AVSpeechSynthesizer. BannerInstruction: type: object required: @@ -310,6 +468,7 @@ components: distanceAlongGeometry: type: number format: double + description: How far (in meters) from the upcoming maneuver the instruction should start being displayed. primary: $ref: '#/components/schemas/BannerContent' secondary: @@ -323,8 +482,33 @@ components: type: string type: type: string + enum: + - turn + - new name + - depart + - arrive + - merge + - on ramp + - off ramp + - fork + - end of road + - continue + - roundabout + - rotary + - roundabout turn + - notification + - exit roundabout + - exit rotary modifier: type: string + enum: + - uturn + - sharp right + - right + - slight right + - slight left + - left + - sharp left components: type: array items: @@ -334,6 +518,16 @@ components: type: string type: type: string + enum: + - text + - icon + - delimiter + - exit-number + - exit + - lane + description: >- + A list of objects with additional context that allow for visual layout improvements + beyond what's possible with plain text. Lane: type: object properties: @@ -341,33 +535,58 @@ components: type: array items: type: string + enum: + - none + - uturn + - sharp right + - right + - slight right + - straight + - slight left + - left + - sharp left + description: >- + A list of indication (e.g. marking on the road) specifying the turn lane. + A road can have multiple indications (e.g. an arrow pointing straight and left). valid: type: boolean + description: True if the lane is a valid choice for the current maneuver. + required: + - indications + - valid Waypoint: type: object properties: name: type: string location: - type: array - items: - type: number - format: double + $ref: '#/components/schemas/Coordinate' distance: type: number format: double + description: The distance of the snapped point from the original location. hint: type: string + required: + - location + - distance ViaWaypoint: type: object properties: distance_from_start: type: number format: double + description: The distance from the start of the leg, in meters. geometry_index: type: integer + description: The index of the waypoint's location in the route geometry. waypoint_index: type: integer + description: The index of the associated waypoint. + required: + - distance_from_start + - geometry_index + - waypoint_index NearestWaypoint: allOf: - $ref: '#/components/schemas/Waypoint' @@ -386,4 +605,11 @@ components: type: integer waypoint_index: type: integer - + Coordinate: + type: array + items: + type: number + format: double + minItems: 2 + maxItems: 2 + description: A (longitude, latitude) coordinate pair. \ No newline at end of file From 3a02e0c8b8ee5b51a84682f9540ff4e69403c297 Mon Sep 17 00:00:00 2001 From: Ian Wagner Date: Wed, 4 Sep 2024 03:10:09 +0900 Subject: [PATCH 2/7] Fix spec and test errors --- android/src/test/kotlin/TestModel.kt | 8 ++++---- openapi.yaml | 4 +++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/android/src/test/kotlin/TestModel.kt b/android/src/test/kotlin/TestModel.kt index ac41184..ed0eca6 100644 --- a/android/src/test/kotlin/TestModel.kt +++ b/android/src/test/kotlin/TestModel.kt @@ -13,7 +13,7 @@ class ModelTest { @Test fun testWaypoint() { - val waypoint = Waypoint("name", listOf(1.0, 2.0)) + val waypoint = Waypoint(listOf(1.0, 2.0), 42.0,"name") assertEquals("name", waypoint.name) assertEquals(listOf(1.0, 2.0), waypoint.location) } @@ -28,10 +28,10 @@ class ModelTest { val route = response?.routes?.first() ?: fail("response must have at least one route") - assertEquals(1, route.legs?.size) - assertEquals(4, route.legs?.first()?.steps?.size) + assertEquals(1, route.legs.size) + assertEquals(4, route.legs.first().steps.size) - val step = route.legs?.first()?.steps?.first() ?: fail("route leg must have at least one step") + val step = route.legs.first().steps.first() assertEquals("State Highway 65", step.name) assertEquals("tezuoAezllgIfhAdStpAzV`hAxQlxA|X|i@vIdQpCnxClh@laCjd@dRdDr}@zOxgApR`pBf^jk@hKvmAnUfJ|AdDj@tCR", step.geometry) diff --git a/openapi.yaml b/openapi.yaml index 1d5fbbb..82c4125 100644 --- a/openapi.yaml +++ b/openapi.yaml @@ -360,6 +360,7 @@ components: enum: - uturn - sharp right + - right - slight right - straight - slight left @@ -437,7 +438,8 @@ components: The index into the admin boundaries list on the route leg. This is an extension that is not available on OSRM and may not be present on all Mapbox responses. duration: - type: integer + type: number + format: double description: >- The estimated duration, in seconds, to traverse the intersection. This is a Valhalla extension to the OSRM spec. From 2ed4c109e657307f4832617d8152fcd8be08f0f7 Mon Sep 17 00:00:00 2001 From: Ian Wagner Date: Wed, 4 Sep 2024 03:10:52 +0900 Subject: [PATCH 3/7] Mark TODs --- openapi.yaml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/openapi.yaml b/openapi.yaml index 82c4125..eb2d193 100644 --- a/openapi.yaml +++ b/openapi.yaml @@ -171,6 +171,7 @@ components: This is a Valhalla extension to the OSRM spec. items: $ref: '#/components/schemas/ViaWaypoint' + # TODO: admins RouteStep: type: object description: >- @@ -191,7 +192,7 @@ components: format: double description: The estimated travel time, in number of seconds. geometry: - type: object + type: object # FIXME weight: type: number format: double @@ -207,8 +208,10 @@ components: Pronunciation of the name (if available). The format of this varies by implementation/vendor. destinations: + # FIXME type: object exits: + # FIXME type: object mode: type: string @@ -250,6 +253,7 @@ components: Annotation: type: object properties: + # TODO: Refactor into properties? distance: type: array items: From c8d31907d1a6bfc2a6ed4e35b6bed4b068c42f3f Mon Sep 17 00:00:00 2001 From: Ian Wagner Date: Wed, 4 Sep 2024 13:48:53 +0900 Subject: [PATCH 4/7] More fixes; generate swift models --- apple/Sources/OSRM/Models/Admin.swift | 36 ++++ apple/Sources/OSRM/Models/Annotation.swift | 25 +-- .../Sources/OSRM/Models/BannerComponent.swift | 43 +++++ apple/Sources/OSRM/Models/BannerContent.swift | 28 ++- .../OSRM/Models/BannerInstruction.swift | 1 + .../OSRM/Models/GuidanceModifier.swift | 23 +++ apple/Sources/OSRM/Models/Intersection.swift | 49 +++++- apple/Sources/OSRM/Models/Lane.swift | 24 ++- .../Sources/OSRM/Models/NearestWaypoint.swift | 13 +- apple/Sources/OSRM/Models/Route.swift | 25 +-- apple/Sources/OSRM/Models/RouteLeg.swift | 26 +-- apple/Sources/OSRM/Models/RouteStep.swift | 51 ++++-- apple/Sources/OSRM/Models/SpeedLimit.swift | 51 ++++++ apple/Sources/OSRM/Models/StepManeuver.swift | 49 ++++-- apple/Sources/OSRM/Models/TripWaypoint.swift | 13 +- apple/Sources/OSRM/Models/ViaWaypoint.swift | 17 +- .../OSRM/Models/VoiceInstruction.swift | 3 + apple/Sources/OSRM/Models/Waypoint.swift | 13 +- openapi.yaml | 166 +++++++++++------- 19 files changed, 509 insertions(+), 147 deletions(-) create mode 100644 apple/Sources/OSRM/Models/Admin.swift create mode 100644 apple/Sources/OSRM/Models/BannerComponent.swift create mode 100644 apple/Sources/OSRM/Models/GuidanceModifier.swift create mode 100644 apple/Sources/OSRM/Models/SpeedLimit.swift diff --git a/apple/Sources/OSRM/Models/Admin.swift b/apple/Sources/OSRM/Models/Admin.swift new file mode 100644 index 0000000..5fa58bf --- /dev/null +++ b/apple/Sources/OSRM/Models/Admin.swift @@ -0,0 +1,36 @@ +// +// Admin.swift +// +// Generated by openapi-generator +// https://openapi-generator.tech +// + +import Foundation +#if canImport(AnyCodable) + import AnyCodable +#endif + +public struct Admin: Codable, Hashable { + /** The ISO 3166-1 two-character code for the admin region. */ + public var iso31661: String? + /** The ISO 3166-1 three-character code for the admin region. */ + public var iso31661Alpha3: String? + + public init(iso31661: String? = nil, iso31661Alpha3: String? = nil) { + self.iso31661 = iso31661 + self.iso31661Alpha3 = iso31661Alpha3 + } + + public enum CodingKeys: String, CodingKey, CaseIterable { + case iso31661 = "iso_3166_1" + case iso31661Alpha3 = "iso_3166_1_alpha3" + } + + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encodeIfPresent(iso31661, forKey: .iso31661) + try container.encodeIfPresent(iso31661Alpha3, forKey: .iso31661Alpha3) + } +} diff --git a/apple/Sources/OSRM/Models/Annotation.swift b/apple/Sources/OSRM/Models/Annotation.swift index 5401603..e371843 100644 --- a/apple/Sources/OSRM/Models/Annotation.swift +++ b/apple/Sources/OSRM/Models/Annotation.swift @@ -11,24 +11,27 @@ import Foundation #endif public struct Annotation: Codable, Hashable { - /** The distance, in metres, between each pair of coordinates */ - public var distance: [Double]? - /** The duration between each pair of coordinates, in seconds */ - public var duration: [Double]? + /** The distance, in meters, between each pair of coordinates. */ + public var distance: [Double] + /** The duration between each pair of coordinates, in seconds. */ + public var duration: [Double] + /** The index of the datasource for the speed between each pair of coordinates. 0 is the default profile. Other values are supplied via --segment-speed-file to osrm-contract. This is OSRM-specific and not supported by most other routers. */ public var datasources: [Int]? + /** The OSM node ID for each coordinate along the route (excluding the first/last user-supplied coordinates). This is not included in Valhalla-derived routers. */ public var nodes: [Int]? public var weight: [Int]? + /** The estimated speed of travel between each pair of coordinates in meters/sec. */ public var speed: [Double]? - public var metadata: AnnotationMetadata? + public var maxspeed: [SpeedLimit]? - public init(distance: [Double]? = nil, duration: [Double]? = nil, datasources: [Int]? = nil, nodes: [Int]? = nil, weight: [Int]? = nil, speed: [Double]? = nil, metadata: AnnotationMetadata? = nil) { + public init(distance: [Double], duration: [Double], datasources: [Int]? = nil, nodes: [Int]? = nil, weight: [Int]? = nil, speed: [Double]? = nil, maxspeed: [SpeedLimit]? = nil) { self.distance = distance self.duration = duration self.datasources = datasources self.nodes = nodes self.weight = weight self.speed = speed - self.metadata = metadata + self.maxspeed = maxspeed } public enum CodingKeys: String, CodingKey, CaseIterable { @@ -38,19 +41,19 @@ public struct Annotation: Codable, Hashable { case nodes case weight case speed - case metadata + case maxspeed } // Encodable protocol methods public func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(distance, forKey: .distance) - try container.encodeIfPresent(duration, forKey: .duration) + try container.encode(distance, forKey: .distance) + try container.encode(duration, forKey: .duration) try container.encodeIfPresent(datasources, forKey: .datasources) try container.encodeIfPresent(nodes, forKey: .nodes) try container.encodeIfPresent(weight, forKey: .weight) try container.encodeIfPresent(speed, forKey: .speed) - try container.encodeIfPresent(metadata, forKey: .metadata) + try container.encodeIfPresent(maxspeed, forKey: .maxspeed) } } diff --git a/apple/Sources/OSRM/Models/BannerComponent.swift b/apple/Sources/OSRM/Models/BannerComponent.swift new file mode 100644 index 0000000..d627853 --- /dev/null +++ b/apple/Sources/OSRM/Models/BannerComponent.swift @@ -0,0 +1,43 @@ +// +// BannerComponent.swift +// +// Generated by openapi-generator +// https://openapi-generator.tech +// + +import Foundation +#if canImport(AnyCodable) + import AnyCodable +#endif + +public struct BannerComponent: Codable, Hashable { + public enum ModelType: String, Codable, CaseIterable { + case text + case icon + case delimiter + case exitNumber = "exit-number" + case exit + case lane + } + + public var text: String? + public var type: ModelType? + + public init(text: String? = nil, type: ModelType? = nil) { + self.text = text + self.type = type + } + + public enum CodingKeys: String, CodingKey, CaseIterable { + case text + case type + } + + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encodeIfPresent(text, forKey: .text) + try container.encodeIfPresent(type, forKey: .type) + } +} diff --git a/apple/Sources/OSRM/Models/BannerContent.swift b/apple/Sources/OSRM/Models/BannerContent.swift index 9ad4a25..0452c3a 100644 --- a/apple/Sources/OSRM/Models/BannerContent.swift +++ b/apple/Sources/OSRM/Models/BannerContent.swift @@ -11,12 +11,32 @@ import Foundation #endif public struct BannerContent: Codable, Hashable { + public enum ModelType: String, Codable, CaseIterable { + case turn + case newName = "new name" + case depart + case arrive + case merge + case onRamp = "on ramp" + case offRamp = "off ramp" + case fork + case endOfRoad = "end of road" + case _continue = "continue" + case roundabout + case rotary + case roundaboutTurn = "roundabout turn" + case notification + case exitRoundabout = "exit roundabout" + case exitRotary = "exit rotary" + } + public var text: String - public var type: String? - public var modifier: String? - public var components: [BannerContentComponentsInner]? + public var type: ModelType? + public var modifier: GuidanceModifier? + /** A list of objects with additional context that allow for visual layout improvements beyond what's possible with plain text. */ + public var components: [BannerComponent]? - public init(text: String, type: String? = nil, modifier: String? = nil, components: [BannerContentComponentsInner]? = nil) { + public init(text: String, type: ModelType? = nil, modifier: GuidanceModifier? = nil, components: [BannerComponent]? = nil) { self.text = text self.type = type self.modifier = modifier diff --git a/apple/Sources/OSRM/Models/BannerInstruction.swift b/apple/Sources/OSRM/Models/BannerInstruction.swift index f1aa0c1..da79d3f 100644 --- a/apple/Sources/OSRM/Models/BannerInstruction.swift +++ b/apple/Sources/OSRM/Models/BannerInstruction.swift @@ -11,6 +11,7 @@ import Foundation #endif public struct BannerInstruction: Codable, Hashable { + /** How far (in meters) from the upcoming maneuver the instruction should start being displayed. */ public var distanceAlongGeometry: Double public var primary: BannerContent public var secondary: BannerContent? diff --git a/apple/Sources/OSRM/Models/GuidanceModifier.swift b/apple/Sources/OSRM/Models/GuidanceModifier.swift new file mode 100644 index 0000000..a33b389 --- /dev/null +++ b/apple/Sources/OSRM/Models/GuidanceModifier.swift @@ -0,0 +1,23 @@ +// +// GuidanceModifier.swift +// +// Generated by openapi-generator +// https://openapi-generator.tech +// + +import Foundation +#if canImport(AnyCodable) + import AnyCodable +#endif + +/** An optional value indicating the directional change of the maneuver (further clarifying type). */ +public enum GuidanceModifier: String, Codable, CaseIterable { + case uturn + case sharpRight = "sharp right" + case _right = "right" + case slightRight = "slight right" + case straight + case slightLeft = "slight left" + case _left = "left" + case sharpLeft = "sharp left" +} diff --git a/apple/Sources/OSRM/Models/Intersection.swift b/apple/Sources/OSRM/Models/Intersection.swift index c538717..b7e61d8 100644 --- a/apple/Sources/OSRM/Models/Intersection.swift +++ b/apple/Sources/OSRM/Models/Intersection.swift @@ -10,16 +10,43 @@ import Foundation import AnyCodable #endif +/** Detailed information about intersections that the route traverses. For every step, the first intersection is at the location of the maneuver. Additional intersections will be provided for every road or path traversed until the next step. */ public struct Intersection: Codable, Hashable { + public enum Classes: String, Codable, CaseIterable { + case toll + case ferry + case restricted + case motorway + case tunnel + } + + static let locationRule = ArrayRule(minItems: 2, maxItems: 2, uniqueItems: false) + /** A (longitude, latitude) coordinate pair. */ public var location: [Double]? + /** A list of bearing values that are available for travel through the intersection. */ public var bearings: [Int]? - public var classes: [String]? + /** The classes of roads exiting the intersection. */ + public var classes: [Classes]? + /** A list of entry flags, which map 1:1 to the bearings. A value of true indicates that the respective road could be entered on a valid route. False indicates that the turn onto the respective road would violate a restriction. */ public var entry: [Bool]? + /** An index into bearings/entry array. Used to calculate the bearing just before the turn. Namely, the clockwise angle from true north to the direction of travel immediately before the maneuver/passing the intersection. Bearings are given relative to the intersection. To get the bearing in the direction of driving, the bearing has to be rotated by a value of 180. The value is not supplied for depart maneuvers. */ public var _in: Int? + /** An index into bearings/entry array. Used to calculate the bearing just after the turn. Namely, the clockwise angle from true north to the direction of travel immediately after the maneuver/passing the intersection. This is not supplied for arrive maneuvers. */ public var out: Int? + /** Available turn lanes at the intersection. May be omitted if no lane information is available for the intersection. */ public var lanes: [Lane]? + /** The index into the admin boundaries list on the route leg. This is an extension that is not available on OSRM and may not be present on all Mapbox responses. */ + public var adminIndex: Int? + /** The estimated duration, in seconds, to traverse the intersection. This is a Valhalla extension to the OSRM spec. */ + public var duration: Double? + /** The estimated duration, in seconds, to complete a turn. This is a Valhalla extension to the OSRM spec. */ + public var turnDuration: Double? + public var turnWeight: Double? + /** The index of the intersection in the leg geometry. This is a Valhalla extension to the OSRM spec. */ + public var geometryIndex: Int? + public var weight: Double? - public init(location: [Double]? = nil, bearings: [Int]? = nil, classes: [String]? = nil, entry: [Bool]? = nil, _in: Int? = nil, out: Int? = nil, lanes: [Lane]? = nil) { + public init(location: [Double]? = nil, bearings: [Int]? = nil, classes: [Classes]? = nil, entry: [Bool]? = nil, _in: Int? = nil, out: Int? = nil, lanes: [Lane]? = nil, adminIndex: Int? = nil, duration: Double? = nil, turnDuration: Double? = nil, turnWeight: Double? = nil, geometryIndex: Int? = nil, weight: Double? = nil) { self.location = location self.bearings = bearings self.classes = classes @@ -27,6 +54,12 @@ public struct Intersection: Codable, Hashable { self._in = _in self.out = out self.lanes = lanes + self.adminIndex = adminIndex + self.duration = duration + self.turnDuration = turnDuration + self.turnWeight = turnWeight + self.geometryIndex = geometryIndex + self.weight = weight } public enum CodingKeys: String, CodingKey, CaseIterable { @@ -37,6 +70,12 @@ public struct Intersection: Codable, Hashable { case _in = "in" case out case lanes + case adminIndex = "admin_index" + case duration + case turnDuration = "turn_duration" + case turnWeight = "turn_weight" + case geometryIndex = "geometry_index" + case weight } // Encodable protocol methods @@ -50,5 +89,11 @@ public struct Intersection: Codable, Hashable { try container.encodeIfPresent(_in, forKey: ._in) try container.encodeIfPresent(out, forKey: .out) try container.encodeIfPresent(lanes, forKey: .lanes) + try container.encodeIfPresent(adminIndex, forKey: .adminIndex) + try container.encodeIfPresent(duration, forKey: .duration) + try container.encodeIfPresent(turnDuration, forKey: .turnDuration) + try container.encodeIfPresent(turnWeight, forKey: .turnWeight) + try container.encodeIfPresent(geometryIndex, forKey: .geometryIndex) + try container.encodeIfPresent(weight, forKey: .weight) } } diff --git a/apple/Sources/OSRM/Models/Lane.swift b/apple/Sources/OSRM/Models/Lane.swift index 2e63538..fdedc2d 100644 --- a/apple/Sources/OSRM/Models/Lane.swift +++ b/apple/Sources/OSRM/Models/Lane.swift @@ -11,10 +11,24 @@ import Foundation #endif public struct Lane: Codable, Hashable { - public var indications: [String]? - public var valid: Bool? + public enum Indications: String, Codable, CaseIterable { + case _none = "none" + case uturn + case sharpRight = "sharp right" + case _right = "right" + case slightRight = "slight right" + case straight + case slightLeft = "slight left" + case _left = "left" + case sharpLeft = "sharp left" + } + + /** A list of indication (e.g. marking on the road) specifying the turn lane. A road can have multiple indications (e.g. an arrow pointing straight and left). */ + public var indications: [Indications] + /** True if the lane is a valid choice for the current maneuver. */ + public var valid: Bool - public init(indications: [String]? = nil, valid: Bool? = nil) { + public init(indications: [Indications], valid: Bool) { self.indications = indications self.valid = valid } @@ -28,7 +42,7 @@ public struct Lane: Codable, Hashable { public func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(indications, forKey: .indications) - try container.encodeIfPresent(valid, forKey: .valid) + try container.encode(indications, forKey: .indications) + try container.encode(valid, forKey: .valid) } } diff --git a/apple/Sources/OSRM/Models/NearestWaypoint.swift b/apple/Sources/OSRM/Models/NearestWaypoint.swift index 8a8c5db..0d4446d 100644 --- a/apple/Sources/OSRM/Models/NearestWaypoint.swift +++ b/apple/Sources/OSRM/Models/NearestWaypoint.swift @@ -11,13 +11,16 @@ import Foundation #endif public struct NearestWaypoint: Codable, Hashable { + static let locationRule = ArrayRule(minItems: 2, maxItems: 2, uniqueItems: false) public var name: String? - public var location: [Double]? - public var distance: Double? + /** A (longitude, latitude) coordinate pair. */ + public var location: [Double] + /** The distance of the snapped point from the original location. */ + public var distance: Double public var hint: String? public var nodes: [Int]? - public init(name: String? = nil, location: [Double]? = nil, distance: Double? = nil, hint: String? = nil, nodes: [Int]? = nil) { + public init(name: String? = nil, location: [Double], distance: Double, hint: String? = nil, nodes: [Int]? = nil) { self.name = name self.location = location self.distance = distance @@ -38,8 +41,8 @@ public struct NearestWaypoint: Codable, Hashable { public func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) try container.encodeIfPresent(name, forKey: .name) - try container.encodeIfPresent(location, forKey: .location) - try container.encodeIfPresent(distance, forKey: .distance) + try container.encode(location, forKey: .location) + try container.encode(distance, forKey: .distance) try container.encodeIfPresent(hint, forKey: .hint) try container.encodeIfPresent(nodes, forKey: .nodes) } diff --git a/apple/Sources/OSRM/Models/Route.swift b/apple/Sources/OSRM/Models/Route.swift index 04179c5..6f51a38 100644 --- a/apple/Sources/OSRM/Models/Route.swift +++ b/apple/Sources/OSRM/Models/Route.swift @@ -11,16 +11,19 @@ import Foundation #endif public struct Route: Codable, Hashable { - /** The distance traveled by the route, in double meters. */ - public var distance: Double? - /** The estimated travel time, in double number of seconds. */ - public var duration: Double? - public var geometry: AnyCodable? + /** The distance traveled by the route, in meters. */ + public var distance: Double + /** The estimated travel time, in number of seconds. */ + public var duration: Double + /** An encoded polyline (https://developers.google.com/maps/documentation/utilities/polylinealgorithm). */ + public var geometry: String + /** The total cost of the route computed by the routing engine. This is a Valhalla extension to the OSRM spec. */ public var weight: Double? + /** The costing model used for the route. This is an extension from Valhalla-based routers. */ public var weightName: String? - public var legs: [RouteLeg]? + public var legs: [RouteLeg] - public init(distance: Double? = nil, duration: Double? = nil, geometry: AnyCodable? = nil, weight: Double? = nil, weightName: String? = nil, legs: [RouteLeg]? = nil) { + public init(distance: Double, duration: Double, geometry: String, weight: Double? = nil, weightName: String? = nil, legs: [RouteLeg]) { self.distance = distance self.duration = duration self.geometry = geometry @@ -42,11 +45,11 @@ public struct Route: Codable, Hashable { public func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(distance, forKey: .distance) - try container.encodeIfPresent(duration, forKey: .duration) - try container.encodeIfPresent(geometry, forKey: .geometry) + try container.encode(distance, forKey: .distance) + try container.encode(duration, forKey: .duration) + try container.encode(geometry, forKey: .geometry) try container.encodeIfPresent(weight, forKey: .weight) try container.encodeIfPresent(weightName, forKey: .weightName) - try container.encodeIfPresent(legs, forKey: .legs) + try container.encode(legs, forKey: .legs) } } diff --git a/apple/Sources/OSRM/Models/RouteLeg.swift b/apple/Sources/OSRM/Models/RouteLeg.swift index 10adee4..d6fa3ac 100644 --- a/apple/Sources/OSRM/Models/RouteLeg.swift +++ b/apple/Sources/OSRM/Models/RouteLeg.swift @@ -11,18 +11,21 @@ import Foundation #endif public struct RouteLeg: Codable, Hashable { - /** The distance traveled by the route, in double meters. */ - public var distance: Double? - /** The estimated travel time, in double number of seconds. */ - public var duration: Double? + /** The distance traveled by the route, in meters. */ + public var distance: Double + /** The estimated travel time, in number of seconds. */ + public var duration: Double + /** The total cost of the leg computed by the routing engine. This is a Valhalla extension to the OSRM spec. */ public var weight: Double? public var summary: String? - public var steps: [RouteStep]? + public var steps: [RouteStep] public var annotation: Annotation? - /** A Mapbox and Valhalla extension which indicates which waypoints are passed through rather than creating a new leg. */ + /** Indicates which waypoints are passed through rather than creating a new leg. This is a Valhalla extension to the OSRM spec. */ public var viaWaypoints: [ViaWaypoint]? + /** Administrative regions visited along the leg. */ + public var admins: [Admin]? - public init(distance: Double? = nil, duration: Double? = nil, weight: Double? = nil, summary: String? = nil, steps: [RouteStep]? = nil, annotation: Annotation? = nil, viaWaypoints: [ViaWaypoint]? = nil) { + public init(distance: Double, duration: Double, weight: Double? = nil, summary: String? = nil, steps: [RouteStep], annotation: Annotation? = nil, viaWaypoints: [ViaWaypoint]? = nil, admins: [Admin]? = nil) { self.distance = distance self.duration = duration self.weight = weight @@ -30,6 +33,7 @@ public struct RouteLeg: Codable, Hashable { self.steps = steps self.annotation = annotation self.viaWaypoints = viaWaypoints + self.admins = admins } public enum CodingKeys: String, CodingKey, CaseIterable { @@ -40,18 +44,20 @@ public struct RouteLeg: Codable, Hashable { case steps case annotation case viaWaypoints = "via_waypoints" + case admins } // Encodable protocol methods public func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(distance, forKey: .distance) - try container.encodeIfPresent(duration, forKey: .duration) + try container.encode(distance, forKey: .distance) + try container.encode(duration, forKey: .duration) try container.encodeIfPresent(weight, forKey: .weight) try container.encodeIfPresent(summary, forKey: .summary) - try container.encodeIfPresent(steps, forKey: .steps) + try container.encode(steps, forKey: .steps) try container.encodeIfPresent(annotation, forKey: .annotation) try container.encodeIfPresent(viaWaypoints, forKey: .viaWaypoints) + try container.encodeIfPresent(admins, forKey: .admins) } } diff --git a/apple/Sources/OSRM/Models/RouteStep.swift b/apple/Sources/OSRM/Models/RouteStep.swift index ceaa5ea..4fe3127 100644 --- a/apple/Sources/OSRM/Models/RouteStep.swift +++ b/apple/Sources/OSRM/Models/RouteStep.swift @@ -10,33 +10,52 @@ import Foundation import AnyCodable #endif +/** A maneuver such as a turn or merge, followed by travel along a single road or path. */ public struct RouteStep: Codable, Hashable { public enum DrivingSide: String, Codable, CaseIterable { case _left = "left" case _right = "right" } - /** The distance traveled by the route, in double meters. */ - public var distance: Double? - /** The estimated travel time, in double number of seconds. */ - public var duration: Double? - public var geometry: AnyCodable? + public enum SpeedLimitSign: String, Codable, CaseIterable { + case mutcd + case vienna + } + + /** The distance traveled by the route, in meters. */ + public var distance: Double + /** The estimated travel time, in number of seconds. */ + public var duration: Double + public var geometry: AnyCodable public var weight: Double? + /** The name of the segment (ex: road) being traversed */ public var name: String? + /** A reference number of code for the segment being traversed. */ public var ref: String? + /** Pronunciation of the name (if available). The format of this varies by implementation/vendor. */ public var pronunciation: String? public var destinations: AnyCodable? public var exits: AnyCodable? - public var mode: String? - public var maneuver: StepManeuver? + /** The mode of travel. */ + public var mode: String + public var maneuver: StepManeuver public var intersections: [Intersection]? + /** The name of the traffic circle. */ public var rotaryName: String? + /** Pronunciation of the rotary name (if available). The format of this varies by implementation/vendor. */ public var rotaryPronunciation: String? + /** The side of the road on which driving is legal for this step. */ public var drivingSide: DrivingSide? + /** A list of announcements which should be spoken at various points along the maneuver. This is a Valhalla extension to the OSRM spec. */ public var voiceInstructions: [VoiceInstruction]? + /** A list of announcements which should be displayed prominently on screen at various points along the maneuver. This is a Valhalla extension to the OSRM spec. */ public var bannerInstructions: [BannerInstruction]? + /** The style of speed limit signs used along the step. This is a Valhalla extension to the OSRM spec, and is only included when speed limits are present in the response. */ + public var speedLimitSign: SpeedLimitSign? + /** The unit of measure that is used locally along the step. This may be different from the unit used in maxspeed annotations, and is provided so that apps can localize their display. This is a Valhalla extension to the OSRM spec, and is only included when speed limits are present in the response. */ + public var speedLimitUnit: String? - public init(distance: Double? = nil, duration: Double? = nil, geometry: AnyCodable? = nil, weight: Double? = nil, name: String? = nil, ref: String? = nil, pronunciation: String? = nil, destinations: AnyCodable? = nil, exits: AnyCodable? = nil, mode: String? = nil, maneuver: StepManeuver? = nil, intersections: [Intersection]? = nil, rotaryName: String? = nil, rotaryPronunciation: String? = nil, drivingSide: DrivingSide? = nil, voiceInstructions: [VoiceInstruction]? = nil, bannerInstructions: [BannerInstruction]? = nil) { + public init(distance: Double, duration: Double, geometry: AnyCodable, weight: Double? = nil, name: String? = nil, ref: String? = nil, pronunciation: String? = nil, destinations: AnyCodable? = nil, exits: AnyCodable? = nil, mode: String, maneuver: StepManeuver, intersections: [Intersection]? = nil, rotaryName: String? = nil, rotaryPronunciation: String? = nil, drivingSide: DrivingSide? = nil, voiceInstructions: [VoiceInstruction]? = nil, bannerInstructions: [BannerInstruction]? = nil, speedLimitSign: SpeedLimitSign? = nil, speedLimitUnit: String? = nil) { self.distance = distance self.duration = duration self.geometry = geometry @@ -54,6 +73,8 @@ public struct RouteStep: Codable, Hashable { self.drivingSide = drivingSide self.voiceInstructions = voiceInstructions self.bannerInstructions = bannerInstructions + self.speedLimitSign = speedLimitSign + self.speedLimitUnit = speedLimitUnit } public enum CodingKeys: String, CodingKey, CaseIterable { @@ -74,28 +95,32 @@ public struct RouteStep: Codable, Hashable { case drivingSide = "driving_side" case voiceInstructions case bannerInstructions + case speedLimitSign + case speedLimitUnit } // Encodable protocol methods public func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(distance, forKey: .distance) - try container.encodeIfPresent(duration, forKey: .duration) - try container.encodeIfPresent(geometry, forKey: .geometry) + try container.encode(distance, forKey: .distance) + try container.encode(duration, forKey: .duration) + try container.encode(geometry, forKey: .geometry) try container.encodeIfPresent(weight, forKey: .weight) try container.encodeIfPresent(name, forKey: .name) try container.encodeIfPresent(ref, forKey: .ref) try container.encodeIfPresent(pronunciation, forKey: .pronunciation) try container.encodeIfPresent(destinations, forKey: .destinations) try container.encodeIfPresent(exits, forKey: .exits) - try container.encodeIfPresent(mode, forKey: .mode) - try container.encodeIfPresent(maneuver, forKey: .maneuver) + try container.encode(mode, forKey: .mode) + try container.encode(maneuver, forKey: .maneuver) try container.encodeIfPresent(intersections, forKey: .intersections) try container.encodeIfPresent(rotaryName, forKey: .rotaryName) try container.encodeIfPresent(rotaryPronunciation, forKey: .rotaryPronunciation) try container.encodeIfPresent(drivingSide, forKey: .drivingSide) try container.encodeIfPresent(voiceInstructions, forKey: .voiceInstructions) try container.encodeIfPresent(bannerInstructions, forKey: .bannerInstructions) + try container.encodeIfPresent(speedLimitSign, forKey: .speedLimitSign) + try container.encodeIfPresent(speedLimitUnit, forKey: .speedLimitUnit) } } diff --git a/apple/Sources/OSRM/Models/SpeedLimit.swift b/apple/Sources/OSRM/Models/SpeedLimit.swift new file mode 100644 index 0000000..e796cbd --- /dev/null +++ b/apple/Sources/OSRM/Models/SpeedLimit.swift @@ -0,0 +1,51 @@ +// +// SpeedLimit.swift +// +// Generated by openapi-generator +// https://openapi-generator.tech +// + +import Foundation +#if canImport(AnyCodable) + import AnyCodable +#endif + +/** The speed limit between the pair of coordinates. Available in Valhalla-derived routers. */ +public struct SpeedLimit: Codable, Hashable { + public enum Unit: String, Codable, CaseIterable { + case kmSlashH = "km/h" + case mph + } + + public var speed: Int? + /** The unit of measure for the speed. Always included if speed is present. */ + public var unit: Unit? + /** True if the speed limit is not known. */ + public var unknown: Bool? + /** True if there is no explicit speed limit (ex: some Autobahn sections) */ + public var _none: Bool? + + public init(speed: Int? = nil, unit: Unit? = nil, unknown: Bool? = nil, _none: Bool? = nil) { + self.speed = speed + self.unit = unit + self.unknown = unknown + self._none = _none + } + + public enum CodingKeys: String, CodingKey, CaseIterable { + case speed + case unit + case unknown + case _none = "none" + } + + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encodeIfPresent(speed, forKey: .speed) + try container.encodeIfPresent(unit, forKey: .unit) + try container.encodeIfPresent(unknown, forKey: .unknown) + try container.encodeIfPresent(_none, forKey: ._none) + } +} diff --git a/apple/Sources/OSRM/Models/StepManeuver.swift b/apple/Sources/OSRM/Models/StepManeuver.swift index ff870e8..48bf294 100644 --- a/apple/Sources/OSRM/Models/StepManeuver.swift +++ b/apple/Sources/OSRM/Models/StepManeuver.swift @@ -11,15 +11,42 @@ import Foundation #endif public struct StepManeuver: Codable, Hashable { - public var location: [Double]? - public var bearingBefore: Int? - public var bearingAfter: Int? - public var type: String? - public var modifier: String? + public enum ModelType: String, Codable, CaseIterable { + case turn + case newName = "new name" + case depart + case arrive + case merge + case ramp + case onRamp = "on ramp" + case offRamp = "off ramp" + case fork + case endOfRoad = "end of road" + case useLane = "use lane" + case _continue = "continue" + case roundabout + case rotary + case roundaboutTurn = "roundabout turn" + case notification + } + + static let locationRule = ArrayRule(minItems: 2, maxItems: 2, uniqueItems: false) + /** A (longitude, latitude) coordinate pair. */ + public var location: [Double] + /** A human-readable instruction for the maneuver. This is a Valhalla extension to the OSRM spec. */ + public var instruction: String? + /** The clockwise angle from true north to the direction of travel immediately before the maneuver. */ + public var bearingBefore: Int + /** The clockwise angle from true north to the direction of travel immediately after the maneuver. */ + public var bearingAfter: Int + public var type: ModelType + public var modifier: GuidanceModifier? + /** The exit number to take (for roundabouts, rotaries, and number of intersections). */ public var exit: Int? - public init(location: [Double]? = nil, bearingBefore: Int? = nil, bearingAfter: Int? = nil, type: String? = nil, modifier: String? = nil, exit: Int? = nil) { + public init(location: [Double], instruction: String? = nil, bearingBefore: Int, bearingAfter: Int, type: ModelType, modifier: GuidanceModifier? = nil, exit: Int? = nil) { self.location = location + self.instruction = instruction self.bearingBefore = bearingBefore self.bearingAfter = bearingAfter self.type = type @@ -29,6 +56,7 @@ public struct StepManeuver: Codable, Hashable { public enum CodingKeys: String, CodingKey, CaseIterable { case location + case instruction case bearingBefore = "bearing_before" case bearingAfter = "bearing_after" case type @@ -40,10 +68,11 @@ public struct StepManeuver: Codable, Hashable { public func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(location, forKey: .location) - try container.encodeIfPresent(bearingBefore, forKey: .bearingBefore) - try container.encodeIfPresent(bearingAfter, forKey: .bearingAfter) - try container.encodeIfPresent(type, forKey: .type) + try container.encode(location, forKey: .location) + try container.encodeIfPresent(instruction, forKey: .instruction) + try container.encode(bearingBefore, forKey: .bearingBefore) + try container.encode(bearingAfter, forKey: .bearingAfter) + try container.encode(type, forKey: .type) try container.encodeIfPresent(modifier, forKey: .modifier) try container.encodeIfPresent(exit, forKey: .exit) } diff --git a/apple/Sources/OSRM/Models/TripWaypoint.swift b/apple/Sources/OSRM/Models/TripWaypoint.swift index 7b07088..3f7791a 100644 --- a/apple/Sources/OSRM/Models/TripWaypoint.swift +++ b/apple/Sources/OSRM/Models/TripWaypoint.swift @@ -11,14 +11,17 @@ import Foundation #endif public struct TripWaypoint: Codable, Hashable { + static let locationRule = ArrayRule(minItems: 2, maxItems: 2, uniqueItems: false) public var name: String? - public var location: [Double]? - public var distance: Double? + /** A (longitude, latitude) coordinate pair. */ + public var location: [Double] + /** The distance of the snapped point from the original location. */ + public var distance: Double public var hint: String? public var tripsIndex: Int? public var waypointIndex: Int? - public init(name: String? = nil, location: [Double]? = nil, distance: Double? = nil, hint: String? = nil, tripsIndex: Int? = nil, waypointIndex: Int? = nil) { + public init(name: String? = nil, location: [Double], distance: Double, hint: String? = nil, tripsIndex: Int? = nil, waypointIndex: Int? = nil) { self.name = name self.location = location self.distance = distance @@ -41,8 +44,8 @@ public struct TripWaypoint: Codable, Hashable { public func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) try container.encodeIfPresent(name, forKey: .name) - try container.encodeIfPresent(location, forKey: .location) - try container.encodeIfPresent(distance, forKey: .distance) + try container.encode(location, forKey: .location) + try container.encode(distance, forKey: .distance) try container.encodeIfPresent(hint, forKey: .hint) try container.encodeIfPresent(tripsIndex, forKey: .tripsIndex) try container.encodeIfPresent(waypointIndex, forKey: .waypointIndex) diff --git a/apple/Sources/OSRM/Models/ViaWaypoint.swift b/apple/Sources/OSRM/Models/ViaWaypoint.swift index 99ecfb0..2e54bde 100644 --- a/apple/Sources/OSRM/Models/ViaWaypoint.swift +++ b/apple/Sources/OSRM/Models/ViaWaypoint.swift @@ -11,11 +11,14 @@ import Foundation #endif public struct ViaWaypoint: Codable, Hashable { - public var distanceFromStart: Double? - public var geometryIndex: Int? - public var waypointIndex: Int? + /** The distance from the start of the leg, in meters. */ + public var distanceFromStart: Double + /** The index of the waypoint's location in the route geometry. */ + public var geometryIndex: Int + /** The index of the associated waypoint. */ + public var waypointIndex: Int - public init(distanceFromStart: Double? = nil, geometryIndex: Int? = nil, waypointIndex: Int? = nil) { + public init(distanceFromStart: Double, geometryIndex: Int, waypointIndex: Int) { self.distanceFromStart = distanceFromStart self.geometryIndex = geometryIndex self.waypointIndex = waypointIndex @@ -31,8 +34,8 @@ public struct ViaWaypoint: Codable, Hashable { public func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(distanceFromStart, forKey: .distanceFromStart) - try container.encodeIfPresent(geometryIndex, forKey: .geometryIndex) - try container.encodeIfPresent(waypointIndex, forKey: .waypointIndex) + try container.encode(distanceFromStart, forKey: .distanceFromStart) + try container.encode(geometryIndex, forKey: .geometryIndex) + try container.encode(waypointIndex, forKey: .waypointIndex) } } diff --git a/apple/Sources/OSRM/Models/VoiceInstruction.swift b/apple/Sources/OSRM/Models/VoiceInstruction.swift index d40fe07..6a03033 100644 --- a/apple/Sources/OSRM/Models/VoiceInstruction.swift +++ b/apple/Sources/OSRM/Models/VoiceInstruction.swift @@ -11,8 +11,11 @@ import Foundation #endif public struct VoiceInstruction: Codable, Hashable { + /** How far (in meters) from the upcoming maneuver the instruction should be announced. */ public var distanceAlongGeometry: Double + /** The plain-text announcement. */ public var announcement: String + /** The announcement in Speech Synthesis Markup Language (SSML). Supported TTS engines include Amazon Polly and Apple's AVSpeechSynthesizer. */ public var ssmlAnnouncement: String? public init(distanceAlongGeometry: Double, announcement: String, ssmlAnnouncement: String? = nil) { diff --git a/apple/Sources/OSRM/Models/Waypoint.swift b/apple/Sources/OSRM/Models/Waypoint.swift index b31c98d..c64bff5 100644 --- a/apple/Sources/OSRM/Models/Waypoint.swift +++ b/apple/Sources/OSRM/Models/Waypoint.swift @@ -11,12 +11,15 @@ import Foundation #endif public struct Waypoint: Codable, Hashable { + static let locationRule = ArrayRule(minItems: 2, maxItems: 2, uniqueItems: false) public var name: String? - public var location: [Double]? - public var distance: Double? + /** A (longitude, latitude) coordinate pair. */ + public var location: [Double] + /** The distance of the snapped point from the original location. */ + public var distance: Double public var hint: String? - public init(name: String? = nil, location: [Double]? = nil, distance: Double? = nil, hint: String? = nil) { + public init(name: String? = nil, location: [Double], distance: Double, hint: String? = nil) { self.name = name self.location = location self.distance = distance @@ -35,8 +38,8 @@ public struct Waypoint: Codable, Hashable { public func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) try container.encodeIfPresent(name, forKey: .name) - try container.encodeIfPresent(location, forKey: .location) - try container.encodeIfPresent(distance, forKey: .distance) + try container.encode(location, forKey: .location) + try container.encode(distance, forKey: .distance) try container.encodeIfPresent(hint, forKey: .hint) } } diff --git a/openapi.yaml b/openapi.yaml index eb2d193..a4033b9 100644 --- a/openapi.yaml +++ b/openapi.yaml @@ -171,7 +171,11 @@ components: This is a Valhalla extension to the OSRM spec. items: $ref: '#/components/schemas/ViaWaypoint' - # TODO: admins + admins: + type: array + description: Administrative regions visited along the leg. + items: + $ref: '#/components/schemas/Admin' RouteStep: type: object description: >- @@ -250,10 +254,29 @@ components: description: >- A list of announcements which should be displayed prominently on screen at various points along the maneuver. This is a Valhalla extension to the OSRM spec. + speedLimitSign: + type: string + enum: + - mutcd + - vienna + description: >- + The style of speed limit signs used along the step. + This is a Valhalla extension to the OSRM spec, + and is only included when speed limits are present in the response. + speedLimitUnit: + type: string + description: >- + The unit of measure that is used locally along the step. + This may be different from the unit used in maxspeed annotations, + and is provided so that apps can localize their display. + This is a Valhalla extension to the OSRM spec, + and is only included when speed limits are present in the response. Annotation: type: object + required: + - distance + - duration properties: - # TODO: Refactor into properties? distance: type: array items: @@ -296,27 +319,7 @@ components: maxspeed: type: array items: - type: object - properties: - speed: - type: integer - unit: - type: string - enum: - - km/h - - mph - description: >- - The unit of measure for the speed. - Always included if speed is present. - unknown: - type: boolean - description: True if the speed limit is not known. - none: - type: boolean - description: "True if there is no explicit speed limit (ex: some Autobahn sections)" - description: >- - The speed limit between the pair of coordinates. - Available in Valhalla-derived routers. + $ref: '#/components/schemas/SpeedLimit' StepManeuver: type: object required: @@ -360,19 +363,7 @@ components: - roundabout turn - notification modifier: - type: string - enum: - - uturn - - sharp right - - right - - slight right - - straight - - slight left - - left - - sharp left - description: >- - An optional value indicating the directional change of the maneuver - (further clarifying type). + $ref: '#/components/schemas/GuidanceModifier' exit: type: integer description: The exit number to take (for roundabouts, rotaries, and number of intersections). @@ -447,6 +438,23 @@ components: description: >- The estimated duration, in seconds, to traverse the intersection. This is a Valhalla extension to the OSRM spec. + turn_duration: + type: number + format: double + description: >- + The estimated duration, in seconds, to complete a turn. + This is a Valhalla extension to the OSRM spec. + turn_weight: + type: number + format: double + geometry_index: + type: integer + description: >- + The index of the intersection in the leg geometry. + This is a Valhalla extension to the OSRM spec. + weight: + type: number + format: double VoiceInstruction: type: object required: @@ -506,31 +514,11 @@ components: - exit roundabout - exit rotary modifier: - type: string - enum: - - uturn - - sharp right - - right - - slight right - - slight left - - left - - sharp left + $ref: '#/components/schemas/GuidanceModifier' components: type: array items: - type: object - properties: - text: - type: string - type: - type: string - enum: - - text - - icon - - delimiter - - exit-number - - exit - - lane + $ref: '#/components/schemas/BannerComponent' description: >- A list of objects with additional context that allow for visual layout improvements beyond what's possible with plain text. @@ -618,4 +606,64 @@ components: format: double minItems: 2 maxItems: 2 - description: A (longitude, latitude) coordinate pair. \ No newline at end of file + description: A (longitude, latitude) coordinate pair. + Admin: + type: object + properties: + iso_3166_1: + type: string + description: The ISO 3166-1 two-character code for the admin region. + iso_3166_1_alpha3: + type: string + description: The ISO 3166-1 three-character code for the admin region. + SpeedLimit: + type: object + properties: + speed: + type: integer + unit: + type: string + enum: + - km/h + - mph + description: >- + The unit of measure for the speed. + Always included if speed is present. + unknown: + type: boolean + description: True if the speed limit is not known. + none: + type: boolean + description: "True if there is no explicit speed limit (ex: some Autobahn sections)" + description: >- + The speed limit between the pair of coordinates. + Available in Valhalla-derived routers. + BannerComponent: + type: object + properties: + text: + type: string + type: + type: string + enum: + - text + - icon + - delimiter + - exit-number + - exit + - lane + GuidanceModifier: + type: string + nullable: true + enum: + - uturn + - sharp right + - right + - slight right + - straight + - slight left + - left + - sharp left + description: >- + An optional value indicating the directional change of the maneuver + (further clarifying type). \ No newline at end of file From 4f61672f9d42d38ce0fd7d2b28c6543361d8d2b8 Mon Sep 17 00:00:00 2001 From: Ian Wagner Date: Wed, 4 Sep 2024 13:58:41 +0900 Subject: [PATCH 5/7] Clean swift models --- .../OSRM/Models/AnnotationMetadata.swift | 30 ------------- .../Models/BannerContentComponentsInner.swift | 34 --------------- .../Models/BannerInstructionPrimary.swift | 42 ------------------- ...nerInstructionPrimaryComponentsInner.swift | 34 --------------- .../OSRM/Models/BannerInstructions.swift | 38 ----------------- .../Models/BannerInstructionsPrimary.swift | 42 ------------------- ...erInstructionsPrimaryComponentsInner.swift | 34 --------------- 7 files changed, 254 deletions(-) delete mode 100644 apple/Sources/OSRM/Models/AnnotationMetadata.swift delete mode 100644 apple/Sources/OSRM/Models/BannerContentComponentsInner.swift delete mode 100644 apple/Sources/OSRM/Models/BannerInstructionPrimary.swift delete mode 100644 apple/Sources/OSRM/Models/BannerInstructionPrimaryComponentsInner.swift delete mode 100644 apple/Sources/OSRM/Models/BannerInstructions.swift delete mode 100644 apple/Sources/OSRM/Models/BannerInstructionsPrimary.swift delete mode 100644 apple/Sources/OSRM/Models/BannerInstructionsPrimaryComponentsInner.swift diff --git a/apple/Sources/OSRM/Models/AnnotationMetadata.swift b/apple/Sources/OSRM/Models/AnnotationMetadata.swift deleted file mode 100644 index 7f84cf0..0000000 --- a/apple/Sources/OSRM/Models/AnnotationMetadata.swift +++ /dev/null @@ -1,30 +0,0 @@ -// -// AnnotationMetadata.swift -// -// Generated by openapi-generator -// https://openapi-generator.tech -// - -import Foundation -#if canImport(AnyCodable) - import AnyCodable -#endif - -public struct AnnotationMetadata: Codable, Hashable { - public var datasourceNames: [String]? - - public init(datasourceNames: [String]? = nil) { - self.datasourceNames = datasourceNames - } - - public enum CodingKeys: String, CodingKey, CaseIterable { - case datasourceNames = "datasource_names" - } - - // Encodable protocol methods - - public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(datasourceNames, forKey: .datasourceNames) - } -} diff --git a/apple/Sources/OSRM/Models/BannerContentComponentsInner.swift b/apple/Sources/OSRM/Models/BannerContentComponentsInner.swift deleted file mode 100644 index a3339c7..0000000 --- a/apple/Sources/OSRM/Models/BannerContentComponentsInner.swift +++ /dev/null @@ -1,34 +0,0 @@ -// -// BannerContentComponentsInner.swift -// -// Generated by openapi-generator -// https://openapi-generator.tech -// - -import Foundation -#if canImport(AnyCodable) - import AnyCodable -#endif - -public struct BannerContentComponentsInner: Codable, Hashable { - public var text: String? - public var type: String? - - public init(text: String? = nil, type: String? = nil) { - self.text = text - self.type = type - } - - public enum CodingKeys: String, CodingKey, CaseIterable { - case text - case type - } - - // Encodable protocol methods - - public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(text, forKey: .text) - try container.encodeIfPresent(type, forKey: .type) - } -} diff --git a/apple/Sources/OSRM/Models/BannerInstructionPrimary.swift b/apple/Sources/OSRM/Models/BannerInstructionPrimary.swift deleted file mode 100644 index e576247..0000000 --- a/apple/Sources/OSRM/Models/BannerInstructionPrimary.swift +++ /dev/null @@ -1,42 +0,0 @@ -// -// BannerInstructionPrimary.swift -// -// Generated by openapi-generator -// https://openapi-generator.tech -// - -import Foundation -#if canImport(AnyCodable) - import AnyCodable -#endif - -public struct BannerInstructionPrimary: Codable, Hashable { - public var text: String? - public var type: String? - public var modifier: String? - public var components: [BannerInstructionPrimaryComponentsInner]? - - public init(text: String? = nil, type: String? = nil, modifier: String? = nil, components: [BannerInstructionPrimaryComponentsInner]? = nil) { - self.text = text - self.type = type - self.modifier = modifier - self.components = components - } - - public enum CodingKeys: String, CodingKey, CaseIterable { - case text - case type - case modifier - case components - } - - // Encodable protocol methods - - public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(text, forKey: .text) - try container.encodeIfPresent(type, forKey: .type) - try container.encodeIfPresent(modifier, forKey: .modifier) - try container.encodeIfPresent(components, forKey: .components) - } -} diff --git a/apple/Sources/OSRM/Models/BannerInstructionPrimaryComponentsInner.swift b/apple/Sources/OSRM/Models/BannerInstructionPrimaryComponentsInner.swift deleted file mode 100644 index 7705557..0000000 --- a/apple/Sources/OSRM/Models/BannerInstructionPrimaryComponentsInner.swift +++ /dev/null @@ -1,34 +0,0 @@ -// -// BannerInstructionPrimaryComponentsInner.swift -// -// Generated by openapi-generator -// https://openapi-generator.tech -// - -import Foundation -#if canImport(AnyCodable) - import AnyCodable -#endif - -public struct BannerInstructionPrimaryComponentsInner: Codable, Hashable { - public var text: String? - public var type: String? - - public init(text: String? = nil, type: String? = nil) { - self.text = text - self.type = type - } - - public enum CodingKeys: String, CodingKey, CaseIterable { - case text - case type - } - - // Encodable protocol methods - - public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(text, forKey: .text) - try container.encodeIfPresent(type, forKey: .type) - } -} diff --git a/apple/Sources/OSRM/Models/BannerInstructions.swift b/apple/Sources/OSRM/Models/BannerInstructions.swift deleted file mode 100644 index f9d4f98..0000000 --- a/apple/Sources/OSRM/Models/BannerInstructions.swift +++ /dev/null @@ -1,38 +0,0 @@ -// -// BannerInstructions.swift -// -// Generated by openapi-generator -// https://openapi-generator.tech -// - -import Foundation -#if canImport(AnyCodable) - import AnyCodable -#endif - -public struct BannerInstructions: Codable, Hashable { - public var distanceAlongGeometry: Double? - public var primary: BannerInstructionsPrimary? - public var secondary: BannerInstructionsPrimary? - - public init(distanceAlongGeometry: Double? = nil, primary: BannerInstructionsPrimary? = nil, secondary: BannerInstructionsPrimary? = nil) { - self.distanceAlongGeometry = distanceAlongGeometry - self.primary = primary - self.secondary = secondary - } - - public enum CodingKeys: String, CodingKey, CaseIterable { - case distanceAlongGeometry - case primary - case secondary - } - - // Encodable protocol methods - - public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(distanceAlongGeometry, forKey: .distanceAlongGeometry) - try container.encodeIfPresent(primary, forKey: .primary) - try container.encodeIfPresent(secondary, forKey: .secondary) - } -} diff --git a/apple/Sources/OSRM/Models/BannerInstructionsPrimary.swift b/apple/Sources/OSRM/Models/BannerInstructionsPrimary.swift deleted file mode 100644 index 5a89836..0000000 --- a/apple/Sources/OSRM/Models/BannerInstructionsPrimary.swift +++ /dev/null @@ -1,42 +0,0 @@ -// -// BannerInstructionsPrimary.swift -// -// Generated by openapi-generator -// https://openapi-generator.tech -// - -import Foundation -#if canImport(AnyCodable) - import AnyCodable -#endif - -public struct BannerInstructionsPrimary: Codable, Hashable { - public var text: String? - public var type: String? - public var modifier: String? - public var components: [BannerInstructionsPrimaryComponentsInner]? - - public init(text: String? = nil, type: String? = nil, modifier: String? = nil, components: [BannerInstructionsPrimaryComponentsInner]? = nil) { - self.text = text - self.type = type - self.modifier = modifier - self.components = components - } - - public enum CodingKeys: String, CodingKey, CaseIterable { - case text - case type - case modifier - case components - } - - // Encodable protocol methods - - public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(text, forKey: .text) - try container.encodeIfPresent(type, forKey: .type) - try container.encodeIfPresent(modifier, forKey: .modifier) - try container.encodeIfPresent(components, forKey: .components) - } -} diff --git a/apple/Sources/OSRM/Models/BannerInstructionsPrimaryComponentsInner.swift b/apple/Sources/OSRM/Models/BannerInstructionsPrimaryComponentsInner.swift deleted file mode 100644 index 4a5551c..0000000 --- a/apple/Sources/OSRM/Models/BannerInstructionsPrimaryComponentsInner.swift +++ /dev/null @@ -1,34 +0,0 @@ -// -// BannerInstructionsPrimaryComponentsInner.swift -// -// Generated by openapi-generator -// https://openapi-generator.tech -// - -import Foundation -#if canImport(AnyCodable) - import AnyCodable -#endif - -public struct BannerInstructionsPrimaryComponentsInner: Codable, Hashable { - public var text: String? - public var type: String? - - public init(text: String? = nil, type: String? = nil) { - self.text = text - self.type = type - } - - public enum CodingKeys: String, CodingKey, CaseIterable { - case text - case type - } - - // Encodable protocol methods - - public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(text, forKey: .text) - try container.encodeIfPresent(type, forKey: .type) - } -} From a13bfe0ca1257c8358331022ff585d8396fd42bc Mon Sep 17 00:00:00 2001 From: Ian Wagner Date: Wed, 4 Sep 2024 16:43:46 +0900 Subject: [PATCH 6/7] More type fixes --- apple/Sources/OSRM/Models/Annotation.swift | 10 +++++----- apple/Sources/OSRM/Models/RouteStep.swift | 6 +++--- openapi.yaml | 9 ++------- 3 files changed, 10 insertions(+), 15 deletions(-) diff --git a/apple/Sources/OSRM/Models/Annotation.swift b/apple/Sources/OSRM/Models/Annotation.swift index e371843..fbc9847 100644 --- a/apple/Sources/OSRM/Models/Annotation.swift +++ b/apple/Sources/OSRM/Models/Annotation.swift @@ -12,9 +12,9 @@ import Foundation public struct Annotation: Codable, Hashable { /** The distance, in meters, between each pair of coordinates. */ - public var distance: [Double] + public var distance: [Double]? /** The duration between each pair of coordinates, in seconds. */ - public var duration: [Double] + public var duration: [Double]? /** The index of the datasource for the speed between each pair of coordinates. 0 is the default profile. Other values are supplied via --segment-speed-file to osrm-contract. This is OSRM-specific and not supported by most other routers. */ public var datasources: [Int]? /** The OSM node ID for each coordinate along the route (excluding the first/last user-supplied coordinates). This is not included in Valhalla-derived routers. */ @@ -24,7 +24,7 @@ public struct Annotation: Codable, Hashable { public var speed: [Double]? public var maxspeed: [SpeedLimit]? - public init(distance: [Double], duration: [Double], datasources: [Int]? = nil, nodes: [Int]? = nil, weight: [Int]? = nil, speed: [Double]? = nil, maxspeed: [SpeedLimit]? = nil) { + public init(distance: [Double]? = nil, duration: [Double]? = nil, datasources: [Int]? = nil, nodes: [Int]? = nil, weight: [Int]? = nil, speed: [Double]? = nil, maxspeed: [SpeedLimit]? = nil) { self.distance = distance self.duration = duration self.datasources = datasources @@ -48,8 +48,8 @@ public struct Annotation: Codable, Hashable { public func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(distance, forKey: .distance) - try container.encode(duration, forKey: .duration) + try container.encodeIfPresent(distance, forKey: .distance) + try container.encodeIfPresent(duration, forKey: .duration) try container.encodeIfPresent(datasources, forKey: .datasources) try container.encodeIfPresent(nodes, forKey: .nodes) try container.encodeIfPresent(weight, forKey: .weight) diff --git a/apple/Sources/OSRM/Models/RouteStep.swift b/apple/Sources/OSRM/Models/RouteStep.swift index 4fe3127..1279467 100644 --- a/apple/Sources/OSRM/Models/RouteStep.swift +++ b/apple/Sources/OSRM/Models/RouteStep.swift @@ -34,8 +34,8 @@ public struct RouteStep: Codable, Hashable { public var ref: String? /** Pronunciation of the name (if available). The format of this varies by implementation/vendor. */ public var pronunciation: String? - public var destinations: AnyCodable? - public var exits: AnyCodable? + public var destinations: String? + public var exits: String? /** The mode of travel. */ public var mode: String public var maneuver: StepManeuver @@ -55,7 +55,7 @@ public struct RouteStep: Codable, Hashable { /** The unit of measure that is used locally along the step. This may be different from the unit used in maxspeed annotations, and is provided so that apps can localize their display. This is a Valhalla extension to the OSRM spec, and is only included when speed limits are present in the response. */ public var speedLimitUnit: String? - public init(distance: Double, duration: Double, geometry: AnyCodable, weight: Double? = nil, name: String? = nil, ref: String? = nil, pronunciation: String? = nil, destinations: AnyCodable? = nil, exits: AnyCodable? = nil, mode: String, maneuver: StepManeuver, intersections: [Intersection]? = nil, rotaryName: String? = nil, rotaryPronunciation: String? = nil, drivingSide: DrivingSide? = nil, voiceInstructions: [VoiceInstruction]? = nil, bannerInstructions: [BannerInstruction]? = nil, speedLimitSign: SpeedLimitSign? = nil, speedLimitUnit: String? = nil) { + public init(distance: Double, duration: Double, geometry: AnyCodable, weight: Double? = nil, name: String? = nil, ref: String? = nil, pronunciation: String? = nil, destinations: String? = nil, exits: String? = nil, mode: String, maneuver: StepManeuver, intersections: [Intersection]? = nil, rotaryName: String? = nil, rotaryPronunciation: String? = nil, drivingSide: DrivingSide? = nil, voiceInstructions: [VoiceInstruction]? = nil, bannerInstructions: [BannerInstruction]? = nil, speedLimitSign: SpeedLimitSign? = nil, speedLimitUnit: String? = nil) { self.distance = distance self.duration = duration self.geometry = geometry diff --git a/openapi.yaml b/openapi.yaml index a4033b9..8594aa4 100644 --- a/openapi.yaml +++ b/openapi.yaml @@ -212,11 +212,9 @@ components: Pronunciation of the name (if available). The format of this varies by implementation/vendor. destinations: - # FIXME - type: object + type: string exits: - # FIXME - type: object + type: string mode: type: string description: The mode of travel. @@ -273,9 +271,6 @@ components: and is only included when speed limits are present in the response. Annotation: type: object - required: - - distance - - duration properties: distance: type: array From 8f4277dd23b08609a452fe6fdb32fa6f8012a840 Mon Sep 17 00:00:00 2001 From: Ian Wagner Date: Thu, 5 Sep 2024 10:52:43 +0900 Subject: [PATCH 7/7] Fix swift --- generate_models.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/generate_models.sh b/generate_models.sh index 7b9fff5..a7a3236 100755 --- a/generate_models.sh +++ b/generate_models.sh @@ -45,6 +45,7 @@ if [ "$language" = "swift" ]; then swiftformat .build/OpenAPIClient/Classes/OpenAPIsModels cp .build/OpenAPIClient/Classes/OpenAPIsModels/* ./apple/Sources/OSRM/Models + cp .build/OpenAPIClient/Classes/OpenAPIsModels/Validation.swift ./apple/Sources/OSRM/ else echo "Language not supported" exit 1