Skip to content

alwaysIdentifier annotation option implementation #373

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

Closed
wants to merge 2 commits into from
Closed

alwaysIdentifier annotation option implementation #373

wants to merge 2 commits into from

Conversation

adelplace
Copy link

@adelplace adelplace commented Jan 3, 2018

Documentation for the feature api-platform/core#1528

@dunglas
Copy link
Member

dunglas commented Jan 15, 2018

Can you rebase against master @adelplace?

@dunglas
Copy link
Member

dunglas commented Jan 15, 2018

Btw, in trees an object will be always serialized only 1 time. The second time, the IRI will always be used because of the circular reference handler. It may worth mentioning this behavior.

@adelplace
Copy link
Author

@dunglas note added

@dunglas dunglas changed the base branch from 2.1 to master January 23, 2018 11:56
@adelplace
Copy link
Author

@dunglas The branch is now on master and up to date

@dunglas
Copy link
Member

dunglas commented Feb 1, 2018

Thank @adelplace.

I made a few changes, but there is something I don't understand in this example, without this option the result will be the same right? I think it should be an explicit example.

@adelplace
Copy link
Author

Thanks for your feedback.
No without the option, the children attribute would be an array of objects (with at least an iri and a context for each object). Here you just have an array of iri

@toby-griffiths
Copy link
Contributor

I've just been pointed here from api-platform/api-platform#560 as I was asking for how to do this, but I'm a little confused by this new feature/documentation.

If you use alwaysIdentifier=true on a property, does it always return an array with a single entry that is itself a URL for the collection of related resources? If so, is there a reason that this is returned as an array, rather than as a string, as this seems confusing, data structure-wise?

@soyuka
Copy link
Member

soyuka commented Feb 8, 2018

@toby-griffiths I think I directed you by error to this issue. All it does is to force the serialization to IRI's.

If you use alwaysIdentifier=true on a property, does it always return an array with a single entry that is itself a URL for the collection of related resources?

It can be a string if the relation is a toOne IIRC

@toby-griffiths
Copy link
Contributor

@soyuka I understand. But I'm now interested in this conversation… am I right in thinking that this new functionality allows you to include a link to a collection of related resources, if there's an ApiSubResource defined for them.

Example

If I have routes /questions/{id} and /questions/{id}/answers, would it be possible to get this output for the questions resource…

{
    "@id": "/questions/123",
    "@type": "Question",
    "id": "123",
    "answers": "/questions/123/answers"
}

… or perhaps…

{
    "@id": "/questions/123",
    "@type": "Question",
    "id": "123",
    "answers": {
        "@id": "/questions/123/answers"
    }
}

… ???

@soyuka
Copy link
Member

soyuka commented Feb 8, 2018

Nope, I'm not found of this new option because it's kinda misleading.

Take a look at the behat tests on the original PR https://github.com/api-platform/core/pull/1528/files all it does is returning the relation IRI's:

{
    "@id": "/questions/123",
    "@type": "Question",
    "id": "123",
    "answers": ["/answer/1", "/answer/2"]
}

It's mainly useful when you have recursive entities which is not your case. I'm sorry for misleading you on this.

About your request we have still work to do on subresource and I'm waiting for https://github.com/api-platform/core/pull/#1478 before I can continue improving stuff.

@toby-griffiths
Copy link
Contributor

@soyuka perhaps it's misleading in this example.

It would work if you added more context thought, wouldn't it?…

{
    "@id": "/questions/123",
    "@type": "Question",
    "id": "123",
    "answers": {
        "@id": "/questions/123/answers",
        "@type": "hydra:Link"
    }
}

… or am I mis-understanding the hydra vocab here?

@soyuka
Copy link
Member

soyuka commented Feb 8, 2018

nope this "feature" is only giving strings

@adelplace
Copy link
Author

adelplace commented Feb 10, 2018

This feature will be soon available with the maxDepth annotation, see api-platform/core#1696

@adelplace adelplace closed this Feb 10, 2018
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.

4 participants