Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,14 @@ private function registerJsonLdHydraConfiguration(ContainerBuilder $container, a
return;
}

if (!InstalledVersions::isInstalled('api-platform/jsonld')) {
throw new \LogicException('JSON+LD support cannot be enabled as the JSON+LD component is not installed. Try running "composer require api-platform/jsonld".');
}

if (!InstalledVersions::isInstalled('api-platform/hydra')) {
throw new \LogicException('JSON+LD support cannot be enabled as the Hydra component is not installed. Try running "composer require api-platform/hydra".');
}

if ($config['use_symfony_listeners']) {
$loader->load('symfony/jsonld.php');
} else {
Expand Down
27 changes: 20 additions & 7 deletions src/Symfony/Bundle/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use ApiPlatform\Metadata\Post;
use ApiPlatform\Metadata\Put;
use ApiPlatform\Symfony\Controller\MainController;
use Composer\InstalledVersions;
use Doctrine\Bundle\DoctrineBundle\DoctrineBundle;
use Doctrine\Bundle\MongoDBBundle\DoctrineMongoDBBundle;
use Doctrine\ORM\EntityManagerInterface;
Expand Down Expand Up @@ -57,6 +58,8 @@ public function getConfigTreeBuilder(): TreeBuilder
$treeBuilder = new TreeBuilder('api_platform');
$rootNode = $treeBuilder->getRootNode();

$jsonLdInstalled = InstalledVersions::isInstalled('api-platform/jsonld') && InstalledVersions::isInstalled('api-platform/hydra');

$rootNode
->beforeNormalization()
->ifTrue(static function ($v) {
Expand Down Expand Up @@ -191,15 +194,17 @@ public function getConfigTreeBuilder(): TreeBuilder

$this->addExceptionToStatusSection($rootNode);

$this->addFormatSection($rootNode, 'formats', [
'jsonld' => ['mime_types' => ['application/ld+json']],
$this->addFormatSection($rootNode, 'formats', $jsonLdInstalled ? [
'jsonld' => ['mime_types' => ['application/ld+json']]
] : [
'json' => ['mime_types' => ['application/json']]
]);
$this->addFormatSection($rootNode, 'patch_formats', [
'json' => ['mime_types' => ['application/merge-patch+json']],
]);

$defaultDocFormats = [
'jsonld' => ['mime_types' => ['application/ld+json']],
$defaultDocFormats = $jsonLdInstalled ? ['jsonld' => ['mime_types' => ['application/ld+json']]] : [];
$defaultDocFormats += [
'jsonopenapi' => ['mime_types' => ['application/vnd.openapi+json']],
'html' => ['mime_types' => ['text/html']],
];
Expand All @@ -210,11 +215,19 @@ public function getConfigTreeBuilder(): TreeBuilder

$this->addFormatSection($rootNode, 'docs_formats', $defaultDocFormats);

$this->addFormatSection($rootNode, 'error_formats', [
'jsonld' => ['mime_types' => ['application/ld+json']],
$defaultDocFormats = $jsonLdInstalled ? ['jsonld' => ['mime_types' => ['application/ld+json']]] : [];
$defaultDocFormats += [
'jsonopenapi' => ['mime_types' => ['application/vnd.openapi+json']],
'html' => ['mime_types' => ['text/html']],
];

$defaultErrorFormats = $jsonLdInstalled ? ['jsonld' => ['mime_types' => ['application/ld+json']]] : [];
$defaultErrorFormats += [
'jsonproblem' => ['mime_types' => ['application/problem+json']],
'json' => ['mime_types' => ['application/problem+json', 'application/json']],
]);
];
$this->addFormatSection($rootNode, 'error_formats', $defaultErrorFormats);

$rootNode
->children()
->arrayNode('jsonschema_formats')
Expand Down
2 changes: 0 additions & 2 deletions src/Symfony/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@
"api-platform/documentation": "^4.3",
"api-platform/http-cache": "^4.3",
"api-platform/json-schema": "^4.3",
"api-platform/jsonld": "^4.3",
"api-platform/hydra": "^4.3",
"api-platform/metadata": "^4.3",
"api-platform/serializer": "^4.3",
"api-platform/state": "^4.3",
Expand Down
Loading