Skip to content

feat(jsonld): add resource-level jsonldContext for namespace prefixes#8204

Merged
soyuka merged 1 commit into
api-platform:mainfrom
soyuka:feat/jsonld-resource-context
May 28, 2026
Merged

feat(jsonld): add resource-level jsonldContext for namespace prefixes#8204
soyuka merged 1 commit into
api-platform:mainfrom
soyuka:feat/jsonld-resource-context

Conversation

@soyuka

@soyuka soyuka commented May 28, 2026

Copy link
Copy Markdown
Member

Summary

  • Add jsonldContext parameter to ApiResource and HttpOperation (and all concrete operation classes)
  • ContextBuilder merges the resource's jsonldContext into the generated @context output
  • YAML and XML extractors updated to support the new field
  • Cascade from ApiResource to operations works automatically via WithResourceTrait::copyFrom

Usage

#[ApiResource(
    jsonldContext: ['dct' => 'http://purl.org/dc/terms/'],
)]
class BibliographicResource
{
    #[ApiProperty(iris: ['dct:title'])]
    public ?string $title = null;
}

Produces /contexts/BibliographicResource:

{
    "@vocab": "...",
    "hydra": "...",
    "dct": "http://purl.org/dc/terms/",
    "title": "dct:title"
}

Test plan

  • php vendor/bin/phpunit tests/Functional/JsonLd/ContextTest.php — 9 tests pass
  • src/Metadata/vendor/bin/phpunit — 189 metadata tests pass
  • testResourceLevelJsonLdContextAddsNamespacePrefixes covers the new feature end-to-end

Closes #767
Supersedes #8188

Allows defining JSON-LD namespace prefix entries (e.g. `dct:
http://purl.org/dc/terms/`) directly on ApiResource/HttpOperation,
which get merged into the generated `@context` output.

Closes api-platform#767
@soyuka soyuka merged commit 5ddf94a into api-platform:main May 28, 2026
109 of 114 checks passed
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.

Add jsonld context to resource

1 participant