Skip to content

Commit b0618e6

Browse files
committed
Condense further
1 parent 6f563df commit b0618e6

File tree

1 file changed

+46
-56
lines changed

1 file changed

+46
-56
lines changed

fern/products/fern-def/pages/types.mdx

Lines changed: 46 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -282,19 +282,56 @@ interface Person {
282282

283283
### Validating types
284284

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.
286286

287-
```yaml {4-6}
287+
<CodeBlock title="Fern Definition">
288+
```yaml {8-11, 15-17}
288289
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
294306
```
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
319+
const client = new YourApiClient();
320+
try {
321+
const person = await client.createPerson({
322+
name: "A", // Fails minLength validation
323+
age: -5, // Fails min validation
324+
});
325+
} catch (error) {
326+
if (error instanceof ValidationError) {
327+
console.log(`Validation failed: ${error.message}`);
328+
}
329+
}
330+
```
331+
</CodeBlock>
295332

296333
<AccordionGroup>
297-
<Accordion title="String validation">
334+
<Accordion title="String validation reference">
298335

299336
String types support several validation constraints.
300337

@@ -338,7 +375,7 @@ types:
338375
339376
</Accordion>
340377
341-
<Accordion title="Number validation">
378+
<Accordion title="Number validation reference">
342379
343380
Number types (including `integer`, `long`, and `double`) support several validation constraints.
344381

@@ -388,51 +425,4 @@ types:
388425
</Accordion>
389426
</AccordionGroup>
390427

391-
#### Validation in generated SDKs
392428

393-
When you add validation constraints to your Fern Definition, they are automatically enforced in generated SDKs:
394-
395-
<CodeBlock title="Fern Definition">
396-
```yaml {8-11, 15-17}
397-
types:
398-
Person:
399-
docs: A person represents a human being
400-
properties:
401-
name:
402-
docs: The person's full name
403-
type: string
404-
validation:
405-
minLength: 2
406-
maxLength: 100
407-
pattern: "^[A-Za-z ]+$"
408-
age:
409-
docs: Age in years
410-
type: integer
411-
validation:
412-
min: 0
413-
max: 150
414-
```
415-
</CodeBlock>
416-
<CodeBlock title="Generated TypeScript SDK from Fern Definition">
417-
```typescript
418-
interface Person {
419-
/** The person's full name */
420-
name: string;
421-
/** Age in years */
422-
age: number;
423-
}
424-
425-
// Validation is automatically enforced when creating Person objects
426-
const client = new YourApiClient();
427-
try {
428-
const person = await client.createPerson({
429-
name: "A", // Fails minLength validation
430-
age: -5, // Fails min validation
431-
});
432-
} catch (error) {
433-
if (error instanceof ValidationError) {
434-
console.log(`Validation failed: ${error.message}`);
435-
}
436-
}
437-
```
438-
</CodeBlock>

0 commit comments

Comments
 (0)