-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdto.schema.php
60 lines (57 loc) · 1.84 KB
/
dto.schema.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
use Klkvsk\DtoGenerator\Schema as dto;
use Klkvsk\DtoGenerator\Schema\Types as t;
$outputDir = getenv('OUTPUT_DIR') ?: null;
if ($outputDir) {
$outputDir = __DIR__ . DIRECTORY_SEPARATOR . $outputDir;
}
return dto\schema(
namespace: 'Klkvsk\\DtoGenerator\\Example\\One',
outputDir: $outputDir,
objects: [
dto\enum(
name: 'Genre',
cases: [
'romance',
'comedy',
'drama',
'non-fiction',
'scientific-work'
]
),
dto\object(
name: 'Author',
fields: [
dto\field('id', t\int(), required: true),
dto\field('firstName', t\string(), required: true,
filters: [ fn ($x) => trim($x), strval(...) ],
),
dto\field('lastName', t\string(),
filters: [ fn ($x) => trim($x) ],
validators: [
'tooShort' => fn ($x) => strlen($x) > 5,
'tooLong' => fn ($x) => strlen($x) < 40,
]
),
]
),
dto\object(
name: 'Book',
fields: [
dto\field('id', t\int(), required: true),
dto\field('title', t\string(), required: true),
dto\field('released', t\date(), deprecated: 'deprecation notice test'),
dto\field('author', t\object('Author'), required: true),
dto\field('rating', t\int(), default: 5),
dto\field('genres', t\list_(t\enum('Genre'))),
]
),
dto\object(
name: 'ScienceBook',
extends: 'Book',
fields: [
dto\field('references', t\list_(t\object('ScienceBook'))),
]
),
],
);