Skip to content

Commit 0acadce

Browse files
committed
Merge pull request #560 from api-platform/no_config
Make title and description config parameters optional
2 parents 8bdf829 + 51b6551 commit 0acadce

File tree

2 files changed

+17
-50
lines changed

2 files changed

+17
-50
lines changed

src/Bridge/Symfony/Bundle/DependencyInjection/Configuration.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ public function getConfigTreeBuilder()
3131

3232
$rootNode
3333
->children()
34-
->scalarNode('title')->cannotBeEmpty()->isRequired()->info('The title of the API.')->end()
35-
->scalarNode('description')->cannotBeEmpty()->isRequired()->info('The description of the API.')->end()
34+
->scalarNode('title')->defaultValue('')->info('The title of the API.')->end()
35+
->scalarNode('description')->defaultValue('')->info('The description of the API.')->end()
3636
->arrayNode('supported_formats')
3737
->defaultValue(['jsonld' => ['mime_types' => ['application/ld+json']]])
3838
->info('The list of enabled formats. The first one will be the default.')

src/Hydra/ApiDocumentationBuilder.php

Lines changed: 15 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -29,57 +29,18 @@
2929
*/
3030
final class ApiDocumentationBuilder implements ApiDocumentationBuilderInterface
3131
{
32-
/**
33-
* @var ResourceNameCollectionFactoryInterface
34-
*/
3532
private $resourceNameCollectionFactory;
36-
37-
/**
38-
* @var ResourceMetadataFactoryInterface
39-
*/
4033
private $resourceMetadataFactory;
41-
42-
/**
43-
* @var PropertyNameCollectionFactoryInterface
44-
*/
4534
private $propertyNameCollectionFactory;
46-
47-
/**
48-
* @var PropertyMetadataFactoryInterface
49-
*/
5035
private $propertyMetadataFactory;
51-
52-
/**
53-
* @var ContextBuilderInterface
54-
*/
5536
private $contextBuilder;
56-
57-
/**
58-
* @var ResourceClassResolverInterface
59-
*/
6037
private $resourceClassResolver;
61-
62-
/**
63-
* @var OperationMethodResolverInterface
64-
*/
6538
private $operationMethodResolver;
66-
67-
/**
68-
* @var UrlGeneratorInterface
69-
*/
7039
private $urlGenerator;
71-
72-
/**
73-
* @var string
74-
*/
7540
private $title;
76-
77-
/**
78-
* @var string
79-
*/
8041
private $description;
8142

82-
public function __construct(ResourceNameCollectionFactoryInterface $resourceNameCollectionFactory, ResourceMetadataFactoryInterface $resourceMetadataFactory, PropertyNameCollectionFactoryInterface $propertyNameCollectionFactory, PropertyMetadataFactoryInterface $propertyMetadataFactory, ContextBuilderInterface $contextBuilder, ResourceClassResolverInterface $resourceClassResolver, OperationMethodResolverInterface $operationMethodResolver, UrlGeneratorInterface $urlGenerator, string $title, string $description)
43+
public function __construct(ResourceNameCollectionFactoryInterface $resourceNameCollectionFactory, ResourceMetadataFactoryInterface $resourceMetadataFactory, PropertyNameCollectionFactoryInterface $propertyNameCollectionFactory, PropertyMetadataFactoryInterface $propertyMetadataFactory, ContextBuilderInterface $contextBuilder, ResourceClassResolverInterface $resourceClassResolver, OperationMethodResolverInterface $operationMethodResolver, UrlGeneratorInterface $urlGenerator, string $title = '', string $description = '')
8344
{
8445
$this->resourceNameCollectionFactory = $resourceNameCollectionFactory;
8546
$this->resourceMetadataFactory = $resourceMetadataFactory;
@@ -275,14 +236,20 @@ public function getApiDocumentation()
275236
],
276237
];
277238

278-
return [
279-
'@context' => $this->getContext(),
280-
'@id' => $this->urlGenerator->generate('api_hydra_vocab'),
281-
'hydra:title' => $this->title,
282-
'hydra:description' => $this->description,
283-
'hydra:entrypoint' => $this->urlGenerator->generate('api_jsonld_entrypoint'),
284-
'hydra:supportedClass' => $classes,
285-
];
239+
$doc = ['@context' => $this->getContext(), '@id' => $this->urlGenerator->generate('api_hydra_vocab')];
240+
241+
if ('' !== $this->title) {
242+
$doc['hydra:title'] = $this->title;
243+
}
244+
245+
if ('' !== $this->description) {
246+
$doc['hydra:description'] = $this->description;
247+
}
248+
249+
$doc['hydra:entrypoint'] = $this->urlGenerator->generate('api_jsonld_entrypoint');
250+
$doc['hydra:supportedClass'] = $classes;
251+
252+
return $doc;
286253
}
287254

288255
/**

0 commit comments

Comments
 (0)