Skip to content

Incorrect decoding of type: null from Yaml #364

Closed
@brandonbloom

Description

@brandonbloom

This test exists:

    func test_decodeNullType() throws {
        let nullTypeData = """
        {
          "type": "null"
        }
        """.data(using: .utf8)!

        let decoded = try orderUnstableDecode(JSONSchema.self, from: nullTypeData)

        XCTAssertEqual(decoded, .null())
    }

However, adding a similar test for Yaml highlights the bug:

diff --git a/Tests/OpenAPIKitTests/Schema Object/SchemaObjectYamsTests.swift b/Tests/OpenAPIKitTests/Schema Object/SchemaObjectYamsTests.swift
index 12c7c10c..1d32f5d7 100644
--- a/Tests/OpenAPIKitTests/Schema Object/SchemaObjectYamsTests.swift   
+++ b/Tests/OpenAPIKitTests/Schema Object/SchemaObjectYamsTests.swift   
@@ -16,6 +16,20 @@ import OpenAPIKit
 import Yams
 
 final class SchemaObjectYamsTests: XCTestCase {
+    func test_nullTypeDecode() throws {
+        let nullString =
+        """
+        type: 'null'
+        """
+
+        let null = try YAMLDecoder().decode(JSONSchema.self, from: nullString)
+
+        XCTAssertEqual(
+            null,
+            JSONSchema.null()
+        )
+    }
+
     func test_floatingPointWholeNumberIntegerDecode() throws {
         let integerString =
         """

In short, nil is returned, when JSONType.null is expected.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions