swift-openapi-generator icon indicating copy to clipboard operation
swift-openapi-generator copied to clipboard

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

Open brandonbloom opened this issue 1 year ago • 4 comments

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

  • Bumped minimum supported Yams version.
  • Returntrue from isSchemaSupported for type: 'null' schemas.
  • Defined .null to have a builtint ype of OpenAPIValueContainer

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.

brandonbloom avatar Mar 31 '24 21:03 brandonbloom

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.

czechboy0 avatar Apr 03 '24 13:04 czechboy0

We had a report that this is blocking generation for the Figma API: https://github.com/figma/rest-api-spec/blob/main/openapi/openapi.yaml, which I can confirm doesn't compile as-is.

simonjbeaumont avatar Sep 13 '24 10:09 simonjbeaumont

It would be great to get this merged as it unblocks using the Figma API as Simon mentions. Anything I can do to help?

Brett-Best avatar Sep 14 '24 09:09 Brett-Best

I think we can't merge it as-is, as it'd be an API break. Plus, see my earlier message, I think we should fix this slightly differently.

czechboy0 avatar Sep 16 '24 06:09 czechboy0