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
Copy file name to clipboardExpand all lines: fern/products/fern-def/pages/types.mdx
+148-1Lines changed: 148 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -278,4 +278,151 @@ interface Person {
278
278
age: number;
279
279
}
280
280
```
281
-
</CodeBlock>
281
+
</CodeBlock>
282
+
283
+
### Validating types
284
+
285
+
You can add validation constraints to your types (both aliases and references) to ensure data integrity. Validation constracts are automatically enforced in generated SDKs.
286
+
287
+
<CodeBlock title="Fern Definition">
288
+
```yaml {8-11, 15-17}
289
+
types:
290
+
Person:
291
+
docs: A person represents a human being
292
+
properties:
293
+
name:
294
+
docs: The person's full name
295
+
type: string
296
+
validation:
297
+
minLength: 2
298
+
maxLength: 100
299
+
pattern: "^[A-Za-z ]+$"
300
+
age:
301
+
docs: Age in years
302
+
type: integer
303
+
validation:
304
+
min: 0
305
+
max: 150
306
+
```
307
+
</CodeBlock>
308
+
<CodeBlock title="Generated TypeScript SDK from Fern Definition">
309
+
310
+
```typescript
311
+
interface Person {
312
+
/** The person's full name */
313
+
name: string;
314
+
/** Age in years */
315
+
age: number;
316
+
}
317
+
318
+
// Validation is automatically enforced when creating Person objects
0 commit comments