import Foundation
import Testing
@testable import IrdAPI
/// The vendored OpenAPI spec, located from this file (no second copy in the repo).
enum Spec {
static let url: URL = {
var u = URL(fileURLWithPath: #filePath)
for _ in 0..<4 { u.deleteLastPathComponent() } // Spec.swift → Helpers → IrdAPITests → Tests → repo root
return u.appendingPathComponent("spec/openapi.json")
}()
static let json: JSONValue = { try! JSONValue.parse(try! Data(contentsOf: url)) }()
static let methods: Set<String> = ["get", "post", "put", "patch", "delete"]
/// Every `"METHOD /path"` the spec declares.
static var operations: Set<String> {
var ops = Set<String>()
for (path, item) in json["paths"]?.objectValue ?? [:] {
for (method, _) in item.objectValue ?? [:] where methods.contains(method) {
ops.insert("\(method.uppercased()) \(path)")
}
}
return ops
}
/// The operation object for `"METHOD /path"`.
static func operation(_ key: String) -> JSONValue? {
let parts = key.split(separator: " ", maxSplits: 1).map(String.init)
guard parts.count == 2 else { return nil }
return json["paths"]?[parts[1]]?[parts[0].lowercased()]
}
}