I have two entities relationship.
/**
* @ORM\Entity(repositoryClass="Infrastructure\ORM\Repository\DoctrineBidRepository")
* @ORM\Table(name="bids")
*/
class Bid
{
/**
* @ORM\Id
* @ORM\Column(type="bigint", length=20)
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\Supplier")
*/
private $supplier;
/**
* @var Order
*
* @ORM\ManyToOne(targetEntity="Domain\Order\Order", inversedBy="bids")
*/
private $order;
In another entity:
/**
* @ORM\Entity(repositoryClass="Infrastructure\ORM\Repository\DoctrineOrderRepository")
* @ORM\Table(name="`order`")
*/
class Order
{
/**
* @ORM\Id
* @ORM\Column(type="bigint")
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity="Domain\User\User")
* @ORM\JoinColumn(name="user_id", referencedColumnName="id")
*/
private $user;
/**
* @ORM\OneToMany(targetEntity="Domain\Supplier\Bid", mappedBy="order")
*/
private $bids;
In my resources.yml
resources:
Domain\Order\Order:
shortName: "Order"
itemOperations:
get:
method: "GET"
collectionOperations:
get:
method: "GET"
Domain\Supplier\Bid:
shortName: "Bid"
itemOperations:
get:
method: "GET"
collectionOperations:
get:
method: "GET"
On localhost/api swagger:
[
{
"id": 0,
"supplier": "string",
"order": "string",
"annotation": [
"string"
],
"rating": "string",
"closed": {},
"answered": true,
"open": true,
"expired": true,
"answers": [
"string"
]
}
]
In other words, it only recognizes as a string.
As result:
[
{
"id": "2",
"supplier": "/api/enterprises/3",
"order": "/api/orders/2",
"rating": null,
"answered": true,
"open": false,
"expired": true
}
]
Does anyone know what can it be?
Other likely bug is:


Not showing the provider attribute in "Example value"
For your 1st report, it's intended. By default API Platform returns links to relations (the URL of the related resource), but Swagger doesn't know about IRI/URL. For Swagger "/api/enterprises/3" is just a plain old string, so it's marked as string in the documentation.
If you care about relation typing, use the Hydra doc instead.
@dunglas, thanks for reply 馃憤
In fact the problem we identify is that it does not return the object. And yes to URI.
Your second report looks like a bug. We use Swagger UI to generate the doc, please report this bug upstream: https://github.com/swagger-api/swagger-ui/issues
You can make API Platform returning an object instead of the IRI: https://api-platform.com/docs/core/serialization-groups-and-relations#embedding-relations
A very important detail the entity Provider is abstract.
/**
* @ORM\Entity(repositoryClass="AppBundle\Repository\ProviderRepository")
* @ORM\Table(name="provider")
* @ORM\InheritanceType("JOINED")
* @ORM\DiscriminatorColumn(name="type", type="string", length=36)
* @ORM\DiscriminatorMap({
* "personal"="AppBundle\Entity\Personal",
* "enterprise"="AppBundle\Entity\Enterprise"
* })
* @ORM\HasLifecycleCallbacks
*/
abstract class Provider
{
/**
* @var integer
*
* @ORM\Id
* @ORM\Column(type="bigint", options={"unsigned"=true})
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
// ...
@dunglas, I've detected that the problem is happening when the mapping it's made with YML.
I did the mapping using annotations and worked correctly.
Which mapping api-platform ones?
Yes! resources.yml
resources:
Domain\Order\Order:
shortName: "Order"
itemOperations:
get:
method: "GET"
collectionOperations:
get:
method: "GET"
Domain\Supplier\Bid:
shortName: "Bid"
itemOperations:
get:
method: "GET"
collectionOperations:
get:
method: "GET"
For some reason it is not recognizing entities that are outside AppBundle...
In my config.yml I customize the entity directories:
orm:
auto_generate_proxy_classes: '%kernel.debug%'
auto_mapping: true
mappings:
domain:
type: annotation
dir: "%kernel.root_dir%/../src/Domain"
prefix: Domain
is_bundle: false
It's was necessary to add in my config.yml
```yaml
api_platform:
loader_paths:
annotation: ["%kernel.root_dir%/../src/Domain"]