Skip to content

Commit 611b6b6

Browse files
committed
readme: Add guidance on handling unknown API enum values
Fixes #1982.
1 parent 208ccff commit 611b6b6

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,27 @@ If passing explicit values in tests is cumbersome, a factory function
313313
in `test/example_data.dart` is an appropriate way to share defaults.
314314

315315

316+
#### Handle unknown enum values gracefully
317+
318+
When adding a new enum that appears in data received from the server
319+
(under `lib/api`), consider how the client should behave if the server
320+
sends an unknown value, generally representing a value that the server
321+
may start sending in a future version.
322+
323+
In most cases, the client should handle unknown values gracefully rather
324+
than rejecting the server response as malformed. A common pattern is to
325+
include an `unknown` enum value and parse unrecognized values into it.
326+
327+
Cases where we reject unknown values should be rare, and we should have
328+
a clear story for why that's appropriate. For example, the `type` field
329+
on a message (https://zulip.com/api/get-messages#response) is so
330+
fundamental to interpreting the rest of the data that the client cannot
331+
reasonably decide what to do with an unknown value. Another case is when
332+
the field represented by the enum is deprecated; in that case, future
333+
additions are unlikely, and so supporting an `unknown` value may not be
334+
worthwhile.
335+
336+
316337
#### Generated files
317338

318339
When editing any of the type definitions in our API, you'll need to

0 commit comments

Comments
 (0)