api-platform / schema-generator

PHP Model Scaffolding from Schema.org and other RDF vocabularies
https://api-platform.com/docs/schema-generator/
MIT License
460 stars 110 forks source link

Invalid schema generation #62

Closed cve closed 7 years ago

cve commented 8 years ago

Hi,

I follow with tutorial at https://github.com/api-platform/docs/blob/master/tutorial/api.md#generating-the-data-model and when I run:

$ vendor/bin/schema generate-types src/ app/config/schema.yml

I get the following output:

[warning] Type "Book" cannot be found. Using "Thing" type to generate entity.
[warning] Type "Person" cannot be found. Using "Thing" type to generate entity.
[warning] Type "Organization" cannot be found. Using "Thing" type to generate entity.
[error] The property "name" (type "Thing") has an unknown type. Add its type to the config file.
[error] The property "description" (type "Thing") has an unknown type. Add its type to the config file.
[error] The property "genre" (type "Thing") has an unknown type. Add its type to the config file.
[error] The property "datePublished" (type "Thing") has an unknown type. Add its type to the config file.
[error] The property "illustrator" (type "Thing") has an unknown type. Add its type to the config file.
[error] The property "isbn" (type "Thing") has an unknown type. Add its type to the config file.
[error] The property "numberOfPages" (type "Thing") has an unknown type. Add its type to the config file.
[error] The property "name" (type "Thing") has an unknown type. Add its type to the config file.
[error] The property "description" (type "Thing") has an unknown type. Add its type to the config file.
[error] The property "url" (type "Thing") has an unknown type. Add its type to the config file.
[error] The property "birthDate" (type "Thing") has an unknown type. Add its type to the config file.
[error] The property "gender" (type "Thing") has an unknown type. Add its type to the config file.
[error] The property "name" (type "Thing") has an unknown type. Add its type to the config file.
[error] The property "description" (type "Thing") has an unknown type. Add its type to the config file.
[error] The property "url" (type "Thing") has an unknown type. Add its type to the config file.

and following entities:

Book

<?php

namespace AppBundle\Entity;

use ApiPlatform\Core\Annotation\ApiResource;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;

/**
 * @see http://schema.org/Thing Documentation on Schema.org
 * 
 * @ORM\Entity
 * @ApiResource(iri="http://schema.org/Thing")
 */
class Book
{
    /**
     * @var int
     * 
     * @ORM\Column(type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;
    /**
     * @var ArrayCollection<Person>
     * 
     * @ORM\ManyToMany(targetEntity="AppBundle\Entity\Person")
     * @ORM\JoinTable(name="book_author")
     */
    private $author;
    /**
     * @var Organization
     * 
     * @ORM\ManyToOne(targetEntity="AppBundle\Entity\Organization")
     * @ORM\JoinColumn(nullable=false)
     */
    private $publisher;

    public function __construct()
    {
        $this->author = new ArrayCollection();
    }

    /**
     * Sets id.
     * 
     * @param int $id
     * 
     * @return $this
     */
    public function setId($id)
    {
        $this->id = $id;

        return $this;
    }

    /**
     * Gets id.
     * 
     * @return int
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Adds author.
     * 
     * @param Person $author
     * 
     * @return $this
     */
    public function addAuthor(Person $author)
    {
        $this->author[] = $author;

        return $this;
    }

    /**
     * Removes author.
     * 
     * @param Person $author
     * 
     * @return $this
     */
    public function removeAuthor(Person $author)
    {
        $this->author->removeElement($author);

        return $this;
    }

    /**
     * Gets author.
     * 
     * @return ArrayCollection<Person>
     */
    public function getAuthor()
    {
        return $this->author;
    }

    /**
     * Sets publisher.
     * 
     * @param Organization $publisher
     * 
     * @return $this
     */
    public function setPublisher(Organization $publisher = null)
    {
        $this->publisher = $publisher;

        return $this;
    }

    /**
     * Gets publisher.
     * 
     * @return Organization
     */
    public function getPublisher()
    {
        return $this->publisher;
    }
}

Organization

<?php

namespace AppBundle\Entity;

use ApiPlatform\Core\Annotation\ApiResource;
use Doctrine\ORM\Mapping as ORM;

/**
 * @see http://schema.org/Thing Documentation on Schema.org
 * 
 * @ORM\Entity
 * @ApiResource(iri="http://schema.org/Thing")
 */
class Organization
{
    /**
     * @var int
     * 
     * @ORM\Column(type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * Sets id.
     * 
     * @param int $id
     * 
     * @return $this
     */
    public function setId($id)
    {
        $this->id = $id;

        return $this;
    }

    /**
     * Gets id.
     * 
     * @return int
     */
    public function getId()
    {
        return $this->id;
    }
}

Person

<?php

namespace AppBundle\Entity;

use ApiPlatform\Core\Annotation\ApiResource;
use Doctrine\ORM\Mapping as ORM;

/**
 * @see http://schema.org/Thing Documentation on Schema.org
 * 
 * @ORM\Entity
 * @ApiResource(iri="http://schema.org/Thing")
 */
class Person
{
    /**
     * @var int
     * 
     * @ORM\Column(type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * Sets id.
     * 
     * @param int $id
     * 
     * @return $this
     */
    public function setId($id)
    {
        $this->id = $id;

        return $this;
    }

    /**
     * Gets id.
     * 
     * @return int
     */
    public function getId()
    {
        return $this->id;
    }
}

I found that output on the TravisCI which reports the same:

https://travis-ci.org/api-platform/schema-generator/jobs/134156337

dunglas commented 8 years ago

There is a bug in the last version of the Schema.org's rdfa file. Can you try using an old version of the rdfa like described at the end of this PR: https://github.com/api-platform/docs/pull/89/files

Thanks.

cve commented 8 years ago

Thanks, it working now. I leave issue open if you let.

dunglas commented 7 years ago

The last version looks OK.

MichalEmbiq commented 7 years ago

Not working, generates only Entities with id. Adding rdfa doesn't fix it.