Fix admin Hydra documentation resolution and API request handling#592
Fix admin Hydra documentation resolution and API request handling#592Copilot wants to merge 6 commits intofeat/disable-hydra-prefixfrom
Conversation
Add explicit shortName to Book, Review, Bookmark, and User entities to ensure the Hydra documentation uses the short name (e.g., #Book) instead of the full type IRI (e.g., #https://schema.org/Book) when referencing supported classes. This fixes the admin client which expects to find resources by their short names. Co-authored-by: vincentchalamon <407859+vincentchalamon@users.noreply.github.com>
|
@copilot E2E tests are still failing. PHP tests only cover the API. This bug occurs on the admin, which is covered by the E2E tests. Additionnally, please add a functional test on the API to check for the Hydra documentation validity. |
Add HydraDocumentationTest to verify that API resources use shortName instead of full type IRIs in the Hydra documentation. This ensures the admin client can properly resolve resources by their short names. Co-authored-by: vincentchalamon <407859+vincentchalamon@users.noreply.github.com>
Merge existing headers when adding Authorization header in httpClient to preserve Content-Type and other headers set by fetchHydra. This prevents API request failures in the admin. Co-authored-by: vincentchalamon <407859+vincentchalamon@users.noreply.github.com>
acd767c to
a7ff0ab
Compare
I've addressed both issues:
All changes committed in 6f2bb54. The E2E tests should now pass as the admin can properly resolve resources and make API requests. |
API Platform Admin cannot resolve resources when entities define semantic
typeswithout explicitshortName. The Hydra documentation generator uses the full type IRI (e.g.,#https://schema.org/Book) as the class identifier instead of the expected short name (#Book), causing the admin to fail when parsingsupportedClass. Additionally, the admin httpClient was overwriting headers, preventing proper API communication.Changes
1. Added explicit shortName to API resources
shortNameparameter to all API resources that define semantic types:Book:shortName: 'Book'Review:shortName: 'Review'Bookmark:shortName: 'Bookmark'User:shortName: 'User'#[ApiResource( shortName: 'Book', // Ensures Hydra docs use #Book, not #https://schema.org/Book types: ['https://schema.org/Book', 'https://schema.org/Offer'], // ... )]2. Fixed admin httpClient headers merging
Fixed the httpClient in
hydraDataProviderto properly merge existing headers when adding the Authorization header:This prevents API request failures by preserving essential headers like Content-Type.
3. Added functional test for Hydra documentation validity
Created
HydraDocumentationTest.phpto verify:Result
This preserves schema.org types in JSON-LD responses while ensuring:
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.