Skip to content

Commit ad847cb

Browse files
authored
[Runtime] Stop generating an undocumented case for enums/oneOfs (#40)
[Runtime] Stop generating an undocumented case for enums/oneOfs ### Motivation Runtime side of apple/swift-openapi-generator#205 ### Modifications Added a helper function that produces the right error. ### Result Generated code can use this error to throw when an unknown case is encountered. ### Test Plan Tested together with the generator. Reviewed by: glbrntt Builds: ✔︎ pull request validation (5.8) - Build finished. ✔︎ pull request validation (5.9) - Build finished. ✔︎ pull request validation (api breakage) - Build finished. ✔︎ pull request validation (docc test) - Build finished. ✔︎ pull request validation (integration test) - Build finished. ✔︎ pull request validation (nightly) - Build finished. ✔︎ pull request validation (soundness) - Build finished. #40
1 parent cd8104a commit ad847cb

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

Sources/OpenAPIRuntime/Conversion/ErrorExtensions.swift

+22
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,28 @@ extension DecodingError {
3535
)
3636
)
3737
}
38+
39+
/// Returns a decoding error used by the oneOf decoder when not a single
40+
/// child schema decodes the received payload.
41+
/// - Parameters:
42+
/// - type: The type representing the oneOf schema in which the decoding
43+
/// occurred.
44+
/// - codingPath: The coding path to the decoder that attempted to decode
45+
/// the type.
46+
/// - Returns: A decoding error.
47+
@_spi(Generated)
48+
public static func failedToDecodeOneOfSchema(
49+
type: Any.Type,
50+
codingPath: [any CodingKey]
51+
) -> Self {
52+
DecodingError.valueNotFound(
53+
type,
54+
DecodingError.Context.init(
55+
codingPath: codingPath,
56+
debugDescription: "The oneOf structure did not decode into any child schema."
57+
)
58+
)
59+
}
3860
}
3961

4062
@_spi(Generated)

0 commit comments

Comments
 (0)