Closed brandonbloom closed 3 months ago
I've been looking at this a little more and have narrowed the problem down to decodeIfPresent
for JSONType
. This is used in a few places (decodeNullable
and decodeTypes
) and behaves incorrectly for type: null
and type: 'null'
. Interestingly, container.contains(.type) ? container.decode(JSONType.self, forKey: .type) : nil
works as expected.
So this is actually related to a Yams bug that has been fixed as of version 5.1.0
of Yams. I had purposefully avoided writing a test for Yams decoding similar to the one you wrote because I knew it would not pass. Now that Yams 5.1.0
is released, it can be added (and passes): https://github.com/mattpolzin/OpenAPIKit/pull/365
Interestingly, the Yams fix also only works for Swift releases later than 5.4, it appears. A bit surprising. That means that I can't bump the locked version of Yams for the project prior to OpenAPIKit 4.0.0.
Here's a little more background: https://github.com/apple/swift-openapi-generator/issues/286#issuecomment-1749127706. In that comment, you can focus on the second paragraph where I explain and link to a Yams bug that describes the behavior you've described in the OP for this issue.
I see you came to the same conclusion as I was typing up my response!
Your PR looks good to me if you rebase it against release/4_0
.
Rebase: Done.
This test exists:
However, adding a similar test for Yaml highlights the bug:
In short,
nil
is returned, whenJSONType.null
is expected.