You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
API-Platform Version 3.0.8, PHP 8.2.0, Symfony 6.2
I've got an entity which I want to only be assessable via another entity - in this case a table of invoice line items which is updated and read only by using the endpoint for the invoices.
I've discovered that I can also use this attribute: #[ApiResource(operations: [])]
This removes the endpoints from the swagger interface (though possibly not the "schemas" section at the bottom of the page). There's still a route for the GET item operation, but it returns this:
{
"@context": "/contexts/Error",
"@type": "hydra:Error",
"hydra:title": "An error occurred",
"hydra:description": "This route does not aim to be called."
}
This seems much easier (barring possibly some work to hide the schemas). Is that a valid method to use - and possibly worth documenting - or am I using accidental behaviour that might change at any point, please?
[Edit]
And a few caveats:
I am using my own StateProviders / StateProcessors and not using Doctrine ORM to retrieve data, so hiding the endpoint for invoice_lines/ doesn't break anything for me. I not sure how a Doctrine ORM Invoice entity would retrieve the InvoiceLines - and whether it relies on the invoice_lines/{id} GET endpoint?
My invoiceLine collection items, returned by the call to invoices/{id} still have IRIs - like invoice_line/1. These are obviously not actually usable, since the endpoint for them doesn't exist. Since I'm returning full details for the invoice lines with the invoice, this doesn't worry me too much - though I guess it's not entirely JSON-LD compliant.
The text was updated successfully, but these errors were encountered:
I'm not sure why I thought I needed to do this. This bug: api-platform/core#5501, caused me to try without the annotation at all - which fixed the bug for me and seemed to work just as well.
API-Platform Version 3.0.8, PHP 8.2.0, Symfony 6.2
I've got an entity which I want to only be assessable via another entity - in this case a table of invoice line items which is updated and read only by using the endpoint for the invoices.
Looking at the documentation, it suggests I can hide the endpoints for
invoice_lines/
this way: https://api-platform.com/docs/core/operations/#expose-a-model-without-any-routesI've discovered that I can also use this attribute:
#[ApiResource(operations: [])]
This removes the endpoints from the swagger interface (though possibly not the "schemas" section at the bottom of the page). There's still a route for the GET item operation, but it returns this:
This seems much easier (barring possibly some work to hide the schemas). Is that a valid method to use - and possibly worth documenting - or am I using accidental behaviour that might change at any point, please?
[Edit]
And a few caveats:
I am using my own StateProviders / StateProcessors and not using Doctrine ORM to retrieve data, so hiding the endpoint for
invoice_lines/
doesn't break anything for me. I not sure how a Doctrine ORM Invoice entity would retrieve the InvoiceLines - and whether it relies on theinvoice_lines/{id}
GET endpoint?My invoiceLine collection items, returned by the call to
invoices/{id}
still have IRIs - likeinvoice_line/1
. These are obviously not actually usable, since the endpoint for them doesn't exist. Since I'm returning full details for the invoice lines with the invoice, this doesn't worry me too much - though I guess it's not entirely JSON-LD compliant.The text was updated successfully, but these errors were encountered: