You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
docs: add documentation for nullable types and explicit null overrides
- Add nullable<T> to built-in types table
- Document the difference between optional and nullable
- Explain PATCH request semantics with explicit null values
- Provide TypeScript and Java SDK usage examples
- Document combining optional and nullable for three-state fields
This addresses the need to document explicit null overrides for APIs that
need to differentiate between omitted fields, explicit null values, and
actual values in PATCH requests.
Co-Authored-By: Devin Logan <[email protected]>
Understanding the difference between `optional` and `nullable` is important for properly modeling your API:
33
+
34
+
-**`optional<T>`**: The field can be omitted from the request/response entirely. When omitted, the field is not sent over the wire.
35
+
-**`nullable<T>`**: The field must be present but can be explicitly set to `null`. This allows you to distinguish between "not specified" and "explicitly cleared".
36
+
37
+
```yaml
38
+
types:
39
+
User:
40
+
properties:
41
+
name: string
42
+
nickname: optional<string> # Can be omitted entirely
43
+
bio: nullable<string> # Must be present, but can be null
44
+
```
45
+
46
+
This distinction is particularly important for PATCH requests where you need to differentiate between:
47
+
1. **Omitting a field** - Don't update this field (keep existing value)
48
+
2. **Setting to `null`** - Clear this field (remove the value)
49
+
3. **Setting to a value** - Update this field with a new value
50
+
51
+
#### Example: PATCH request semantics
52
+
53
+
```yaml
54
+
types:
55
+
UpdateUserRequest:
56
+
properties:
57
+
nickname: optional<string> # Omit to keep current nickname
58
+
bio: nullable<string> # Set to null to clear bio
59
+
```
60
+
61
+
**TypeScript SDK usage:**
62
+
```typescript
63
+
// Don't update nickname, clear bio
64
+
await client.users.update({
65
+
bio: null // Explicitly clear the bio field
66
+
// nickname is omitted, so it won't be updated
67
+
});
68
+
69
+
// Update both fields
70
+
await client.users.update({
71
+
nickname: "john_doe",
72
+
bio: "Software engineer"
73
+
});
74
+
```
75
+
76
+
**Java SDK usage:**
77
+
```java
78
+
// With collapse-optional-nullable config enabled
79
+
UpdateUserRequest.builder()
80
+
.nickname(Optional.empty()) // Omit field (don't update)
81
+
.bio(OptionalNullable.ofNull()) // Clear field (set to null)
82
+
.build();
83
+
84
+
UpdateUserRequest.builder()
85
+
.nickname(Optional.of("john_doe"))
86
+
.bio(OptionalNullable.of("Software engineer"))
87
+
.build();
88
+
```
89
+
90
+
### Combining optional and nullable
91
+
92
+
You can combine `optional` and `nullable` to create a field that can be omitted OR explicitly set to null:
0 commit comments