Skip to content

Hydra docs#594

Open
soyuka wants to merge 4 commits into4.2from
hydra-docs
Open

Hydra docs#594
soyuka wants to merge 4 commits into4.2from
hydra-docs

Conversation

@soyuka
Copy link
Member

@soyuka soyuka commented Feb 10, 2026

Q A
Branch? main
Tickets Related to api-platform/core#7746
License MIT

This PR demonstrates an issue and potential solution when using multiple #[ApiResource] attributes on a single entity with different URI templates.

When a resource class has multiple #[ApiResource] declarations with different URI templates (e.g., /admin/multi_route_books and /multi_route_books), the client generator only generates types for the resource that appears in the JSON-LD entrypoint, typically missing the other routes.

Example:

  #[ApiResource(uriTemplate: '/admin/multi_route_books')]
  #[ApiResource(uriTemplate: '/multi_route_books')]
  class MultipleResourceBook

Using 2 different shortName will do the trick, api-platform/core#7746 will fix the behavior (as without the patch this won't work).

We'll also add an automatic way of handling this inside API Platform so this PR may not be needed in the end (for now its just a showcase).

We also need to test that @api-platform/admin is still working.

* @see https://schema.org/Review
*/
#[ApiResource(
uriTemplate: '/admin/reviews{._format}',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure it's useful as uriTemplate option is overriden in every operation of this ApiResource.

]
)]
#[ApiResource(
shortName: 'Book',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would remove this option to let API Platform specify it automatically by default, and see if it works (or not)!

]
)]
#[ApiResource(
shortName: 'Review',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same: I would remove it to let API Platform automatically specify it and see if it works or breaks anything

]
)]
#[ApiResource(
shortName: 'User',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same: I would remove this option to let API Platform define it automatically, and see if it works or breaks

"readOnly": true,
"type": "string",
"pattern": "^/contexts/Book$"
"pattern": "^/contexts/AdminBook$"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be Book as it's not related to the admin

"readOnly": true,
"type": "string",
"pattern": "^/contexts/Book$"
"pattern": "^/contexts/AdminBook$"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be Book as it's not related to the admin

"readOnly": true,
"type": "string",
"pattern": "^/contexts/Review$"
"pattern": "^/contexts/AdminReview$"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be Review as it's not related to the admin

"readOnly": true,
"type": "string",
"pattern": "^/contexts/Review$"
"pattern": "^/contexts/AdminReview$"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be Review as it's not related to the admin


###> nelmio/cors-bundle ###
CORS_ALLOW_ORIGIN='^https?://(localhost|127\.0\.0\.1)(:[0-9]+)?$'
CORS_ALLOW_ORIGIN='^https?://(localhost|127\.0\.0\.1)(:[0-9]+)?$|^https://api-platform\.github\.io$'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be in your .env.local file insead 😉

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