Skip to content

Commit

Permalink
Version 4 - Support for navigation aids
Browse files Browse the repository at this point in the history
  • Loading branch information
ianthetechie committed Sep 4, 2024
1 parent b2d1aa4 commit 87d74dc
Show file tree
Hide file tree
Showing 42 changed files with 1,410 additions and 21 deletions.
42 changes: 42 additions & 0 deletions .openapi-generator/FILES
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Sources/StadiaMaps/Models.swift
Sources/StadiaMaps/Models/Access.swift
Sources/StadiaMaps/Models/AdminRegion.swift
Sources/StadiaMaps/Models/Administrative.swift
Sources/StadiaMaps/Models/AnnotationFilters.swift
Sources/StadiaMaps/Models/AutoCostingOptions.swift
Sources/StadiaMaps/Models/BaseCostingOptions.swift
Sources/StadiaMaps/Models/BaseTraceRequest.swift
Expand All @@ -34,6 +35,7 @@ Sources/StadiaMaps/Models/DistanceUnit.swift
Sources/StadiaMaps/Models/EdgeSign.swift
Sources/StadiaMaps/Models/EdgeUse.swift
Sources/StadiaMaps/Models/EndNode.swift
Sources/StadiaMaps/Models/ExtendedDirectionsOptions.swift
Sources/StadiaMaps/Models/GeoAttributes.swift
Sources/StadiaMaps/Models/GeoJSONGeometry.swift
Sources/StadiaMaps/Models/GeoJSONGeometryBase.swift
Expand Down Expand Up @@ -75,6 +77,24 @@ Sources/StadiaMaps/Models/NearestRoadsRequest.swift
Sources/StadiaMaps/Models/NodeId.swift
Sources/StadiaMaps/Models/NodeType.swift
Sources/StadiaMaps/Models/OptimizedRouteRequest.swift
Sources/StadiaMaps/Models/OsrmAdmin.swift
Sources/StadiaMaps/Models/OsrmAnnotation.swift
Sources/StadiaMaps/Models/OsrmBannerComponent.swift
Sources/StadiaMaps/Models/OsrmBannerContent.swift
Sources/StadiaMaps/Models/OsrmBannerInstruction.swift
Sources/StadiaMaps/Models/OsrmBaseApiResponse.swift
Sources/StadiaMaps/Models/OsrmGuidanceModifier.swift
Sources/StadiaMaps/Models/OsrmIntersection.swift
Sources/StadiaMaps/Models/OsrmLane.swift
Sources/StadiaMaps/Models/OsrmRoute.swift
Sources/StadiaMaps/Models/OsrmRouteLeg.swift
Sources/StadiaMaps/Models/OsrmRouteResponse.swift
Sources/StadiaMaps/Models/OsrmRouteStep.swift
Sources/StadiaMaps/Models/OsrmSpeedLimit.swift
Sources/StadiaMaps/Models/OsrmStepManeuver.swift
Sources/StadiaMaps/Models/OsrmViaWaypoint.swift
Sources/StadiaMaps/Models/OsrmVoiceInstruction.swift
Sources/StadiaMaps/Models/OsrmWaypoint.swift
Sources/StadiaMaps/Models/PedestrianCostingOptions.swift
Sources/StadiaMaps/Models/PeliasGeoJSONFeature.swift
Sources/StadiaMaps/Models/PeliasGeoJSONProperties.swift
Expand All @@ -85,6 +105,7 @@ Sources/StadiaMaps/Models/PeliasResponse.swift
Sources/StadiaMaps/Models/PeliasSource.swift
Sources/StadiaMaps/Models/Restrictions.swift
Sources/StadiaMaps/Models/RoadClass.swift
Sources/StadiaMaps/Models/Route200Response.swift
Sources/StadiaMaps/Models/RouteLeg.swift
Sources/StadiaMaps/Models/RouteManeuver.swift
Sources/StadiaMaps/Models/RouteRequest.swift
Expand Down Expand Up @@ -120,6 +141,7 @@ StadiaMaps.podspec
docs/Access.md
docs/AdminRegion.md
docs/Administrative.md
docs/AnnotationFilters.md
docs/AutoCostingOptions.md
docs/BaseCostingOptions.md
docs/BaseTraceRequest.md
Expand All @@ -137,6 +159,7 @@ docs/DistanceUnit.md
docs/EdgeSign.md
docs/EdgeUse.md
docs/EndNode.md
docs/ExtendedDirectionsOptions.md
docs/GeoAttributes.md
docs/GeoJSONGeometry.md
docs/GeoJSONGeometryBase.md
Expand Down Expand Up @@ -180,6 +203,24 @@ docs/NearestRoadsRequest.md
docs/NodeId.md
docs/NodeType.md
docs/OptimizedRouteRequest.md
docs/OsrmAdmin.md
docs/OsrmAnnotation.md
docs/OsrmBannerComponent.md
docs/OsrmBannerContent.md
docs/OsrmBannerInstruction.md
docs/OsrmBaseApiResponse.md
docs/OsrmGuidanceModifier.md
docs/OsrmIntersection.md
docs/OsrmLane.md
docs/OsrmRoute.md
docs/OsrmRouteLeg.md
docs/OsrmRouteResponse.md
docs/OsrmRouteStep.md
docs/OsrmSpeedLimit.md
docs/OsrmStepManeuver.md
docs/OsrmViaWaypoint.md
docs/OsrmVoiceInstruction.md
docs/OsrmWaypoint.md
docs/PedestrianCostingOptions.md
docs/PeliasGeoJSONFeature.md
docs/PeliasGeoJSONProperties.md
Expand All @@ -190,6 +231,7 @@ docs/PeliasResponse.md
docs/PeliasSource.md
docs/Restrictions.md
docs/RoadClass.md
docs/Route200Response.md
docs/RouteLeg.md
docs/RouteManeuver.md
docs/RouteRequest.md
Expand Down
2 changes: 1 addition & 1 deletion .openapi-generator/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7.7.0
7.8.0
34 changes: 34 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,40 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Version 4.0.0 - 2024-09-04

