apple / swift-openapi-generator

Generate Swift client and server code from an OpenAPI document.
https://swiftpackageindex.com/apple/swift-openapi-generator/documentation
Apache License 2.0
1.21k stars 87 forks source link

Support `type: 'null'` as `OpenAPIValueContainer` #557

Open brandonbloom opened 1 month ago

brandonbloom commented 1 month ago

Motivation

OpenAPIKit's handling of type: 'null' was problematic with older Yams versions. See https://github.com/mattpolzin/OpenAPIKit/pull/366/files for a test demonstrating that & dependency version bump.

Similarly, swift-openapi-generator explicitly does not "support" type: 'null'. As part of searching for something to address https://github.com/apple/swift-openapi-generator/issues/513 I have added such support for explicit nulls. This gives one more sort of input schema where swift-openapi-generator produces some useful output instead of skipping a schema.

Modifications

Result

Nothing should change for existing users because type: null schemas were previously unsupported. Going forward, usages of these schemas is supported.

Test Plan

New test included.

czechboy0 commented 1 month ago

Based on the discussion in the other thread, I think we should not merge this PR, and instead we should simply filter out null from anyOf/allOf schemas, as OpenAPIKit will already represent the nullability on the parent schema.