Skip to content

feat(hydra)!: classify custom actions by extraProperties.custom_action only - #23

Merged
schmunk42 merged 6 commits into
masterfrom
feature/utils-custom-action-marker
Nov 26, 2026
Merged

schmunk42 merged 6 commits into
masterfrom
feature/utils-custom-action-marker

Conversation

@schmunk42

Copy link
Copy Markdown
Member

What

A custom action in the Hydra documentation is now exactly the operation whose merged extraProperties carry custom_action: true (boolean). The URI heuristic is removed from both places that used it, CustomOperationHydraFactory and HydraDocumentationSubscriber, with no fallback. Release 0.8.0.

Breaking: real actions lose @type: schema:Action until their resource sets the marker. Clients that build an actions menu from that type show nothing for them, without an error. See CHANGELOG and the new README section "Custom actions".

Commits

  1. test: first kernel test setup; boots API Platform plus the bundle and serves /api/docs.jsonld (no database, no new dependencies).
  2. refactor: the heuristic moves into Metadata\CustomAction, used by factory and subscriber. No behaviour change, pinned by characterization tests.
  3. fix: HydraDocumentationSubscriber pairs each documented operation with its metadata operation by position (mirroring DocumentationNormalizer::getHydraOperations()) instead of "first operation with the same method and placeholder flag", so every operation carries its own URL.
  4. feat!: marker instead of heuristic. NotExposed is never a custom action. The factory strips {._format} from its URL carrier and adds none when the author set one.
  5. docs: README, config info() texts, comments.
  6. docs(changelog): 0.8.0.

Marker semantics

  • Only the boolean true marks; missing, false, 1, 'true', '1' do not.
  • Inherited by API Platform's flat merge: operation over #[ApiResource] over api_platform.defaults.extra_properties; false on an operation exempts it.
  • A marked operation is a custom action at any path depth; an unmarked one is an ordinary operation at any depth.
  • An author-set hydraContext still wins. hydra:title still comes from the operation name (see the comment on CustomOperationHydraFactory misclassifies reads on multi-segment resource paths #8).

Tests

252 tests, 772 assertions (was 85 / 213). Each regression test fails against the commit before its fix:

  • commit 3 against commit 2: 13 failures (10 unit, 3 kernel), e.g. two item GETs of one resource sharing one URL, POST with a placeholder getting the collection URL.
  • commit 4 against commit 3: 3 errors and 81 failures: path matrix /a, /a/{id}, /a/b, /a/b/{id}, /a/b/verb with and without marker for GET and POST at both places, marker values, inheritance from resource and global defaults, NotExposed.

Run locally on PHP 8.5 with API Platform 4.4.10; inheritance is not verified for API Platform ^3.0.

Not in this PR

Closes #7
Closes #8

🤖 Generated with Claude Code

schmunk42 and others added 6 commits November 26, 2026 13:29
Boots FrameworkBundle, ApiPlatformBundle and this bundle in a test kernel
with an unconnected in-memory EntityManager, so the Hydra documentation
can be asserted end to end without a database.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The URI heuristic lived in CustomOperationHydraFactory and as a copy in
HydraDocumentationSubscriber. Both now call Metadata\CustomAction. No
behaviour change: the one observable difference between the copies
({._format} as a whole path segment) is kept per call site and pinned by
characterization tests.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…/docs.jsonld [*]

HydraDocumentationSubscriber matched a documented operation to the first
metadata operation with the same HTTP method and placeholder flag, so two
item or two collection operations of one resource shared one URL and a
POST with a placeholder got the collection URL. Operations are now paired
by position, mirroring DocumentationNormalizer::getHydraOperations():
per ApiResource, in getOperations() order, hidden ones left out, POST and
collection operations on the Entrypoint, the rest on the class.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…n only [*]

A custom action is exactly the HTTP operation whose merged
extraProperties carry custom_action with the boolean true. The URI
heuristic is removed from CustomOperationHydraFactory and
HydraDocumentationSubscriber, with no fallback. NotExposed stubs are
never custom actions, even when they inherit a resource marker. The
factory strips {._format} from its URL carrier and adds none when the
author set @id or hydra:uriTemplate.

BREAKING CHANGE: operations are no longer typed schema:Action by their
URI shape. Set extraProperties: ['custom_action' => true] on every real
action; unmarked operations get API Platform's own type and title.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
README gets a section on custom actions and no longer describes path
shapes as the criterion in the hydra:operation section. Config info
texts, the services.yaml comment and the comments in
AddHydraOperationsSubscriber follow; the info texts of the two enabled
switches say that they currently have no effect.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@schmunk42 schmunk42 self-assigned this Nov 26, 2026
@schmunk42
schmunk42 merged commit 506a9c3 into master Nov 26, 2026
2 checks passed
@schmunk42
schmunk42 deleted the feature/utils-custom-action-marker branch November 26, 2026 13:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant