title | description |
---|---|
Forward compatibility |
SDKs that are fault-tolerant as your API evolves |
Fern SDKs are designed so that you can evolve your API without breaking users on legacy SDKs. You can safely add additional response properties, enum values, and union variants. The legacy SDKs will safely handle deserializing extra information.
### Additional Response Properties As you make new response properties available, the legacy SDKs will continue to work. For example, let's say you generated an SDK that had the following `Movie` object: ```ts export interface Movie { name: string; id: string; } ```If you decided to add a new genre
property on your server, the SDK will
simply pass the extra property back. Users would also be able to access
the property by doing
const genre = movie['genre'];
As you add additional enum properties on your server, the
legacy SDKs will continue to work. For example, let's say your generated SDK
had the following Genre
type:
export type Genre =
| "horror"
| "action"
| "thriller"
| "drama";
If you decided to add a new enum value comedy
, the SDK will simply pass
the string value back to the user. The consumer can then handle this case
in the default case of a switch statement.
switch(genre) {
case "horror":
case "action":
case "thriller":
case "drama":
default:
console.log(genre); // prints out comedy
}
Similar to additional enum properties, if you add additional union types
on your server, the legacy SDKs will continue to work. For example, let's say your
generated SDK had the following Shape
type:
export type Shape = Square | Circle;
export interface Circle {
type: "circle",
radius: number
}
export interface Square {
type: "square",
side: number
}
If you decided to add an additional union type called Triangle
+ export type Shape = Square | Circle | Triangle;
+ export interface Triangle {
+ type: "triangle",
+ a: number
+ b: number
+ c: number
+ }
then the user could simply handle the unknown case in their legacy SDK.
switch (type) {
case "circle":
...
case "square":
...
default:
console.log(type); // prints out triangle
}