Skip to content

Commit e3a2960

Browse files
author
Alexis Lefebvre
committed
Shorter yet full examples of generated code
1 parent 3aa36de commit e3a2960

File tree

1 file changed

+55
-142
lines changed

1 file changed

+55
-142
lines changed

schema-generator/getting-started.md

Lines changed: 55 additions & 142 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,7 @@ types:
3535
familyName: ~
3636
givenName: ~
3737
additionalName: ~
38-
gender: ~
3938
address: ~
40-
birthDate: ~
41-
telephone: ~
42-
email: ~
43-
url: ~
44-
jobTitle: ~
4539
PostalAddress:
4640
# Disable the generation of the class hierarchy for this type
4741
parent: false
@@ -69,13 +63,7 @@ types:
6963
familyName: ~
7064
givenName: ~
7165
additionalName: ~
72-
gender: ~
7366
address: ~
74-
birthDate: ~
75-
telephone: ~
76-
email: ~
77-
url: ~
78-
jobTitle: ~
7967
PostalAddress:
8068
properties:
8169
# Force the type of the addressCountry property to text
@@ -97,7 +85,6 @@ namespace App\Entity;
9785
use ApiPlatform\Core\Annotation\ApiProperty;
9886
use ApiPlatform\Core\Annotation\ApiResource;
9987
use Doctrine\ORM\Mapping as ORM;
100-
use Symfony\Component\Validator\Constraints as Assert;
10188

10289
/**
10390
* A person (alive, dead, undead, or fictional).
@@ -118,14 +105,6 @@ class Person
118105
*/
119106
private $id;
120107

121-
/**
122-
* @var string|null the name of the item
123-
*
124-
* @ORM\Column(type="text", nullable=true)
125-
* @ApiProperty(iri="http://schema.org/name")
126-
*/
127-
private $name;
128-
129108
/**
130109
* @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.
131110
*
@@ -150,14 +129,6 @@ class Person
150129
*/
151130
private $additionalName;
152131

153-
/**
154-
* @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.
155-
*
156-
* @ORM\Column(type="text", nullable=true)
157-
* @ApiProperty(iri="http://schema.org/gender")
158-
*/
159-
private $gender;
160-
161132
/**
162133
* @var PostalAddress|null physical address of the item
163134
*
@@ -166,64 +137,11 @@ class Person
166137
*/
167138
private $address;
168139

169-
/**
170-
* @var \DateTimeInterface|null date of birth
171-
*
172-
* @ORM\Column(type="date", nullable=true)
173-
* @ApiProperty(iri="http://schema.org/birthDate")
174-
* @Assert\Date
175-
*/
176-
private $birthDate;
177-
178-
/**
179-
* @var string|null the telephone number
180-
*
181-
* @ORM\Column(type="text", nullable=true)
182-
* @ApiProperty(iri="http://schema.org/telephone")
183-
*/
184-
private $telephone;
185-
186-
/**
187-
* @var string|null email address
188-
*
189-
* @ORM\Column(type="text", nullable=true)
190-
* @ApiProperty(iri="http://schema.org/email")
191-
* @Assert\Email
192-
*/
193-
private $email;
194-
195-
/**
196-
* @var string|null URL of the item
197-
*
198-
* @ORM\Column(type="text", nullable=true)
199-
* @ApiProperty(iri="http://schema.org/url")
200-
* @Assert\Url
201-
*/
202-
private $url;
203-
204-
/**
205-
* @var string|null the job title of the person (for example, Financial Manager)
206-
*
207-
* @ORM\Column(type="text", nullable=true)
208-
* @ApiProperty(iri="http://schema.org/jobTitle")
209-
*/
210-
private $jobTitle;
211-
212140
public function getId(): ?int
213141
{
214142
return $this->id;
215143
}
216144

217-
public function setName(?string $name): void
218-
{
219-
$this->name = $name;
220-
}
221-
222-
public function getName(): ?string
223-
{
224-
return $this->name;
225-
}
226-
227145
public function setFamilyName(?string $familyName): void
228146
{
229147
$this->familyName = $familyName;
@@ -254,16 +172,6 @@ class Person
254172
return $this->additionalName;
255173
}
256174

257-
public function setGender(?string $gender): void
258-
{
259-
$this->gender = $gender;
260-
}
261-
262-
public function getGender(): ?string
263-
{
264-
return $this->gender;
265-
}
266-
267175
public function setAddress(?PostalAddress $address): void
268176
{
269177
$this->address = $address;
@@ -273,56 +181,6 @@ class Person
273181
{
274182
return $this->address;
275183
}
276-
277-
public function setBirthDate(?\DateTimeInterface $birthDate): void
278-
{
279-
$this->birthDate = $birthDate;
280-
}
281-
282-
public function getBirthDate(): ?\DateTimeInterface
283-
{
284-
return $this->birthDate;
285-
}
286-
287-
public function setTelephone(?string $telephone): void
288-
{
289-
$this->telephone = $telephone;
290-
}
291-
292-
public function getTelephone(): ?string
293-
{
294-
return $this->telephone;
295-
}
296-
297-
public function setEmail(?string $email): void
298-
{
299-
$this->email = $email;
300-
}
301-
302-
public function getEmail(): ?string
303-
{
304-
return $this->email;
305-
}
306-
307-
public function setUrl(?string $url): void
308-
{
309-
$this->url = $url;
310-
}
311-
312-
public function getUrl(): ?string
313-
{
314-
return $this->url;
315-
}
316-
317-
public function setJobTitle(?string $jobTitle): void
318-
{
319-
$this->jobTitle = $jobTitle;
320-
}
321-
322-
public function getJobTitle(): ?string
323-
{
324-
return $this->jobTitle;
325-
}
326184
}
327185
```
328186

@@ -471,6 +329,61 @@ class PostalAddress
471329
}
472330
```
473331

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

476389
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)