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

Sources/OpenAPIKit/JSONReference.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ extension JSONReference: Decodable {
461461

462462
if referenceString.first == "#" {
463463
guard let internalReference = InternalReference(rawValue: referenceString) else {
464-
throw InconsistencyError(
464+
throw GenericError(
465465
subjectName: "JSON Reference",
466466
details: "Failed to parse a JSON Reference from '\(referenceString)'",
467467
codingPath: container.codingPath
@@ -482,7 +482,7 @@ extension JSONReference: Decodable {
482482
externalReference = URL(string: referenceString)
483483
#endif
484484
guard let externalReference else {
485-
throw InconsistencyError(
485+
throw GenericError(
486486
subjectName: "JSON Reference",
487487
details: "Failed to parse a valid URI for a JSON Reference from '\(referenceString)'",
488488
codingPath: container.codingPath

Sources/OpenAPIKit/Operation/Operation.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ extension OpenAPI.Operation: Decodable {
336336
} catch let error as DecodingError {
337337

338338
throw OpenAPI.Error.Decoding.Operation(unwrapping: error)
339-
} catch let error as InconsistencyError {
339+
} catch let error as GenericError {
340340

341341
throw OpenAPI.Error.Decoding.Operation(error)
342342
} catch let error as EitherDecodeNoTypesMatchedError {

Sources/OpenAPIKit/Parameter/Parameter.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ extension OpenAPI.Parameter: Decodable {
298298
context = .header(required: required)
299299
case .path:
300300
if !required {
301-
throw InconsistencyError(
301+
throw GenericError(
302302
subjectName: name,
303303
details: "positional path parameters must be explicitly set to required",
304304
codingPath: decoder.codingPath
@@ -324,13 +324,13 @@ extension OpenAPI.Parameter: Decodable {
324324
case (nil, let schema?):
325325
schemaOrContent = .init(schema)
326326
case (nil, nil):
327-
throw InconsistencyError(
327+
throw GenericError(
328328
subjectName: name,
329329
details: "A parameter must specify either `content` or `schema`",
330330
codingPath: decoder.codingPath
331331
)
332332
case (_, _):
333-
throw InconsistencyError(
333+
throw GenericError(
334334
subjectName: name,
335335
details: "A parameter must specify one but not both `content` and `schema`",
336336
codingPath: decoder.codingPath

Sources/OpenAPIKit/Path Item/PathItem.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ extension OpenAPI.PathItem: Decodable {
286286
} catch let error as DecodingError {
287287

288288
throw OpenAPI.Error.Decoding.Path(error)
289-
} catch let error as InconsistencyError {
289+
} catch let error as GenericError {
290290

291291
throw OpenAPI.Error.Decoding.Path(error)
292292
} catch let error as OpenAPI.Error.Decoding.Operation {

Sources/OpenAPIKit/Request/Request.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ extension OpenAPI.Request: Decodable {
123123
required = try container.decodeIfPresent(Bool.self, forKey: .required) ?? false
124124

125125
vendorExtensions = try Self.extensions(from: decoder)
126-
} catch let error as InconsistencyError {
126+
} catch let error as GenericError {
127127

128128
throw OpenAPI.Error.Decoding.Request(error)
129129
} catch let error as Swift.DecodingError {

Sources/OpenAPIKit/Response/Response.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ extension OpenAPI.Response: Decodable {
186186

187187
vendorExtensions = try Self.extensions(from: decoder)
188188

189-
} catch let error as InconsistencyError {
189+
} catch let error as GenericError {
190190

191191
throw OpenAPI.Error.Decoding.Response(error)
192192
} catch let error as EitherDecodeNoTypesMatchedError {

Sources/OpenAPIKit/Schema Object/JSONSchema.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2049,7 +2049,7 @@ extension JSONSchema: Decodable {
20492049
if keysFrom.count > 1 {
20502050
_warnings.append(
20512051
.underlyingError(
2052-
InconsistencyError(
2052+
GenericError(
20532053
subjectName: "Schema",
20542054
details: "A schema contains properties for multiple types of schemas, namely: \(keysFrom).",
20552055
codingPath: decoder.codingPath
@@ -2066,7 +2066,7 @@ extension JSONSchema: Decodable {
20662066
if !keysFromElsewhere.isEmpty {
20672067
_warnings.append(
20682068
.underlyingError(
2069-
InconsistencyError(
2069+
GenericError(
20702070
subjectName: "OpenAPI Schema",
20712071
details: "Found schema attributes not consistent with the type specified: \(typeHint). Specifically, attributes for these other types: \(keysFromElsewhere)",
20722072
codingPath: decoder.codingPath
@@ -2124,7 +2124,7 @@ extension JSONSchema: Decodable {
21242124
if fragmentContext.isEmpty && hintContainerCount > 0 {
21252125
_warnings.append(
21262126
.underlyingError(
2127-
InconsistencyError(
2127+
GenericError(
21282128
subjectName: "OpenAPI Schema",
21292129
details: "Found nothing but unsupported attributes.",
21302130
codingPath: decoder.codingPath

Sources/OpenAPIKit/Schema Object/JSONSchemaContext.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -987,7 +987,7 @@ extension JSONSchema.CoreContext: Decodable {
987987
case (true, false):
988988
_permissions = .readOnly
989989
case (true, true):
990-
throw InconsistencyError(
990+
throw GenericError(
991991
subjectName: "JSONSchema",
992992
details: "Either `readOnly` or `writeOnly` can be true but not both",
993993
codingPath: decoder.codingPath
@@ -1033,7 +1033,7 @@ extension JSONSchema.CoreContext: Decodable {
10331033
nullable = _nullable
10341034
warnings.append(
10351035
.underlyingError(
1036-
InconsistencyError(
1036+
GenericError(
10371037
subjectName: "OpenAPI Schema",
10381038
details: "Found 'nullable' property. This property is not supported by OpenAPI v3.1.x. OpenAPIKit has translated it into 'type: [\"null\", ...]'.",
10391039
codingPath: container.codingPath
@@ -1167,7 +1167,7 @@ extension JSONSchema.IntegerContext: Decodable {
11671167
let value = try intAttempt
11681168
?? doubleAttempt.map { floatVal in
11691169
guard let integer = Int(exactly: floatVal) else {
1170-
throw InconsistencyError(
1170+
throw GenericError(
11711171
subjectName: max ? "maximum" : "minimum",
11721172
details: "Expected an Integer literal but found a floating point value (\(String(describing: floatVal)))",
11731173
codingPath: decoder.codingPath,

Sources/OpenAPIKit/Utility/Container+DecodeURLAsString.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ extension KeyedDecodingContainerProtocol {
2424
url = URL(string: string)
2525
#endif
2626
guard let url else {
27-
throw InconsistencyError(
27+
throw GenericError(
2828
subjectName: key.stringValue,
2929
details: "If specified, must be a valid URL",
3030
codingPath: codingPath
@@ -51,7 +51,7 @@ extension KeyedDecodingContainerProtocol {
5151
url = URL(string: string)
5252
#endif
5353
guard let url else {
54-
throw InconsistencyError(
54+
throw GenericError(
5555
subjectName: key.stringValue,
5656
details: "If specified, must be a valid URL",
5757
codingPath: codingPath

Sources/OpenAPIKit30/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/OpenAPIKit30/Components Object/Components.swift

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

Sources/OpenAPIKit30/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/OpenAPIKit30/Document/Document.swift

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

524524
throw OpenAPI.Error.Decoding.Document(error)
525-
} catch let error as InconsistencyError {
525+
} catch let error as GenericError {
526526

527527
throw OpenAPI.Error.Decoding.Document(error)
528528
} catch let error as DecodingError {
@@ -651,7 +651,7 @@ internal func decodeSecurityRequirements<CodingKeys: CodingKey>(from container:
651651
return (try? components.contains(ref)) ?? false
652652
}
653653
guard securityKeysAndValues.map({ $0.key }).allSatisfy(foundInComponents) else {
654-
throw InconsistencyError(
654+
throw GenericError(
655655
subjectName: key.stringValue,
656656
details: "Each key found in a Security Requirement dictionary must refer to a Security Scheme present in the Components dictionary",
657657
codingPath: container.codingPath + [key]
@@ -700,7 +700,7 @@ internal func validate(securityRequirements: [OpenAPI.SecurityRequirement], at p
700700
]
701701
.map(AnyCodingKey.init(stringValue:))
702702

703-
throw InconsistencyError(
703+
throw GenericError(
704704
subjectName: schemeKey,
705705
details: "Each key found in a Security Requirement dictionary must refer to a Security Scheme present in the Components dictionary",
706706
codingPath: keys

0 commit comments

Comments
 (0)