Skip to content

Commit ad1666e

Browse files
authored
Merge pull request #443 from alexislefebvre/442-schema-generator-improve-getting-started
“Schema generator“ > improve “Getting started”
2 parents 7e296b4 + e3a2960 commit ad1666e

File tree

1 file changed

+61
-143
lines changed

1 file changed

+61
-143
lines changed

schema-generator/getting-started.md

Lines changed: 61 additions & 143 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@ The Schema Generator can also [be downloaded independently as a PHAR](https://gi
1515
Start by browsing [Schema.org](https://schema.org) and pick types applicable to your application. The website provides
1616
tons of schemas including (but not limited to) representations of people, organization, event, postal address, creative
1717
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.
1924

2025
```yaml
2126
# api/config/schema.yaml
@@ -30,13 +35,7 @@ types:
3035
familyName: ~
3136
givenName: ~
3237
additionalName: ~
33-
gender: ~
3438
address: ~
35-
birthDate: ~
36-
telephone: ~
37-
email: ~
38-
url: ~
39-
jobTitle: ~
4039
PostalAddress:
4140
# Disable the generation of the class hierarchy for this type
4241
parent: false
@@ -64,13 +63,7 @@ types:
6463
familyName: ~
6564
givenName: ~
6665
additionalName: ~
67-
gender: ~
6866
address: ~
69-
birthDate: ~
70-
telephone: ~
71-
email: ~
72-
url: ~
73-
jobTitle: ~
7467
PostalAddress:
7568
properties:
7669
# Force the type of the addressCountry property to text
@@ -92,7 +85,6 @@ namespace App\Entity;
9285
use ApiPlatform\Core\Annotation\ApiProperty;
9386
use ApiPlatform\Core\Annotation\ApiResource;
9487
use Doctrine\ORM\Mapping as ORM;
95-
use Symfony\Component\Validator\Constraints as Assert;
9688

9789
/**
9890
* A person (alive, dead, undead, or fictional).
@@ -113,14 +105,6 @@ class Person
113105
*/
114106
private $id;
115107

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-
124108
/**
125109
* @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.
126110
*
@@ -145,14 +129,6 @@ class Person
145129
*/
146130
private $additionalName;
147131

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-
156132
/**
157133
* @var PostalAddress|null physical address of the item
158134
*
@@ -161,64 +137,11 @@ class Person
161137
*/
162138
private $address;
163139

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-
207140
public function getId(): ?int
208141
{
209142
return $this->id;
210143
}
211144

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-
222145
public function setFamilyName(?string $familyName): void
223146
{
224147
$this->familyName = $familyName;
@@ -249,16 +172,6 @@ class Person
249172
return $this->additionalName;
250173
}
251174

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-
262175
public function setAddress(?PostalAddress $address): void
263176
{
264177
$this->address = $address;
@@ -268,56 +181,6 @@ class Person
268181
{
269182
return $this->address;
270183
}
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-
}
321184
}
322185
```
323186

@@ -466,6 +329,61 @@ class PostalAddress
466329
}
467330
```
468331

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+
469387
Note that the generator takes care of creating directories corresponding to the namespace structure.
470388

471389
Without configuration file, the tool will build the entire Schema.org vocabulary. If no properties are specified for a given

0 commit comments

Comments
 (0)