Skip to content

Commit a0df460

Browse files
authored
Allow refs to oneOf/anyOf inside a oneOf with a discriminator (#224)
Allow refs to oneOf/anyOf inside a oneOf with a discriminator ### Motivation Fixes #222. We had a bug, where we considered oneOf/anyOf nested within a oneOf with a discriminator as not supported. We already allowed allOf in there, but it was an oversight to disallow oneOf/anyOf there. ### Modifications Update the isSupported logic to allow oneOf and anyOf within such oneOfs with a discriminator. Note that the nested schemas _within_ the oneOf/anyOf still must be objectish, as oneOf + discriminator always represent a JSON object. ### Result OpenAPI docs with this nesting won't skip such schemas anymore. ### Test Plan Updated the unit test. Reviewed by: glbrntt Builds: ✔︎ pull request validation (5.8) - Build finished. ✔︎ pull request validation (5.9) - 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. #224
1 parent d2dbd0d commit a0df460

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

Sources/_OpenAPIGeneratorCore/Translator/TypeAssignment/isSchemaSupported.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ extension FileTranslator {
212212
switch schema.value {
213213
case .object, .reference:
214214
return try isSchemaSupported(schema)
215-
case .all(of: let schemas, _):
215+
case .all(of: let schemas, _), .any(of: let schemas, _), .one(of: let schemas, _):
216216
return try areSchemasSupported(schemas)
217217
default:
218218
return .unsupported(

Tests/OpenAPIGeneratorCoreTests/Translator/TypeAssignment/Test_isSchemaSupported.swift

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,15 @@ class Test_isSchemaSupported: XCTestCase {
2525
"Foo": .string,
2626
"MyObj": .object,
2727
"MyObj2": .object,
28+
"MyNestedObjectishOneOf": .one(of: [
29+
.object(properties: ["foo": .string])
30+
]),
31+
"MyNestedAllOf": .all(of: [
32+
.object(properties: ["foo": .string])
33+
]),
34+
"MyNestedAnyOf": .any(of: [
35+
.object(properties: ["foo": .string])
36+
]),
2837
])
2938
)
3039
}
@@ -71,10 +80,14 @@ class Test_isSchemaSupported: XCTestCase {
7180
.array(items: .string),
7281
]),
7382

74-
// oneOf with a discriminator with two objectish schemas and two (ignored) inline schemas
83+
// oneOf with a discriminator with a few objectish schemas and two (ignored) inline schemas
7584
.one(
7685
of: .reference(.component(named: "MyObj")),
7786
.reference(.component(named: "MyObj2")),
87+
.reference(.component(named: "MyNestedAllOf")),
88+
.reference(.component(named: "MyNestedAnyOf")),
89+
.reference(.component(named: "MyNestedObjectishOneOf")),
90+
7891
.object,
7992
.boolean,
8093
discriminator: .init(propertyName: "foo")

0 commit comments

Comments
 (0)