api-swift / Sources / IrdAPI / Core / Operation.swift
231 words
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import Foundation

public enum HTTPMethod: String, Sendable, Hashable, CaseIterable {
    case get = "GET", post = "POST", put = "PUT", patch = "PATCH", delete = "DELETE"
}

/// Which credentials an operation accepts, as declared by the spec.
public enum IrdSecurity: Sendable, Hashable {
    /// An API key or an account session (JWT).
    case keyOrJwt
    /// Only an account session; API keys answer 401.
    case jwtOnly
    /// No credentials; the client never sends its bearer.
    case anonymous
    /// Works without credentials; the bearer is sent when the client has one.
    case anonymousOrKey
}

/// One API operation: the spec's method and path template plus the client's name for it.
public struct IrdOperation: Sendable, Hashable {
    public let method: HTTPMethod
    public let pathTemplate: String
    public let module: String
    public let name: String
    public let security: IrdSecurity

    public init(method: HTTPMethod, pathTemplate: String, module: String, name: String, security: IrdSecurity) {
        self.method = method
        self.pathTemplate = pathTemplate
        self.module = module
        self.name = name
        self.security = security
    }

    /// `"METHOD /path/{template}"` — the key used by the domain gate and the coverage test.
    public var key: String { "\(method.rawValue) \(pathTemplate)" }
}

/// One query-string pair. Unset fields never become items, so nothing is dropped later.
public struct QueryItem: Sendable, Hashable {
    public let name: String
    public let value: String
    public init(_ name: String, _ value: String) { self.name = name; self.value = value }
}

static mirror of HEAD · about · clone: git clone https://ird.cod-sursa.ro/api-swift.git