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
@@ -15,7 +15,12 @@ The Schema Generator can also [be downloaded independently as a PHAR](https://gi
15
15
Start by browsing [Schema.org](https://schema.org) and pick types applicable to your application. The website provides
16
16
tons of schemas including (but not limited to) representations of people, organization, event, postal address, creative
17
17
work and e-commerce structures.
18
-
Then, write a simple YAML config file like the following (here we will generate a data model for an address book):
18
+
Then, write a simple YAML config file like the following.
19
+
20
+
Here we will generate a data model for an address book with these data:
21
+
22
+
- a [`Person`](http://schema.org/Person) which inherits from [`Thing`](http://schema.org/Thing)
23
+
- a [`PostalAddress`](http://schema.org/PostalAddress) which inherits from [`ContactPoint`](http://schema.org/ContactPoint), which inherits from [`StructuredValue`](http://schema.org/StructuredValue), etc.
19
24
20
25
```yaml
21
26
# api/config/schema.yaml
@@ -30,13 +35,7 @@ types:
30
35
familyName: ~
31
36
givenName: ~
32
37
additionalName: ~
33
-
gender: ~
34
38
address: ~
35
-
birthDate: ~
36
-
telephone: ~
37
-
email: ~
38
-
url: ~
39
-
jobTitle: ~
40
39
PostalAddress:
41
40
# Disable the generation of the class hierarchy for this type
42
41
parent: false
@@ -64,13 +63,7 @@ types:
64
63
familyName: ~
65
64
givenName: ~
66
65
additionalName: ~
67
-
gender: ~
68
66
address: ~
69
-
birthDate: ~
70
-
telephone: ~
71
-
email: ~
72
-
url: ~
73
-
jobTitle: ~
74
67
PostalAddress:
75
68
properties:
76
69
# Force the type of the addressCountry property to text
@@ -92,7 +85,6 @@ namespace App\Entity;
92
85
use ApiPlatform\Core\Annotation\ApiProperty;
93
86
use ApiPlatform\Core\Annotation\ApiResource;
94
87
use Doctrine\ORM\Mapping as ORM;
95
-
use Symfony\Component\Validator\Constraints as Assert;
96
88
97
89
/**
98
90
* A person (alive, dead, undead, or fictional).
@@ -113,14 +105,6 @@ class Person
113
105
*/
114
106
private $id;
115
107
116
-
/**
117
-
* @var string|null the name of the item
118
-
*
119
-
* @ORM\Column(type="text", nullable=true)
120
-
* @ApiProperty(iri="http://schema.org/name")
121
-
*/
122
-
private $name;
123
-
124
108
/**
125
109
* @var string|null Family name. In the U.S., the last name of an Person. This can be used along with givenName instead of the name property.
126
110
*
@@ -145,14 +129,6 @@ class Person
145
129
*/
146
130
private $additionalName;
147
131
148
-
/**
149
-
* @var string|null Gender of the person. While http://schema.org/Male and http://schema.org/Female may be used, text strings are also acceptable for people who do not identify as a binary gender.
150
-
*
151
-
* @ORM\Column(type="text", nullable=true)
152
-
* @ApiProperty(iri="http://schema.org/gender")
153
-
*/
154
-
private $gender;
155
-
156
132
/**
157
133
* @var PostalAddress|null physical address of the item
158
134
*
@@ -161,64 +137,11 @@ class Person
161
137
*/
162
138
private $address;
163
139
164
-
/**
165
-
* @var \DateTimeInterface|null date of birth
166
-
*
167
-
* @ORM\Column(type="date", nullable=true)
168
-
* @ApiProperty(iri="http://schema.org/birthDate")
169
-
* @Assert\Date
170
-
*/
171
-
private $birthDate;
172
-
173
-
/**
174
-
* @var string|null the telephone number
175
-
*
176
-
* @ORM\Column(type="text", nullable=true)
177
-
* @ApiProperty(iri="http://schema.org/telephone")
178
-
*/
179
-
private $telephone;
180
-
181
-
/**
182
-
* @var string|null email address
183
-
*
184
-
* @ORM\Column(type="text", nullable=true)
185
-
* @ApiProperty(iri="http://schema.org/email")
186
-
* @Assert\Email
187
-
*/
188
-
private $email;
189
-
190
-
/**
191
-
* @var string|null URL of the item
192
-
*
193
-
* @ORM\Column(type="text", nullable=true)
194
-
* @ApiProperty(iri="http://schema.org/url")
195
-
* @Assert\Url
196
-
*/
197
-
private $url;
198
-
199
-
/**
200
-
* @var string|null the job title of the person (for example, Financial Manager)
201
-
*
202
-
* @ORM\Column(type="text", nullable=true)
203
-
* @ApiProperty(iri="http://schema.org/jobTitle")
204
-
*/
205
-
private $jobTitle;
206
-
207
140
public function getId(): ?int
208
141
{
209
142
return $this->id;
210
143
}
211
144
212
-
public function setName(?string $name): void
213
-
{
214
-
$this->name = $name;
215
-
}
216
-
217
-
public function getName(): ?string
218
-
{
219
-
return $this->name;
220
-
}
221
-
222
145
public function setFamilyName(?string $familyName): void
223
146
{
224
147
$this->familyName = $familyName;
@@ -249,16 +172,6 @@ class Person
249
172
return $this->additionalName;
250
173
}
251
174
252
-
public function setGender(?string $gender): void
253
-
{
254
-
$this->gender = $gender;
255
-
}
256
-
257
-
public function getGender(): ?string
258
-
{
259
-
return $this->gender;
260
-
}
261
-
262
175
public function setAddress(?PostalAddress $address): void
263
176
{
264
177
$this->address = $address;
@@ -268,56 +181,6 @@ class Person
268
181
{
269
182
return $this->address;
270
183
}
271
-
272
-
public function setBirthDate(?\DateTimeInterface $birthDate): void
273
-
{
274
-
$this->birthDate = $birthDate;
275
-
}
276
-
277
-
public function getBirthDate(): ?\DateTimeInterface
278
-
{
279
-
return $this->birthDate;
280
-
}
281
-
282
-
public function setTelephone(?string $telephone): void
283
-
{
284
-
$this->telephone = $telephone;
285
-
}
286
-
287
-
public function getTelephone(): ?string
288
-
{
289
-
return $this->telephone;
290
-
}
291
-
292
-
public function setEmail(?string $email): void
293
-
{
294
-
$this->email = $email;
295
-
}
296
-
297
-
public function getEmail(): ?string
298
-
{
299
-
return $this->email;
300
-
}
301
-
302
-
public function setUrl(?string $url): void
303
-
{
304
-
$this->url = $url;
305
-
}
306
-
307
-
public function getUrl(): ?string
308
-
{
309
-
return $this->url;
310
-
}
311
-
312
-
public function setJobTitle(?string $jobTitle): void
313
-
{
314
-
$this->jobTitle = $jobTitle;
315
-
}
316
-
317
-
public function getJobTitle(): ?string
318
-
{
319
-
return $this->jobTitle;
320
-
}
321
184
}
322
185
```
323
186
@@ -466,6 +329,61 @@ class PostalAddress
466
329
}
467
330
```
468
331
332
+
```php
333
+
<?php
334
+
335
+
declare(strict_types=1);
336
+
337
+
namespace App\Entity;
338
+
339
+
use ApiPlatform\Core\Annotation\ApiProperty;
340
+
use ApiPlatform\Core\Annotation\ApiResource;
341
+
use Doctrine\ORM\Mapping as ORM;
342
+
343
+
/**
344
+
* The most generic type of item.
345
+
*
346
+
* @see http://schema.org/Thing Documentation on Schema.org
347
+
*
348
+
* @ORM\Entity
349
+
* @ApiResource(iri="http://schema.org/Thing")
350
+
*/
351
+
class Thing
352
+
{
353
+
/**
354
+
* @var int|null
355
+
*
356
+
* @ORM\Id
357
+
* @ORM\GeneratedValue(strategy="AUTO")
358
+
* @ORM\Column(type="integer")
359
+
*/
360
+
private $id;
361
+
362
+
/**
363
+
* @var string|null the name of the item
364
+
*
365
+
* @ORM\Column(type="text", nullable=true)
366
+
* @ApiProperty(iri="http://schema.org/name")
367
+
*/
368
+
private $name;
369
+
370
+
public function getId(): ?int
371
+
{
372
+
return $this->id;
373
+
}
374
+
375
+
public function setName(?string $name): void
376
+
{
377
+
$this->name = $name;
378
+
}
379
+
380
+
public function getName(): ?string
381
+
{
382
+
return $this->name;
383
+
}
384
+
}
385
+
```
386
+
469
387
Note that the generator takes care of creating directories corresponding to the namespace structure.
470
388
471
389
Without configuration file, the tool will build the entire Schema.org vocabulary. If no properties are specified for a given
0 commit comments