# Getting Started ## Installation If you use [the official distribution of API Platform](../distribution/index.md), the Schema Generator is already installed as a development dependency of your project and can be invoked through Docker: $ docker-compose exec app vendor/bin/schema The Schema Generator can also [be downloaded independently as a PHAR](https://github.com/api-platform/schema-generator/releases) or installed in an existing project using [Composer](https://getcomposer.org): $ composer require --dev api-platform/schema-generator ## Model scaffolding 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): ```yaml # app/config/schema.yml # The list of types and properties we want to use types: # Parent class of Person Thing: properties: name: ~ Person: properties: familyName: ~ givenName: ~ additionalName: ~ gender: ~ address: ~ birthDate: ~ telephone: ~ email: ~ url: ~ jobTitle: ~ PostalAddress: # Disable the generation of the class hierarchy for this type parent: false properties: # Force the type of the addressCountry property to text addressCountry: { range: "Text" } addressLocality: ~ addressRegion: ~ postOfficeBoxNumber: ~ postalCode: ~ streetAddress: ~ ``` Run the generator with this config file as parameter: $ vendor/bin/schema generate-types src/ app/config/schema.yml The following classes will be generated: ```php types: Person: properties: name: ~ familyName: ~ givenName: ~ additionalName: ~ gender: ~ address: ~ birthDate: ~ telephone: ~ email: ~ url: ~ jobTitle: ~ PostalAddress: properties: # Force the type of the addressCountry property to text addressCountry: { range: "Text" } addressLocality: ~ addressRegion: ~ postOfficeBoxNumber: ~ postalCode: ~ streetAddress: ~ ``` ```php 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; } public function getFamilyName(): ?string { return $this->familyName; } public function setGivenName(?string $givenName): void { $this->givenName = $givenName; } public function getGivenName(): ?string { return $this->givenName; } public function setAdditionalName(?string $additionalName): void { $this->additionalName = $additionalName; } public function getAdditionalName(): ?string { 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; } public function getAddress(): ?PostalAddress { 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; } } ``` ```php id; } public function setAddressCountry(?string $addressCountry): void { $this->addressCountry = $addressCountry; } public function getAddressCountry(): ?string { return $this->addressCountry; } public function setAddressLocality(?string $addressLocality): void { $this->addressLocality = $addressLocality; } public function getAddressLocality(): ?string { return $this->addressLocality; } public function setAddressRegion(?string $addressRegion): void { $this->addressRegion = $addressRegion; } public function getAddressRegion(): ?string { return $this->addressRegion; } public function setPostOfficeBoxNumber(?string $postOfficeBoxNumber): void { $this->postOfficeBoxNumber = $postOfficeBoxNumber; } public function getPostOfficeBoxNumber(): ?string { return $this->postOfficeBoxNumber; } public function setPostalCode(?string $postalCode): void { $this->postalCode = $postalCode; } public function getPostalCode(): ?string { return $this->postalCode; } public function setStreetAddress(?string $streetAddress): void { $this->streetAddress = $streetAddress; } public function getStreetAddress(): ?string { return $this->streetAddress; } } ``` 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 type, all its properties will be generated. The generator also supports enumerations generation. For subclasses of [`Enumeration`](https://schema.org/Enumeration), the generator will automatically create a class extending the Enum type provided by [myclabs/php-enum](https://github.com/myclabs/php-enum). Don't forget to install this library in your project. Refer you to PHP Enum documentation to see how to use it. The Symfony validation annotation generator automatically takes care of enumerations to validate choices values. A config file generating an enum class: ```yaml types: OfferItemCondition: ~ # The generator will automatically guess that OfferItemCondition is subclass of Enum ``` The related PHP class: ```php