Skip to content

feat(metadata): auto order, stable order and output relation labels [*] - #9

Merged
schmunk42 merged 4 commits into
masterfrom
feature/auto-order
Oct 9, 2026
Merged

schmunk42 merged 4 commits into
masterfrom
feature/auto-order

Conversation

@schmunk42

Copy link
Copy Markdown
Member

Summary

Opt-in features so admin UIs can derive sortable columns from the standard API Platform order[...] parameters instead of guessing:

  • auto_order (default off): a resource metadata factory (decoration priority 1100, before API Platform's parameter factory) adds one SortFilter QueryParameter per readable scalar Doctrine field and per to-one relation label (order[<relation>.<label>], label from relation_field_decorator.label_property_candidates only). Identifiers, embedded fields, json/text/blob/vector types and properties outside the operation's serializer groups or readable: false are skipped. An explicit #[ApiFilter(OrderFilter::class)] or an existing parameter wins per property. #[AutoOrder(enabled:, exclude:)] per entity. Configurable default_order (default name ASC, then createdAt DESC), applied only to operations without order.
  • stable_order (default off): StableOrderExtension (priority -40, between OrderExtension and pagination) appends the identifier as tie-breaker for stable pagination; skips composite/foreign identifiers and GROUP BY queries.
  • Output schemas now carry x-label-property and x-resource-class for relations (no x-collection etc., so form editors don't claim read-only relations).
  • email added to the default label property candidates.
  • symfony/yaml moved to require (the extension always loads YAML service files).
  • CHANGELOG: proper 0.4.0 section for the hydra:operation filtering.

Requires API Platform >= 4.3 when auto_order is enabled (guarded with a configuration error).

Verification

  • PHPUnit: 58 tests, 124 assertions.
  • Consumer app (API Platform 4.4.2) OpenAPI export: no duplicate parameters, scalar and relation sort parameters on all Doctrine collection resources, none on resources with their own provider, x-label-property in output schemas.
  • Without DB: order[collection.name]=asc produces LEFT JOIN o.collection … ORDER BY collection_a1.name ASC. Row-order tests against a database run in the consumer's CI.

Proposed release: 0.5.0.

🤖 Generated with Claude Code

schmunk42 and others added 3 commits October 8, 2026 11:57
…spike) [*]

Opt-in auto_order: a metadata factory decorating with priority 1100
adds one SortFilter QueryParameter per sortable scalar field and per
to-one relation label, skipping properties with an explicit
OrderFilter.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- auto_order: per-property SortFilter parameters for readable scalar
  fields and to-one relation labels (candidates only), identifiers
  excluded, explicit OrderFilter wins, #[AutoOrder] per entity,
  configurable default_order (name ASC, createdAt DESC)
- stable_order: StableOrderExtension (priority -40) appends the
  identifier as tie-breaker for stable pagination
- output schemas carry x-label-property and x-resource-class
- email added to the default label property candidates
- CHANGELOG: 0.4.0 section for the hydra:operation filtering

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The extension always loads config/services.yaml via YamlFileLoader;
neither framework-bundle nor dependency-injection pulls symfony/yaml in.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@schmunk42 schmunk42 self-assigned this Oct 8, 2026
Resolves the conflict with 0.4.1 in RelationFieldSchemaDecorator in
favour of 0.4.1: output schemas get all five relation extensions, the
reduced output variant of this branch is dropped. Properties inside
allOf (JSON-LD output definitions) are decorated too. CHANGELOG gets the
0.5.0 section.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@schmunk42
schmunk42 merged commit aafbf36 into master Oct 9, 2026
2 checks passed
@schmunk42
schmunk42 deleted the feature/auto-order branch October 9, 2026 20:19
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.

1 participant