Skip to content

Commit 202c60f

Browse files
authored
feat(openapi): license identifier (#7141)
1 parent 2a13100 commit 202c60f

File tree

6 files changed

+11
-2
lines changed

6 files changed

+11
-2
lines changed

src/OpenApi/Factory/OpenApiFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public function __invoke(array $context = []): OpenApi
116116
{
117117
$baseUrl = $context[self::BASE_URL] ?? '/';
118118
$contact = null === $this->openApiOptions->getContactUrl() || null === $this->openApiOptions->getContactEmail() ? null : new Contact($this->openApiOptions->getContactName(), $this->openApiOptions->getContactUrl(), $this->openApiOptions->getContactEmail());
119-
$license = null === $this->openApiOptions->getLicenseName() ? null : new License($this->openApiOptions->getLicenseName(), $this->openApiOptions->getLicenseUrl());
119+
$license = null === $this->openApiOptions->getLicenseName() ? null : new License($this->openApiOptions->getLicenseName(), $this->openApiOptions->getLicenseUrl(), $this->openApiOptions->getLicenseIdentifier());
120120
$info = new Info($this->openApiOptions->getTitle(), $this->openApiOptions->getVersion(), trim($this->openApiOptions->getDescription()), $this->openApiOptions->getTermsOfService(), $contact, $license);
121121
$servers = '/' === $baseUrl || '' === $baseUrl ? [new Server('/')] : [new Server($baseUrl)];
122122
$paths = new Paths();

src/OpenApi/Options.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public function __construct(
4646
private array $tags = [],
4747
private ?string $errorResourceClass = null,
4848
private ?string $validationErrorResourceClass = null,
49+
private ?string $licenseIdentifier = null,
4950
) {
5051
}
5152

@@ -172,4 +173,9 @@ public function getValidationErrorResourceClass(): ?string
172173
{
173174
return $this->validationErrorResourceClass;
174175
}
176+
177+
public function getLicenseIdentifier(): ?string
178+
{
179+
return $this->licenseIdentifier;
180+
}
175181
}

src/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -865,6 +865,7 @@ private function registerOpenApiConfiguration(ContainerBuilder $container, array
865865
$container->setParameter('api_platform.openapi.contact.email', $config['openapi']['contact']['email']);
866866
$container->setParameter('api_platform.openapi.license.name', $config['openapi']['license']['name']);
867867
$container->setParameter('api_platform.openapi.license.url', $config['openapi']['license']['url']);
868+
$container->setParameter('api_platform.openapi.license.identifier', $config['openapi']['license']['identifier']);
868869
$container->setParameter('api_platform.openapi.overrideResponses', $config['openapi']['overrideResponses']);
869870

870871
$tags = [];

src/Symfony/Bundle/DependencyInjection/Configuration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
use ApiPlatform\Metadata\Exception\InvalidArgumentException;
1919
use ApiPlatform\Metadata\Post;
2020
use ApiPlatform\Metadata\Put;
21-
use ApiPlatform\OpenApi\Model\Tag;
2221
use ApiPlatform\Symfony\Controller\MainController;
2322
use Doctrine\Bundle\DoctrineBundle\DoctrineBundle;
2423
use Doctrine\Bundle\MongoDBBundle\DoctrineMongoDBBundle;
@@ -524,6 +523,7 @@ private function addOpenApiSection(ArrayNodeDefinition $rootNode): void
524523
->children()
525524
->scalarNode('name')->defaultNull()->info('The license name used for the API.')->end()
526525
->scalarNode('url')->defaultNull()->info('URL to the license used for the API. MUST be in the format of a URL.')->end()
526+
->scalarNode('identifier')->defaultNull()->info('An SPDX license expression for the API. The identifier field is mutually exclusive of the url field.')->end()
527527
->end()
528528
->end()
529529
->variableNode('swagger_ui_extra_configuration')

src/Symfony/Bundle/Resources/config/openapi.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
<argument>%api_platform.swagger.persist_authorization%</argument>
6363
<argument>%api_platform.swagger.http_auth%</argument>
6464
<argument>%api_platform.openapi.tags%</argument>
65+
<argument>%api_platform.openapi.license.identifier%</argument>
6566
</service>
6667
<service id="ApiPlatform\OpenApi\Options" alias="api_platform.openapi.options" />
6768

tests/Symfony/Bundle/DependencyInjection/ConfigurationTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ private function runDefaultConfigTests(array $doctrineIntegrationsToLoad = ['orm
216216
'license' => [
217217
'name' => null,
218218
'url' => null,
219+
'identifier' => null,
219220
],
220221
'swagger_ui_extra_configuration' => [],
221222
'overrideResponses' => true,

0 commit comments

Comments
 (0)