core icon indicating copy to clipboard operation
core copied to clipboard

Hydra documentation returning with double @context (docs.jsonld)

Open durimjusaj opened this issue 8 months ago • 0 comments

API Platform version(s) affected: 4.1.16

Description
Just updated to v4.1.16, and docs.jsonld is now returning a result with two @context entries.

Image

Possible Solution
ApiPlatform\JsonLd\HydraContext - has already @context key in array

Image

ApiPlatform\Hydra\Serializer\DocumentationNormalizer

  • computeDoc: line 556 - Adds a new @context entry to the documentation.
  • getContext: line 580 - Returns HYDRA_CONTEXT merged with another array that already contains @context

Image

An array merge would do the trick.

return array_merge(HYDRA_CONTEXT['@context'] ?? [],
[
    '@vocab' => $this->urlGenerator->generate('api_doc', ['_format' => self::FORMAT], UrlGeneratorInterface::ABS_URL) . '#',
    'hydra' => ContextBuilderInterface::HYDRA_NS,
    'rdf' => ContextBuilderInterface::RDF_NS,
    'rdfs' => ContextBuilderInterface::RDFS_NS,
    'xmls' => ContextBuilderInterface::XML_NS,
    'owl' => ContextBuilderInterface::OWL_NS,
    'schema' => ContextBuilderInterface::SCHEMA_ORG_NS,
    'domain' => ['@id' => 'rdfs:domain', '@type' => '@id'],
    'range' => ['@id' => 'rdfs:range', '@type' => '@id'],
    'subClassOf' => ['@id' => 'rdfs:subClassOf', '@type' => '@id'],
]);

durimjusaj avatar Jun 16 '25 14:06 durimjusaj