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

fix(laravel): allow serializer attributes through ApiProperty #6680

Merged
merged 2 commits into from
Oct 11, 2024

Conversation

soyuka
Copy link
Member

@soyuka soyuka commented Sep 27, 2024

Q A
Branch? 4.0 (new metadata feature but a bug fix for laravel)
License MIT
Doc PR required?
#[ApiResource(normalizationContext: ['groups' => ['read']])]
class Resource
{
    #[ApiProperty(serialize: [new Groups(['read'])])]
    public function relation(): Relation
    {
        return new Relation(id: 1, name: 'test');
    }
}

#[Groups(['read'])]
#[ApiResource(operations: [])]
class Relation
{
    public function __construct(public int $id, public string $name) {}
}
{
  "@context": "/api/contexts/SomeClass",
  "@id": "/api/some_classes/1",
  "@type": "SomeClass",
  "relation": {
    "@id": "/api/relations/1",
    "@type": "Relation",
    "id": 1,
    "name": "test"
  }
}

@soyuka soyuka force-pushed the fix/groups-2 branch 2 times, most recently from ed1ed40 to 6d39500 Compare September 27, 2024 16:30
}

/**
* @param array<int, Groups|SerializedName|SerializedPath|MaxDepth|Ignore|Context> $serialize
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @param array<int, Groups|SerializedName|SerializedPath|MaxDepth|Ignore|Context> $serialize
* @param array<int, Context|DiscriminatorMap|Groups|Ignore|MaxDepth|SerializedName|SerializedPath> $serialize

@soyuka soyuka force-pushed the fix/groups-2 branch 2 times, most recently from ab0b6dd to acd37d6 Compare October 9, 2024 12:21
@soyuka soyuka requested a review from dunglas October 9, 2024 13:39
@soyuka soyuka force-pushed the fix/groups-2 branch 4 times, most recently from d0c9dc1 to f081805 Compare October 11, 2024 11:00

Verified

This commit was signed with the committer’s verified signature.
vinceAmstoutz Vincent Amstoutz

Verified

This commit was signed with the committer’s verified signature.
vinceAmstoutz Vincent Amstoutz
@soyuka soyuka merged commit 4bbfff3 into api-platform:4.0 Oct 11, 2024
59 checks passed
@soyuka soyuka deleted the fix/groups-2 branch October 11, 2024 11:13
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 this pull request may close these issues.

None yet

2 participants