Skip to content

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

Open
soyuka wants to merge 1 commit into
api-platform:mainfrom
soyuka:main
Open

feat(jsonld): add resource-level jsonldContext for namespace prefixes#8188
soyuka wants to merge 1 commit into
api-platform:mainfrom
soyuka:main

Conversation

@soyuka
Copy link
Copy Markdown
Member

@soyuka soyuka commented May 19, 2026

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
  • testResourceLevelJsonLdContextAddsNamespacePrefixes covers the new feature end-to-end

Closes #767

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
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