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
+46-56Lines changed: 46 additions & 56 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -282,19 +282,56 @@ interface Person {
282
282
283
283
### Validating types
284
284
285
-
You can add validation constraints to your types (both aliases and references) to ensure data integrity and provide better error messages in generated SDKs:
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
286
287
-
```yaml {4-6}
287
+
<CodeBlock title="Fern Definition">
288
+
```yaml {8-11, 15-17}
288
289
types:
289
-
Sentence:
290
-
type: string
291
-
validation:
292
-
minLength: 4
293
-
maxLength: 256
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
294
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