From 3aa36deae5f644678b6533c97707b1c85ffdde42 Mon Sep 17 00:00:00 2001 From: Alexis Lefebvre Date: Tue, 20 Mar 2018 16:12:58 +0100 Subject: [PATCH 1/2] =?UTF-8?q?Explain=20that=20=E2=80=9CPerson=E2=80=9D?= =?UTF-8?q?=20inherits=20from=20=E2=80=9CThing=E2=80=9D=20and=20that=20?= =?UTF-8?q?=E2=80=9CPostalAddress=E2=80=9D=20inherits?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit from 4 parents --- schema-generator/getting-started.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/schema-generator/getting-started.md b/schema-generator/getting-started.md index 4d03cf0bc99..84bb479f554 100644 --- a/schema-generator/getting-started.md +++ b/schema-generator/getting-started.md @@ -15,7 +15,12 @@ The Schema Generator can also [be downloaded independently as a PHAR](https://gi Start by browsing [Schema.org](https://schema.org) and pick types applicable to your application. The website provides tons of schemas including (but not limited to) representations of people, organization, event, postal address, creative work and e-commerce structures. -Then, write a simple YAML config file like the following (here we will generate a data model for an address book): +Then, write a simple YAML config file like the following. + +Here we will generate a data model for an address book with these data: + +- a [`Person`](http://schema.org/Person) which inherits from [`Thing`](http://schema.org/Thing) +- a [`PostalAddress`](http://schema.org/PostalAddress) which inherits from [`ContactPoint`](http://schema.org/ContactPoint), which inherits from [`StructuredValue`](http://schema.org/StructuredValue), etc. ```yaml # api/config/schema.yaml From e3a296052ba91a87ad42261476c77d6688b30b70 Mon Sep 17 00:00:00 2001 From: Alexis Lefebvre Date: Tue, 20 Mar 2018 16:19:54 +0100 Subject: [PATCH 2/2] Shorter yet full examples of generated code --- schema-generator/getting-started.md | 197 ++++++++-------------------- 1 file changed, 55 insertions(+), 142 deletions(-) diff --git a/schema-generator/getting-started.md b/schema-generator/getting-started.md index 84bb479f554..6388ad37b1a 100644 --- a/schema-generator/getting-started.md +++ b/schema-generator/getting-started.md @@ -35,13 +35,7 @@ types: familyName: ~ givenName: ~ additionalName: ~ - gender: ~ address: ~ - birthDate: ~ - telephone: ~ - email: ~ - url: ~ - jobTitle: ~ PostalAddress: # Disable the generation of the class hierarchy for this type parent: false @@ -69,13 +63,7 @@ types: familyName: ~ givenName: ~ additionalName: ~ - gender: ~ address: ~ - birthDate: ~ - telephone: ~ - email: ~ - url: ~ - jobTitle: ~ PostalAddress: properties: # Force the type of the addressCountry property to text @@ -97,7 +85,6 @@ namespace App\Entity; use ApiPlatform\Core\Annotation\ApiProperty; use ApiPlatform\Core\Annotation\ApiResource; use Doctrine\ORM\Mapping as ORM; -use Symfony\Component\Validator\Constraints as Assert; /** * A person (alive, dead, undead, or fictional). @@ -118,14 +105,6 @@ class Person */ private $id; - /** - * @var string|null the name of the item - * - * @ORM\Column(type="text", nullable=true) - * @ApiProperty(iri="http://schema.org/name") - */ - private $name; - /** * @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. * @@ -150,14 +129,6 @@ class Person */ private $additionalName; - /** - * @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. - * - * @ORM\Column(type="text", nullable=true) - * @ApiProperty(iri="http://schema.org/gender") - */ - private $gender; - /** * @var PostalAddress|null physical address of the item * @@ -166,64 +137,11 @@ class Person */ private $address; - /** - * @var \DateTimeInterface|null date of birth - * - * @ORM\Column(type="date", nullable=true) - * @ApiProperty(iri="http://schema.org/birthDate") - * @Assert\Date - */ - private $birthDate; - - /** - * @var string|null the telephone number - * - * @ORM\Column(type="text", nullable=true) - * @ApiProperty(iri="http://schema.org/telephone") - */ - private $telephone; - - /** - * @var string|null email address - * - * @ORM\Column(type="text", nullable=true) - * @ApiProperty(iri="http://schema.org/email") - * @Assert\Email - */ - private $email; - - /** - * @var string|null URL of the item - * - * @ORM\Column(type="text", nullable=true) - * @ApiProperty(iri="http://schema.org/url") - * @Assert\Url - */ - private $url; - - /** - * @var string|null the job title of the person (for example, Financial Manager) - * - * @ORM\Column(type="text", nullable=true) - * @ApiProperty(iri="http://schema.org/jobTitle") - */ - private $jobTitle; - public function getId(): ?int { return $this->id; } - public function setName(?string $name): void - { - $this->name = $name; - } - - public function getName(): ?string - { - return $this->name; - } - public function setFamilyName(?string $familyName): void { $this->familyName = $familyName; @@ -254,16 +172,6 @@ class Person return $this->additionalName; } - public function setGender(?string $gender): void - { - $this->gender = $gender; - } - - public function getGender(): ?string - { - return $this->gender; - } - public function setAddress(?PostalAddress $address): void { $this->address = $address; @@ -273,56 +181,6 @@ class Person { return $this->address; } - - public function setBirthDate(?\DateTimeInterface $birthDate): void - { - $this->birthDate = $birthDate; - } - - public function getBirthDate(): ?\DateTimeInterface - { - return $this->birthDate; - } - - public function setTelephone(?string $telephone): void - { - $this->telephone = $telephone; - } - - public function getTelephone(): ?string - { - return $this->telephone; - } - - public function setEmail(?string $email): void - { - $this->email = $email; - } - - public function getEmail(): ?string - { - return $this->email; - } - - public function setUrl(?string $url): void - { - $this->url = $url; - } - - public function getUrl(): ?string - { - return $this->url; - } - - public function setJobTitle(?string $jobTitle): void - { - $this->jobTitle = $jobTitle; - } - - public function getJobTitle(): ?string - { - return $this->jobTitle; - } } ``` @@ -471,6 +329,61 @@ class PostalAddress } ``` +```php +id; + } + + public function setName(?string $name): void + { + $this->name = $name; + } + + public function getName(): ?string + { + return $this->name; + } +} +``` + Note that the generator takes care of creating directories corresponding to the namespace structure. Without configuration file, the tool will build the entire Schema.org vocabulary. If no properties are specified for a given