-
Notifications
You must be signed in to change notification settings - Fork 25
Closed
Description
Optional properties don't accept null values
Issue
The @Schemable macro generates schemas for optional properties (Int?, String?, etc.) that accept missing fields but reject explicit null values.
@Schemable
struct User {
let name: String
let age: Int?
}Works:
{"name": "Alice"}Fails:
{"name": "Alice", "age": null}Error: Type mismatch: the instance of type 'null' does not match the expected type 'integer'
Current Behavior
For let age: Int?, the macro generates:
JSONProperty(key: "age") {
JSONInteger() // Only accepts integers, rejects null
}
// Not required, so can be omittedExpected Behavior
Optional properties should accept both the unwrapped type and null values, since many APIs explicitly send null for absent values.
Possible Solutions
.orNull()modifier - Add a new modifier and apply to optionalsOneOfcomposition - Wrap optional types inOneOf([type, null])- Type array - Use
{"type": ["integer", "null"]}if supported
Which approach would you prefer? Happy to submit a PR.
ajevans99
Metadata
Metadata
Assignees
Labels
No labels