Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass-down normalizer groups #66

Open
gijsgroenewegen opened this issue Dec 13, 2023 · 1 comment
Open

Pass-down normalizer groups #66

gijsgroenewegen opened this issue Dec 13, 2023 · 1 comment

Comments

@gijsgroenewegen
Copy link

gijsgroenewegen commented Dec 13, 2023

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.

@BowlOfSoup
Copy link
Owner

BowlOfSoup commented Dec 13, 2023

A few questions.

  1. Your goal would be to only get the ID of certain type="collection", is that correct?
  2. Could we instead of a passDownGroup use a specific option like normalizeIdOnly?
  3. Or maybe we could add an indicator of the ID field like normalizeIdField=uuid (if the id field is not used, but another field is actually the identifier). We could even make it a class annotation (@Bos\Normalize(idField="uuid")) and use that in combination with normalizeIdOnly

The meaning of passDownGroup may be unclear.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants