Skip to content

Commit

Permalink
feat: swift package setup and OSRM models
Browse files Browse the repository at this point in the history
  • Loading branch information
Archdoog committed Mar 13, 2024
1 parent d87227f commit e906ef4
Show file tree
Hide file tree
Showing 21 changed files with 1,698 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.build
25 changes: 25 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// swift-tools-version: 5.9
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "OSRM",
platforms: [
.iOS(.v13)
],
products: [
.library(
name: "OSRM",
targets: ["OSRM"]
)
],
targets: [
.target(
name: "OSRM",
dependencies: [
"AnyCodable"
]
)
]
)
17 changes: 15 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,15 @@
# osrm-openapi
OpenAPI spec for generating OSRM Models
# OSRM OpenAPI

OpenAPI spec and generation script to build OSRM Models for various platforms.

## Building OSRM Models

```sh
./generate_models.sh swift
```

* `--clean` delete the .build and generated folder.

## References

- OSRM Open API Initial Source - <https://github.com/1papaya/osrm-openapi>
56 changes: 56 additions & 0 deletions Sources/OSRM/Models/Annotation.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
//
// Annotation.swift
//
// Generated by openapi-generator
// https://openapi-generator.tech
//

import Foundation
#if canImport(AnyCodable)
import AnyCodable
#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]?
public var datasources: [Int]?
public var nodes: [Int]?
public var weight: [Int]?
public var speed: [Double]?
public var metadata: AnnotationMetadata?

public init(distance: [Double]? = nil, duration: [Double]? = nil, datasources: [Int]? = nil, nodes: [Int]? = nil, weight: [Int]? = nil, speed: [Double]? = nil, metadata: AnnotationMetadata? = nil) {
self.distance = distance
self.duration = duration
self.datasources = datasources
self.nodes = nodes
self.weight = weight
self.speed = speed
self.metadata = metadata
}

public enum CodingKeys: String, CodingKey, CaseIterable {
case distance
case duration
case datasources
case nodes
case weight
case speed
case metadata
}

// 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(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)
}
}
30 changes: 30 additions & 0 deletions Sources/OSRM/Models/AnnotationMetadata.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//
// 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)
}
}
54 changes: 54 additions & 0 deletions Sources/OSRM/Models/ApiResponse.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
//
// ApiResponse.swift
//
// Generated by openapi-generator
// https://openapi-generator.tech
//

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

public struct ApiResponse: Codable, Hashable {
public enum Code: String, Codable, CaseIterable {
case ok = "Ok"
case invalidUrl = "InvalidUrl"
case invalidService = "InvalidService"
case invalidVersion = "InvalidVersion"
case invalidOptions = "InvalidOptions"
case invalidQuery = "InvalidQuery"
case invalidValue = "InvalidValue"
case noSegment = "NoSegment"
case tooBig = "TooBig"
case noRoute = "NoRoute"
case noTable = "NoTable"
case notImplemented = "NotImplemented"
case noTrips = "NoTrips"
}

public var code: Code
public var message: String?
public var dataVersion: Date?

public init(code: Code, message: String? = nil, dataVersion: Date? = nil) {
self.code = code
self.message = message
self.dataVersion = dataVersion
}

public enum CodingKeys: String, CodingKey, CaseIterable {
case code
case message
case dataVersion = "data_version"
}

// Encodable protocol methods

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

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

public struct Intersection: Codable, Hashable {
public var location: [Double]?
public var bearings: [Int]?
public var classes: [String]?
public var entry: [Bool]?
public var _in: Int?
public var out: Int?
public var lanes: [Lane]?

public init(location: [Double]? = nil, bearings: [Int]? = nil, classes: [String]? = nil, entry: [Bool]? = nil, _in: Int? = nil, out: Int? = nil, lanes: [Lane]? = nil) {
self.location = location
self.bearings = bearings
self.classes = classes
self.entry = entry
self._in = _in
self.out = out
self.lanes = lanes
}

public enum CodingKeys: String, CodingKey, CaseIterable {
case location
case bearings
case classes
case entry
case _in = "in"
case out
case lanes
}

// Encodable protocol methods

public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(location, forKey: .location)
try container.encodeIfPresent(bearings, forKey: .bearings)
try container.encodeIfPresent(classes, forKey: .classes)
try container.encodeIfPresent(entry, forKey: .entry)
try container.encodeIfPresent(_in, forKey: ._in)
try container.encodeIfPresent(out, forKey: .out)
try container.encodeIfPresent(lanes, forKey: .lanes)
}
}
34 changes: 34 additions & 0 deletions Sources/OSRM/Models/Lane.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// Lane.swift
//
// Generated by openapi-generator
// https://openapi-generator.tech
//

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

public struct Lane: Codable, Hashable {
public var indications: [String]?
public var valid: Bool?

public init(indications: [String]? = nil, valid: Bool? = nil) {
self.indications = indications
self.valid = valid
}

public enum CodingKeys: String, CodingKey, CaseIterable {
case indications
case valid
}

// Encodable protocol methods

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)
}
}
58 changes: 58 additions & 0 deletions Sources/OSRM/Models/NearestResponse.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
//
// NearestResponse.swift
//
// Generated by openapi-generator
// https://openapi-generator.tech
//

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

public struct NearestResponse: Codable, Hashable {
public enum Code: String, Codable, CaseIterable {
case ok = "Ok"
case invalidUrl = "InvalidUrl"
case invalidService = "InvalidService"
case invalidVersion = "InvalidVersion"
case invalidOptions = "InvalidOptions"
case invalidQuery = "InvalidQuery"
case invalidValue = "InvalidValue"
case noSegment = "NoSegment"
case tooBig = "TooBig"
case noRoute = "NoRoute"
case noTable = "NoTable"
case notImplemented = "NotImplemented"
case noTrips = "NoTrips"
}

public var code: Code
public var message: String?
public var dataVersion: Date?
public var waypoints: [NearestWaypoint]?

public init(code: Code, message: String? = nil, dataVersion: Date? = nil, waypoints: [NearestWaypoint]? = nil) {
self.code = code
self.message = message
self.dataVersion = dataVersion
self.waypoints = waypoints
}

public enum CodingKeys: String, CodingKey, CaseIterable {
case code
case message
case dataVersion = "data_version"
case waypoints
}

// Encodable protocol methods

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

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

public struct NearestWaypoint: Codable, Hashable {
public var name: String?
public var location: [Double]?
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) {
self.name = name
self.location = location
self.distance = distance
self.hint = hint
self.nodes = nodes
}

public enum CodingKeys: String, CodingKey, CaseIterable {
case name
case location
case distance
case hint
case nodes
}

// Encodable protocol methods

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.encodeIfPresent(hint, forKey: .hint)
try container.encodeIfPresent(nodes, forKey: .nodes)
}
}
Loading

0 comments on commit e906ef4

Please sign in to comment.