Skip to content
Merged
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 @@ -31,8 +31,8 @@ public function getConfigTreeBuilder()

$rootNode
->children()
->scalarNode('title')->cannotBeEmpty()->isRequired()->info('The title of the API.')->end()
->scalarNode('description')->cannotBeEmpty()->isRequired()->info('The description of the API.')->end()
->scalarNode('title')->defaultValue('')->info('The title of the API.')->end()
->scalarNode('description')->defaultValue('')->info('The description of the API.')->end()
->arrayNode('supported_formats')
->defaultValue(['jsonld' => ['mime_types' => ['application/ld+json']]])
->info('The list of enabled formats. The first one will be the default.')
Expand Down
63 changes: 15 additions & 48 deletions src/Hydra/ApiDocumentationBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,57 +29,18 @@
*/
final class ApiDocumentationBuilder implements ApiDocumentationBuilderInterface
{
/**
* @var ResourceNameCollectionFactoryInterface
*/
private $resourceNameCollectionFactory;

/**
* @var ResourceMetadataFactoryInterface
*/
private $resourceMetadataFactory;

/**
* @var PropertyNameCollectionFactoryInterface
*/
private $propertyNameCollectionFactory;

/**
* @var PropertyMetadataFactoryInterface
*/
private $propertyMetadataFactory;

/**
* @var ContextBuilderInterface
*/
private $contextBuilder;

/**
* @var ResourceClassResolverInterface
*/
private $resourceClassResolver;

/**
* @var OperationMethodResolverInterface
*/
private $operationMethodResolver;

/**
* @var UrlGeneratorInterface
*/
private $urlGenerator;

/**
* @var string
*/
private $title;

/**
* @var string
*/
private $description;

public function __construct(ResourceNameCollectionFactoryInterface $resourceNameCollectionFactory, ResourceMetadataFactoryInterface $resourceMetadataFactory, PropertyNameCollectionFactoryInterface $propertyNameCollectionFactory, PropertyMetadataFactoryInterface $propertyMetadataFactory, ContextBuilderInterface $contextBuilder, ResourceClassResolverInterface $resourceClassResolver, OperationMethodResolverInterface $operationMethodResolver, UrlGeneratorInterface $urlGenerator, string $title, string $description)
public function __construct(ResourceNameCollectionFactoryInterface $resourceNameCollectionFactory, ResourceMetadataFactoryInterface $resourceMetadataFactory, PropertyNameCollectionFactoryInterface $propertyNameCollectionFactory, PropertyMetadataFactoryInterface $propertyMetadataFactory, ContextBuilderInterface $contextBuilder, ResourceClassResolverInterface $resourceClassResolver, OperationMethodResolverInterface $operationMethodResolver, UrlGeneratorInterface $urlGenerator, string $title = '', string $description = '')
{
$this->resourceNameCollectionFactory = $resourceNameCollectionFactory;
$this->resourceMetadataFactory = $resourceMetadataFactory;
Expand Down Expand Up @@ -275,14 +236,20 @@ public function getApiDocumentation()
],
];

return [
'@context' => $this->getContext(),
'@id' => $this->urlGenerator->generate('api_hydra_vocab'),
'hydra:title' => $this->title,
'hydra:description' => $this->description,
'hydra:entrypoint' => $this->urlGenerator->generate('api_jsonld_entrypoint'),
'hydra:supportedClass' => $classes,
];
$doc = ['@context' => $this->getContext(), '@id' => $this->urlGenerator->generate('api_hydra_vocab')];

if ('' !== $this->title) {
$doc['hydra:title'] = $this->title;
}

if ('' !== $this->description) {
$doc['hydra:description'] = $this->description;
}

$doc['hydra:entrypoint'] = $this->urlGenerator->generate('api_jsonld_entrypoint');
$doc['hydra:supportedClass'] = $classes;

return $doc;
}

/**
Expand Down