### Added

- Support for the OSRM format and navigation aids
- BREAKING: To support the new format, the response type of directions APIs has changed

You will now need to match against the response enum,
which has variants for each response.
This enables you to build your apps in a type-safe manner.
Here is an example:


```swift
let req = RouteRequest(units: .mi,
format: .osrm,
bannerInstructions: true,
filters: AnnotationFilters(action: .include, attributes: [
.speedLimit,
]),
id: "route",
locations: [
RoutingWaypoint(lat: locationA.lat, lon: locationA.lon),
RoutingWaypoint(lat: locationB.lat, lon: locationB.lon),
],
costing: .auto,
costingOptions: CostingOptions(auto: AutoCostingOptions(useHighways: 0.3)))
guard case let .typeOsrmRouteResponse(res) = try await RoutingAPI.route(routeRequest: req) else {
XCTFail("Expected an OSRM format route response")
return
}
```


## Version 3.2.1 - 2024-08-16


Expand Down
2 changes: 2 additions & 0 deletions Sources/StadiaMaps/APIHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ public enum APIHelper {
return collection
.compactMap { value in convertAnyToString(value) }
.joined(separator: ",")
} else if let value = source as? any RawRepresentable {
return "\(value.rawValue)"
}
return source
}
Expand Down
20 changes: 10 additions & 10 deletions Sources/StadiaMaps/APIs/RoutingAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,10 @@ open class RoutingAPI {
Calculate an optimized route between a known start and end point.
- parameter optimizedRouteRequest: (body) (optional)
- returns: RouteResponse
- returns: Route200Response
*/
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
open class func optimizedRoute(optimizedRouteRequest: OptimizedRouteRequest? = nil) async throws -> RouteResponse {
open class func optimizedRoute(optimizedRouteRequest: OptimizedRouteRequest? = nil) async throws -> Route200Response {
try await optimizedRouteWithRequestBuilder(optimizedRouteRequest: optimizedRouteRequest).execute().body
}

Expand All @@ -147,9 +147,9 @@ open class RoutingAPI {
- type: apiKey api_key (QUERY)
- name: ApiKeyAuth
- parameter optimizedRouteRequest: (body) (optional)
- returns: RequestBuilder<RouteResponse>
- returns: RequestBuilder<Route200Response>
*/
open class func optimizedRouteWithRequestBuilder(optimizedRouteRequest: OptimizedRouteRequest? = nil) -> RequestBuilder<RouteResponse> {
open class func optimizedRouteWithRequestBuilder(optimizedRouteRequest: OptimizedRouteRequest? = nil) -> RequestBuilder<Route200Response> {
let localVariablePath = "/optimized_route/v1"
let localVariableURLString = StadiaMapsAPI.basePath + localVariablePath
let localVariableParameters = JSONEncodingHelper.encodingParameters(forEncodableObject: optimizedRouteRequest)
Expand All @@ -162,7 +162,7 @@ open class RoutingAPI {

let localVariableHeaderParameters = APIHelper.rejectNilHeaders(localVariableNillableHeaders)

let localVariableRequestBuilder: RequestBuilder<RouteResponse>.Type = StadiaMapsAPI.requestBuilderFactory.getBuilder()
let localVariableRequestBuilder: RequestBuilder<Route200Response>.Type = StadiaMapsAPI.requestBuilderFactory.getBuilder()

return localVariableRequestBuilder.init(method: "POST", URLString: (localVariableUrlComponents?.string ?? localVariableURLString), parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true)
}
Expand All @@ -171,10 +171,10 @@ open class RoutingAPI {
Get turn by turn routing instructions between two or more locations.
- parameter routeRequest: (body) (optional)
- returns: RouteResponse
- returns: Route200Response
*/
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
open class func route(routeRequest: RouteRequest? = nil) async throws -> RouteResponse {
open class func route(routeRequest: RouteRequest? = nil) async throws -> Route200Response {
try await routeWithRequestBuilder(routeRequest: routeRequest).execute().body
}

Expand All @@ -186,9 +186,9 @@ open class RoutingAPI {
- type: apiKey api_key (QUERY)
- name: ApiKeyAuth
- parameter routeRequest: (body) (optional)
- returns: RequestBuilder<RouteResponse>
- returns: RequestBuilder<Route200Response>
*/
open class func routeWithRequestBuilder(routeRequest: RouteRequest? = nil) -> RequestBuilder<RouteResponse> {
open class func routeWithRequestBuilder(routeRequest: RouteRequest? = nil) -> RequestBuilder<Route200Response> {
let localVariablePath = "/route/v1"
let localVariableURLString = StadiaMapsAPI.basePath + localVariablePath
let localVariableParameters = JSONEncodingHelper.encodingParameters(forEncodableObject: routeRequest)
Expand All @@ -201,7 +201,7 @@ open class RoutingAPI {

let localVariableHeaderParameters = APIHelper.rejectNilHeaders(localVariableNillableHeaders)

let localVariableRequestBuilder: RequestBuilder<RouteResponse>.Type = StadiaMapsAPI.requestBuilderFactory.getBuilder()
let localVariableRequestBuilder: RequestBuilder<Route200Response>.Type = StadiaMapsAPI.requestBuilderFactory.getBuilder()

return localVariableRequestBuilder.init(method: "POST", URLString: (localVariableUrlComponents?.string ?? localVariableURLString), parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: true)
}
Expand Down
47 changes: 47 additions & 0 deletions Sources/StadiaMaps/Models/AnnotationFilters.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//
// AnnotationFilters.swift
//
// Generated by openapi-generator
// https://openapi-generator.tech
//

import Foundation
#if canImport(AnyCodable)
import AnyCodable
#endif

public struct AnnotationFilters: Codable, JSONEncodable, Hashable {
public enum Action: String, Codable, CaseIterable {
case include
case exclude
}

public enum Attributes: String, Codable, CaseIterable {
case speed = "shape_attributes.speed"
case speedLimit = "shape_attributes.speed_limit"
case time = "shape_attributes.time"
case length = "shape_attributes.length"
}

public var action: Action?
/** A set of granular attributes to include between every pair of coordinates along the route. This can significantly increase the response size. */
public var attributes: [Attributes]?

public init(action: Action? = nil, attributes: [Attributes]? = nil) {
self.action = action
self.attributes = attributes
}

public enum CodingKeys: String, CodingKey, CaseIterable {
case action
case attributes
}

// Encodable protocol methods

public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(action, forKey: .action)
try container.encodeIfPresent(attributes, forKey: .attributes)
}
}
50 changes: 50 additions & 0 deletions Sources/StadiaMaps/Models/ExtendedDirectionsOptions.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//
// ExtendedDirectionsOptions.swift
//
// Generated by openapi-generator
// https://openapi-generator.tech
//

import Foundation
#if canImport(AnyCodable)
import AnyCodable
#endif

public struct ExtendedDirectionsOptions: Codable, JSONEncodable, Hashable {
public enum Format: String, Codable, CaseIterable {
case json
case osrm
}

/** The output response format. The default JSON format is extremely compact and ideal for web or data-constrained use cases where you want to fetch additional attributes on demand in small chunks. The OSRM format is much richer and is configurable with significantly more info for turn-by-turn navigation use cases. */
public var format: Format?
/** Optionally includes helpful banners with timing information for turn-by-turn navigation. This is only available in the OSRM format. */
public var bannerInstructions: Bool?
/** Optionally includes voice instructions with timing information for turn-by-turn navigation. This is only available in the OSRM format. */
public var voiceInstructions: Bool?
public var filters: AnnotationFilters?

public init(format: Format? = nil, bannerInstructions: Bool? = nil, voiceInstructions: Bool? = nil, filters: AnnotationFilters? = nil) {
self.format = format
self.bannerInstructions = bannerInstructions
self.voiceInstructions = voiceInstructions
self.filters = filters
}

public enum CodingKeys: String, CodingKey, CaseIterable {
case format
case bannerInstructions = "banner_instructions"
case voiceInstructions = "voice_instructions"
case filters
}

// Encodable protocol methods

public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(format, forKey: .format)
try container.encodeIfPresent(bannerInstructions, forKey: .bannerInstructions)
try container.encodeIfPresent(voiceInstructions, forKey: .voiceInstructions)
try container.encodeIfPresent(filters, forKey: .filters)
}
}
1 change: 1 addition & 0 deletions Sources/StadiaMaps/Models/GeoJSONPoint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public struct GeoJSONPoint: Codable, JSONEncodable, Hashable {
case multiPolygon = "MultiPolygon"
}

static let coordinatesRule = ArrayRule(minItems: 2, maxItems: 3, uniqueItems: false)
public var type: ModelType
public var coordinates: [Double]

Expand Down
1 change: 1 addition & 0 deletions Sources/StadiaMaps/Models/IsochroneRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Foundation
#endif

public struct IsochroneRequest: Codable, JSONEncodable, Hashable {
static let contoursRule = ArrayRule(minItems: 1, maxItems: 4, uniqueItems: false)
static let denoiseRule = NumericRule<Double>(minimum: 0, exclusiveMinimum: false, maximum: 1, exclusiveMaximum: false, multipleOf: nil)
/** An identifier to disambiguate requests (echoed by the server). */
public var id: String?
Expand Down
Loading

0 comments on commit 87d74dc

Please sign in to comment.