symfony-jsonapi icon indicating copy to clipboard operation
symfony-jsonapi copied to clipboard

Annotations

Open davidbarratt opened this issue 8 years ago • 2 comments

Would it be possible to have annotation support? That would make it a lot easier to write the relationship mapping, you could simply do it in your doctrine entities.

davidbarratt avatar Jan 15 '17 04:01 davidbarratt

Agreed.

Perhaps introduce a new annotation to determine which columns should be exposed via the API, so that we don't accidentally blurb out sensitive information (like passwords).

For instance @ApiExposable or @ClientExposable.

Example entity:

/**
 * @Entity
 */
class User
{
    /**
     * @Id
     * @Column(type="integer")
     * @GeneratedValue
     * @ApiExposable
     */
    private $id;
    
    /**
     * @Column(type="string")
     * @ApiExposable
     */
    private $username;
    
    
    /**
     * @Column(type="string")
     */
    private $password;
    
    
    /**
     * @Column(type="string")
     */
    private $email;
}

(Disclaimer: Passwords should never be in any User table directly, but that's another talk and this is just a thought-up example.)

In the above example, only columns id and username will be exposed when the entity is JSON serialized.


On a related note: The class metadata can be used to automatically find @Id columns. As such:

$meta = $em->getClassMetadata(get_class($entity));
var_dump($meta->getIdentifierFieldNames());

kafoso avatar Apr 06 '17 12:04 kafoso

It should just work without annotation, so it would be better with @ApiHide annotation.

Toilal avatar Apr 21 '17 07:04 Toilal