Skip to content

Commit 86cff2f

Browse files
committed
Support type: 'null' as OpenAPIValueContainer
1 parent 2520194 commit 86cff2f

File tree

4 files changed

+24
-4
lines changed

4 files changed

+24
-4
lines changed

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ let package = Package(
5252

5353
// Read OpenAPI documents
5454
.package(url: "https://github.com/mattpolzin/OpenAPIKit", from: "3.1.2"),
55-
.package(url: "https://github.com/jpsim/Yams", "4.0.0"..<"6.0.0"),
55+
.package(url: "https://github.com/jpsim/Yams", "5.1.0"..<"6.0.0"),
5656

5757
// CLI Tool
5858
.package(url: "https://github.com/apple/swift-argument-parser", from: "1.3.0"),

Sources/_OpenAPIGeneratorCore/Translator/TypeAssignment/TypeMatcher.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ struct TypeMatcher {
289289
private static func _tryMatchBuiltinNonRecursive(for schema: JSONSchema.Schema) -> TypeUsage? {
290290
let typeName: TypeName
291291
switch schema {
292+
case .null(_): typeName = TypeName.valueContainer
292293
case .boolean(_): typeName = .swift("Bool")
293294
case .number(let core, _):
294295
switch core.format {
@@ -331,7 +332,7 @@ struct TypeMatcher {
331332
// arrays are already recursed-into by _tryMatchTypeRecursive
332333
// so just return nil here
333334
return nil
334-
case .reference, .not, .all, .any, .one, .null:
335+
case .reference, .not, .all, .any, .one:
335336
// never built-in
336337
return nil
337338
}

Sources/_OpenAPIGeneratorCore/Translator/TypeAssignment/isSchemaSupported.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ extension FileTranslator {
132132
func isSchemaSupported(_ schema: JSONSchema, referenceStack: inout ReferenceStack) throws -> IsSchemaSupportedResult
133133
{
134134
switch schema.value {
135-
case .string, .integer, .number, .boolean,
135+
case .null, .string, .integer, .number, .boolean,
136136
// We mark any object as supported, even if it
137137
// has unsupported properties.
138138
// The code responsible for emitting an object is
@@ -173,7 +173,7 @@ extension FileTranslator {
173173
schemas.filter(\.isReference),
174174
referenceStack: &referenceStack
175175
)
176-
case .not, .null: return .unsupported(reason: .schemaType, schema: schema)
176+
case .not: return .unsupported(reason: .schemaType, schema: schema)
177177
}
178178
}
179179

Tests/OpenAPIGeneratorReferenceTests/SnippetBasedReferenceTests.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,25 @@ final class SnippetBasedReferenceTests: XCTestCase {
224224
)
225225
}
226226

227+
func testComponentsSchemasNull() throws {
228+
try self.assertSchemasTranslation(
229+
"""
230+
schemas:
231+
Null:
232+
type: "null"
233+
NullArray:
234+
type: array
235+
items:
236+
$ref: "#/components/schemas/Null"
237+
""",
238+
"""
239+
public enum Schemas {
240+
public typealias Null = OpenAPIRuntime.OpenAPIValueContainer
241+
public typealias NullArray = [Components.Schemas.Null]
242+
}
243+
""")
244+
}
245+
227246
func testComponentsSchemasNullableStringProperty() throws {
228247
try self.assertSchemasTranslation(
229248
"""

0 commit comments

Comments
 (0)