Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Describing attributes in .yaml doesn`t apply to virtual properties (method) #2956

Open
@wwwitalya

Description

@wwwitalya

API Platform version(s) affected: 4.2.6 + Symfony
Describing attributes in .yaml doesn`t apply to virtual properties (method)

Description
If we try to describe virtual property (like method) in resource YAML then extra attributes doesn`t read and apply to property because of bug in ApiPlatform\Metadata\Property\Factory\ExtractorPropertyMetadataFactoryhttps://github.com/api-platform/metadata/blob/3.1/Property/Factory/ExtractorPropertyMetadataFactory.php line 48

    if (        !property_exists($resourceClass, $property) && !interface_exists($resourceClass)        || null === ($propertyMetadata = $this->extractor->getProperties()[$resourceClass][$property] ?? null)    ) {        return $this->handleNotFound($parentPropertyMetadata, $resourceClass, $property);    }

If we using propertyExtractor why do we need straight check of property exists?
Just for record, PHP attribute #[ApiProperty] works as expected.

How to reproduce

Entity/User.phpclass User {    public function isAdmin(): bool    {        return true;    }}
config/api/user.yamlproperties:  App\Entity\User    admin:      security: "user.isAdmin() === true"

Because of no property named '$admin' in class property from .yaml doesn`t apply.

Possible Solution
I think property_exists is useless condition and should be removed.

if (null === ($propertyMetadata = $this->extractor->getProperties()[$resourceClass][$property] ?? null)){     return $this->handleNotFound($parentPropertyMetadata, $resourceClass, $property);}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp