Skip to content

Pass-down normalizer groups #66

@gijsgroenewegen

Description

@gijsgroenewegen

This issue suggests to add support for a passdownGroup option in the normalizer bundle. With this option, the groups passed down to nested objects can be manually defined.

The following PHP class example will demonstrate the use case:

class Bar
{
    /**
     * @Bos\Normalize(group={"api_v3", "id_only"})
     * 
     * @var int
     */
    public $id;

    /**
     * @Bos\Normalize(group={"api_v3"}, passdownGroup="id_only")
     * 
     * @var Foo
     */
    public $foo;
}

class Foo
{
    /**
     * @Bos\Normalize(group={"api_v3", "id_only"})
     * 
     * @var int
     */
    public $id;

    /**
     * @Bos\Normalize(group={"api_v3"})
     * 
     * @var string
     */
    public $name;
}

Calling the normalizer like:

$this->normalizer->normalize($bar, 'api_v3');

Would result in:

{
  "id": 1,
  "foo": {
    "id": 1
  }
}

Instead of:

{
  "id": 1,
  "foo": {
    "id": 1,
    "name": "test"
  }
}

Without this feature, a lot of manual groups might have to be defined to support simple use cases like above.

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