Skip to content

[JSONAPI] Nested resource inclusion not exposing specified properties #2675

Description

@maximgubar

I have 2 entities, Product and Supplier

<?php
/**
 * @ApiResource(
 *     itemOperations={
 *         "get"={
 *             "normalization_context"={"groups"={"single-read"}},
 *         },
 *     },
 * )
 * @ORM\Table(name="product")
 * @ORM\Entity(repositoryClass="App\Repository\ProductRepository")
 * @ApiFilter(SearchFilter::class, properties={"id": "exact", "supplier": "exact"})
 */
class Product
{
    /**
     * @ApiProperty(identifier=true)
     * @ORM\Id()
     * @ORM\GeneratedValue()
     * @ORM\Column(type="integer")
     */
    private $id;

    /**
     * @ORM\ManyToOne(targetEntity="Supplier", inversedBy="products")
     * @ORM\JoinColumn(name="supplier_id", referencedColumnName="id")
     * @Groups({"single-read"})
     */
    private $supplier;

    /**
     * @ORM\Column(type="string", length=255)
     * @Groups({"single-read"})
     */
    private $sku;
}
<?php

/**
 * @ORM\Table(name="supplier")
 * @ORM\Entity(repositoryClass="App\Repository\SupplierRepository")
 * @ApiResource(
 *     attributes={
 *         "normalization_context"={"groups"={"read"}},
 *         "denormalization_context"={"groups"={"write"}},
 *     },
 * )
 * @ApiFilter(SearchFilter::class, properties={"id": "exact", "code": "exact", "name": "exact"})
 */
class Supplier
{
    /**
     * @ApiProperty(identifier=true)
     * @ORM\Id()
     * @ORM\GeneratedValue()
     * @ORM\Column(type="integer")
     */
    private $id;

    /**
     * @ORM\Column(type="string", length=255, unique=true)
     * @Groups({"read", "write", "single-read"})
     */
    private $code;

    /**
     * @ORM\Column(type="string", length=255, unique=true)
     * @Groups({"read", "write", "single-read"})
     */
    private $name;
}

When I use 'application/json' as response content type, properties 'code' and 'name' are exposed.
If I'm using 'application/vnd.api+json' I always see dereferencable IRI,

"relationships": {
      "supplier": {
        "data": {
          "type": "Supplier",
          "id": "/api/suppliers/73"
        }
      }
    }

Am I missing something in the configuration or this is a bug ?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions