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

Recursive check for hidden properties. #14

Merged
merged 1 commit into from
Mar 13, 2017
Merged

Recursive check for hidden properties. #14

merged 1 commit into from
Mar 13, 2017

Conversation

PaulRoth
Copy link
Contributor

@PaulRoth PaulRoth commented Mar 9, 2017

No description provided.

@nilportugues
Copy link
Owner

@PaulRoth looks good, but mind providing use-case or bug that solves?

@PaulRoth
Copy link
Contributor Author

Hi @nilportugues, I use Symfony 3.2.4 & Doctrine ORM 2.5.6.

The Entities looking like this. The Entity 'Document' has an owner (User).

class Document {
    /** @var int */
    private $id;
    /** @var string */
    private $filename;
    /** @var int */
    private $downloadCount;
    /** @var User **/
    private $owner;
}

class User {
    /** @var int */
    private $id;
    /** @var string */
    private $username;
    /** @var string */
    private $password;
}

The Mappings looking like this. I would like to hide the field "downloadCount" at the Document and the field "password" at the User.

mapping:
    class: Document
    hide_properties:
        - downloadCount
    id_properties:
        - id
    urls:
        self: get_document
    relationships:
        owner:
            self: get_user

mapping:
    class: User
    hide_properties:
        - password
    id_properties:
        - id
    urls:
        self: get_user

When I query a user, his password is hidden. But when I query a document, the field "downloadCount" is hidden, but the password of user remains visible.

{
  "data": {
    "type": "document",
    "id": "1",
    "attributes": {
      "filename": "test.pdf"
    },
    "links": {
      "self": {
        "href": "/api/documents/1"
      }
    },
    "relationships": {
      "owner": {
        "data": {
          "type": "user",
          "id": "1"
        }
      }
    }
  },
  "included": [
    {
      "type": "user",
      "id": "1",
      "attributes": {
        "username": "Paul Roth",
        "password": "Lwa312GIJnruAHKM"
      },
      "links": {
        "self": {
          "href": "/api/users/1"
        }
      }
    }
  ],
  "links": {
    "self": {
      "href": "/api/documents/1"
    }
  },
  "jsonapi": {
    "version": "1.0"
  }
}

@nilportugues
Copy link
Owner

@PaulRoth alright!

@nilportugues nilportugues merged commit 6759043 into nilportugues:master Mar 13, 2017
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.

2 participants