Skip to content

Commit 15147d8

Browse files
authored
Merge pull request #408 from mattpolzin/update-error-phrasing
Update inconsistency error to be better suited to general use
2 parents 04391a3 + 35f095a commit 15147d8

File tree

79 files changed

+167
-159
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+167
-159
lines changed

Sources/OpenAPIKit/CodableVendorExtendable.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ extension CodableVendorExtendable {
111111
let invalidKeys = extensions.keys.filter { !$0.lowercased().starts(with: "x-") }
112112
if !invalidKeys.isEmpty {
113113
let invalidKeysList = "[ " + invalidKeys.joined(separator: ", ") + " ]"
114-
throw InconsistencyError(
114+
throw GenericError(
115115
subjectName: "Vendor Extension",
116116
details: "Found at least one vendor extension property that does not begin with the required 'x-' prefix. Invalid properties: \(invalidKeysList)",
117117
codingPath: decoder.codingPath

Sources/OpenAPIKit/Components Object/Components.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ extension OpenAPI.Components: Decodable {
220220
vendorExtensions = try Self.extensions(from: decoder)
221221
} catch let error as DecodingError {
222222
if let underlyingError = error.underlyingError as? KeyDecodingError {
223-
throw InconsistencyError(
223+
throw GenericError(
224224
subjectName: error.subjectName,
225225
details: underlyingError.localizedDescription,
226226
codingPath: error.codingPath

Sources/OpenAPIKit/Content/Content.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ extension OpenAPI.Content: Decodable {
172172
let container = try decoder.container(keyedBy: CodingKeys.self)
173173

174174
guard !(container.contains(.examples) && container.contains(.example)) else {
175-
throw InconsistencyError(
175+
throw GenericError(
176176
subjectName: "Example and Examples",
177177
details: "Only one of `example` and `examples` is allowed in the Media Type Object (`OpenAPI.Content`).",
178178
codingPath: container.codingPath

Sources/OpenAPIKit/Document/Document.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ extension OpenAPI.Document: Decodable {
538538
} catch let error as OpenAPI.Error.Decoding.Path {
539539

540540
throw OpenAPI.Error.Decoding.Document(error)
541-
} catch let error as InconsistencyError {
541+
} catch let error as GenericError {
542542

543543
throw OpenAPI.Error.Decoding.Document(error)
544544
} catch let error as DecodingError {
@@ -679,7 +679,7 @@ internal func decodeSecurityRequirements<CodingKeys: CodingKey>(from container:
679679
return (try? components.contains(ref)) ?? false
680680
}
681681
guard securityKeysAndValues.map({ $0.key }).allSatisfy(foundInComponents) else {
682-
throw InconsistencyError(
682+
throw GenericError(
683683
subjectName: key.stringValue,
684684
details: "Each key found in a Security Requirement dictionary must refer to a Security Scheme present in the Components dictionary",
685685
codingPath: container.codingPath + [key]
@@ -728,7 +728,7 @@ internal func validate(securityRequirements: [OpenAPI.SecurityRequirement], at p
728728
]
729729
.map(AnyCodingKey.init(stringValue:))
730730

731-
throw InconsistencyError(
731+
throw GenericError(
732732
subjectName: schemeKey,
733733
details: "Each key found in a Security Requirement dictionary must refer to a Security Scheme present in the Components dictionary",
734734
codingPath: keys

Sources/OpenAPIKit/Encoding and Decoding Errors/DocumentDecodingError.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ extension OpenAPI.Error.Decoding {
1414

1515
public enum Context: Sendable {
1616
case path(Path)
17-
case inconsistency(InconsistencyError)
17+
case inconsistency(GenericError)
1818
case other(Swift.DecodingError)
1919
case neither(EitherDecodeNoTypesMatchedError)
2020
}
@@ -82,7 +82,7 @@ extension OpenAPI.Error.Decoding.Document {
8282
codingPath = error.codingPath
8383
}
8484

85-
internal init(_ error: InconsistencyError) {
85+
internal init(_ error: GenericError) {
8686
context = .inconsistency(error)
8787
codingPath = error.codingPath
8888
}
@@ -107,7 +107,7 @@ extension OpenAPI.Error.Decoding.Document: DiggingError {
107107
public init(unwrapping error: Swift.DecodingError) {
108108
if let decodingError = error.underlyingError as? Swift.DecodingError {
109109
self = Self(unwrapping: decodingError)
110-
} else if let inconsistencyError = error.underlyingError as? InconsistencyError {
110+
} else if let inconsistencyError = error.underlyingError as? GenericError {
111111
self = Self(inconsistencyError)
112112
} else if let pathError = error.underlyingError as? OpenAPI.Error.Decoding.Path {
113113
self = Self(pathError)

Sources/OpenAPIKit/Encoding and Decoding Errors/OperationDecodingError.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ extension OpenAPI.Error.Decoding {
1616
public enum Context: Sendable {
1717
case request(Request)
1818
case response(Response)
19-
case inconsistency(InconsistencyError)
19+
case inconsistency(GenericError)
2020
case other(Swift.DecodingError)
2121
case neither(EitherDecodeNoTypesMatchedError)
2222
}
@@ -95,7 +95,7 @@ extension OpenAPI.Error.Decoding.Operation {
9595
relativeCodingPath = Array(codingPath)
9696
}
9797

98-
internal init(_ error: InconsistencyError) {
98+
internal init(_ error: GenericError) {
9999
var codingPath = error.codingPath.dropFirst(2)
100100
// this part of the coding path is structurally guaranteed to be an HTTP verb.
101101
let verb = OpenAPI.HttpMethod(rawValue: codingPath.removeFirst().stringValue.uppercased())!
@@ -139,7 +139,7 @@ extension OpenAPI.Error.Decoding.Operation: DiggingError {
139139
self = Self(responseError)
140140
} else if let responseError = error.underlyingError as? OpenAPI.Error.Decoding.Response {
141141
self = Self(responseError)
142-
} else if let inconsistencyError = error.underlyingError as? InconsistencyError {
142+
} else if let inconsistencyError = error.underlyingError as? GenericError {
143143
self = Self(inconsistencyError)
144144
} else if let eitherError = error.underlyingError as? EitherDecodeNoTypesMatchedError {
145145
self = Self(eitherError)

Sources/OpenAPIKit/Encoding and Decoding Errors/PathDecodingError.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ extension OpenAPI.Error.Decoding {
1515

1616
public enum Context: Sendable {
1717
case endpoint(Operation)
18-
case inconsistency(InconsistencyError)
18+
case inconsistency(GenericError)
1919
case other(Swift.DecodingError)
2020
case neither(EitherDecodeNoTypesMatchedError)
2121
}
@@ -120,7 +120,7 @@ extension OpenAPI.Error.Decoding.Path {
120120
relativeCodingPath = Array(codingPath)
121121
}
122122

123-
internal init(_ error: InconsistencyError) {
123+
internal init(_ error: GenericError) {
124124
var codingPath = error.codingPath.dropFirst()
125125
let route = OpenAPI.Path(rawValue: codingPath.removeFirst().stringValue)
126126

@@ -165,7 +165,7 @@ extension OpenAPI.Error.Decoding.Path {
165165
// public init(unwrapping error: Swift.DecodingError) {
166166
// if let decodingError = error.underlyingError as? Swift.DecodingError {
167167
// self = Self(unwrapping: decodingError)
168-
// } else if let inconsistencyError = error.underlyingError as? InconsistencyError {
168+
// } else if let inconsistencyError = error.underlyingError as? GenericError {
169169
// self = Self(inconsistencyError)
170170
// } else if let eitherError = error.underlyingError as? EitherDecodeNoTypesMatchedError {
171171
// self = Self(eitherError)

Sources/OpenAPIKit/Encoding and Decoding Errors/ResponseDecodingError.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ extension OpenAPI.Error.Decoding {
1414
internal let relativeCodingPath: [CodingKey]
1515

1616
public enum Context: Sendable {
17-
case inconsistency(InconsistencyError)
17+
case inconsistency(GenericError)
1818
case other(Swift.DecodingError)
1919
case neither(EitherDecodeNoTypesMatchedError)
2020
}
@@ -68,7 +68,7 @@ extension OpenAPI.Error.Decoding.Response {
6868
return Array(path.dropFirst(responsesIndex.advanced(by: 1)))
6969
}
7070

71-
internal init(_ error: InconsistencyError) {
71+
internal init(_ error: GenericError) {
7272
var codingPath = Self.relativePath(from: error.codingPath)
7373
let code = codingPath.removeFirst().stringValue.lowercased()
7474

@@ -114,7 +114,7 @@ extension OpenAPI.Error.Decoding.Response: DiggingError {
114114
public init(unwrapping error: Swift.DecodingError) {
115115
if let decodingError = error.underlyingError as? Swift.DecodingError {
116116
self = Self(unwrapping: decodingError)
117-
} else if let inconsistencyError = error.underlyingError as? InconsistencyError {
117+
} else if let inconsistencyError = error.underlyingError as? GenericError {
118118
self = Self(inconsistencyError)
119119
} else if let eitherError = error.underlyingError as? EitherDecodeNoTypesMatchedError {
120120
self = Self(eitherError)

Sources/OpenAPIKit/Example.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ extension OpenAPI.Example: Decodable {
117117
let container = try decoder.container(keyedBy: CodingKeys.self)
118118

119119
guard !(container.contains(.externalValue) && container.contains(.value)) else {
120-
throw InconsistencyError(
120+
throw GenericError(
121121
subjectName: "example value",
122122
details: "Found both `value` and `externalValue` keys in an Example. You must specify one or the other.",
123123
codingPath: container.codingPath

Sources/OpenAPIKit/Header/Header.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,13 +316,13 @@ extension OpenAPI.Header: Decodable {
316316
case (nil, let schema?):
317317
schemaOrContent = .init(schema)
318318
case (nil, nil):
319-
throw InconsistencyError(
319+
throw GenericError(
320320
subjectName: "Header",
321321
details: "A header parameter must specify either `content` or `schema`",
322322
codingPath: decoder.codingPath
323323
)
324324
case (_, _):
325-
throw InconsistencyError(
325+
throw GenericError(
326326
subjectName: "Header",
327327
details: "A header must specify one but not both `content` and `schema`",
328328
codingPath: decoder.codingPath

0 commit comments

Comments
 (0)