Skip to content

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

@durimjusaj

Description

@durimjusaj

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'],
]);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions