Skip to content

Impossible to set @ApiProperty(writable=false) #1980

@bendavies

Description

@bendavies

Hey there,

It appears that
@ApiProperty(writable=false)
is ignored when added to a property (it remains as true)

This is because the AnnotationPropertyMetadataFactory refuses to overwrite an existing value if the decorated PropertyMetadataFactoryInterface has already set it.
https://github.com/api-platform/core/blob/master/src/Metadata/Property/Factory/AnnotationPropertyMetadataFactory.php#L137-L138

It is already set here:
https://github.com/api-platform/core/blob/master/src/Bridge/Symfony/PropertyInfo/Metadata/Property/PropertyInfoPropertyMetadataFactory.php#L68

A few questions:

  1. Should later running PropertyMetadataFactory services overwrite the one they are decorating, or do earlier ones have priority?
  2. What should be the order be of the PropertyMetadataFactoryInterface? Here is the current decoration order:
    CachedPropertyMetadataFactory: -10
    ValidatorPropertyMetadataFactory 20
    AnnotationSubresourceMetadataFactory: 30
    SerializerPropertyMetadataFactory: 30
    DoctrineOrmPropertyMetadataFactory: 40
    AnnotationPropertyMetadataFactory: 40
    PropertyInfoPropertyMetadataFactory: 40
    InheritedPropertyMetadataFactory: 40
    ExtractorPropertyMetadataFactory: 40
  3. Is it a problem that many of them have the same priority, as the order is not deterministic.

cc @soyuka @dunglas

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