Skip to content

Commit 1a08948

Browse files
committed
Update to allow API to strictly enforce environments.
This change means an API can choose to throw an error if the server is attempting to use a different environment.
1 parent 9e87ba6 commit 1a08948

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

Sources/ComposableArchitecturePattern/Server+API.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ public protocol ServerAPI: Identifiable, Equatable {
1616
var supportedHTTPMethods: [HTTPMethod] { get set }
1717
var supportedReturnObjects: [Codable.Type]? { get set }
1818
var timeoutInterval: TimeInterval { get set }
19+
/// Whether to block this API if the server is attempting to use a different environment.
20+
///
21+
/// For example, perhaps the server is using a specific environment but this API uses a different environment for some other purpose, such as a specific authentication endpoint. Setting this to `true` would mean that the API will throw an error if the environments don't match up.
22+
var strictEnvironmentEnforcement: Bool { get }
1923

2024
/// Initialize with the provided values.
2125
///
@@ -91,7 +95,7 @@ public extension ServerAPI {
9195
guard self.supportedHTTPMethods.contains(httpMethod) else {
9296
throw ServerAPIError.badRequest(description: "\(httpMethod.rawValue) is not supported for this API.")
9397
}
94-
if (self.environment != nil && environment != self.environment) {
98+
if self.strictEnvironmentEnforcement, (self.environment != nil && environment != self.environment) {
9599
throw ServerAPIError.badRequest(description: "API (\(self.id)) requires to use environment: \(self.environment?.description ?? "Unknown environment")")
96100
}
97101

0 commit comments

Comments
 (0)