diff --git a/src/OpenApi/Factory/OpenApiFactory.php b/src/OpenApi/Factory/OpenApiFactory.php index a6636add814..43894a6b347 100644 --- a/src/OpenApi/Factory/OpenApiFactory.php +++ b/src/OpenApi/Factory/OpenApiFactory.php @@ -116,7 +116,7 @@ public function __invoke(array $context = []): OpenApi { $baseUrl = $context[self::BASE_URL] ?? '/'; $contact = null === $this->openApiOptions->getContactUrl() || null === $this->openApiOptions->getContactEmail() ? null : new Contact($this->openApiOptions->getContactName(), $this->openApiOptions->getContactUrl(), $this->openApiOptions->getContactEmail()); - $license = null === $this->openApiOptions->getLicenseName() ? null : new License($this->openApiOptions->getLicenseName(), $this->openApiOptions->getLicenseUrl()); + $license = null === $this->openApiOptions->getLicenseName() ? null : new License($this->openApiOptions->getLicenseName(), $this->openApiOptions->getLicenseUrl(), $this->openApiOptions->getLicenseIdentifier()); $info = new Info($this->openApiOptions->getTitle(), $this->openApiOptions->getVersion(), trim($this->openApiOptions->getDescription()), $this->openApiOptions->getTermsOfService(), $contact, $license); $servers = '/' === $baseUrl || '' === $baseUrl ? [new Server('/')] : [new Server($baseUrl)]; $paths = new Paths(); diff --git a/src/OpenApi/Options.php b/src/OpenApi/Options.php index a6f003542d7..e91976aa929 100644 --- a/src/OpenApi/Options.php +++ b/src/OpenApi/Options.php @@ -46,6 +46,7 @@ public function __construct( private array $tags = [], private ?string $errorResourceClass = null, private ?string $validationErrorResourceClass = null, + private ?string $licenseIdentifier = null, ) { } @@ -172,4 +173,9 @@ public function getValidationErrorResourceClass(): ?string { return $this->validationErrorResourceClass; } + + public function getLicenseIdentifier(): ?string + { + return $this->licenseIdentifier; + } } diff --git a/src/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php b/src/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php index 56676d287f3..f465798713a 100644 --- a/src/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php +++ b/src/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php @@ -865,6 +865,7 @@ private function registerOpenApiConfiguration(ContainerBuilder $container, array $container->setParameter('api_platform.openapi.contact.email', $config['openapi']['contact']['email']); $container->setParameter('api_platform.openapi.license.name', $config['openapi']['license']['name']); $container->setParameter('api_platform.openapi.license.url', $config['openapi']['license']['url']); + $container->setParameter('api_platform.openapi.license.identifier', $config['openapi']['license']['identifier']); $container->setParameter('api_platform.openapi.overrideResponses', $config['openapi']['overrideResponses']); $tags = []; diff --git a/src/Symfony/Bundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/DependencyInjection/Configuration.php index 6dc5b9d3974..2e1b5734283 100644 --- a/src/Symfony/Bundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/DependencyInjection/Configuration.php @@ -18,7 +18,6 @@ use ApiPlatform\Metadata\Exception\InvalidArgumentException; use ApiPlatform\Metadata\Post; use ApiPlatform\Metadata\Put; -use ApiPlatform\OpenApi\Model\Tag; use ApiPlatform\Symfony\Controller\MainController; use Doctrine\Bundle\DoctrineBundle\DoctrineBundle; use Doctrine\Bundle\MongoDBBundle\DoctrineMongoDBBundle; @@ -524,6 +523,7 @@ private function addOpenApiSection(ArrayNodeDefinition $rootNode): void ->children() ->scalarNode('name')->defaultNull()->info('The license name used for the API.')->end() ->scalarNode('url')->defaultNull()->info('URL to the license used for the API. MUST be in the format of a URL.')->end() + ->scalarNode('identifier')->defaultNull()->info('An SPDX license expression for the API. The identifier field is mutually exclusive of the url field.')->end() ->end() ->end() ->variableNode('swagger_ui_extra_configuration') diff --git a/src/Symfony/Bundle/Resources/config/openapi.xml b/src/Symfony/Bundle/Resources/config/openapi.xml index 7bf673b90e2..9245f89e86f 100644 --- a/src/Symfony/Bundle/Resources/config/openapi.xml +++ b/src/Symfony/Bundle/Resources/config/openapi.xml @@ -62,6 +62,7 @@ %api_platform.swagger.persist_authorization% %api_platform.swagger.http_auth% %api_platform.openapi.tags% + %api_platform.openapi.license.identifier% diff --git a/tests/Symfony/Bundle/DependencyInjection/ConfigurationTest.php b/tests/Symfony/Bundle/DependencyInjection/ConfigurationTest.php index cdb46c678df..b597141efa4 100644 --- a/tests/Symfony/Bundle/DependencyInjection/ConfigurationTest.php +++ b/tests/Symfony/Bundle/DependencyInjection/ConfigurationTest.php @@ -216,6 +216,7 @@ private function runDefaultConfigTests(array $doctrineIntegrationsToLoad = ['orm 'license' => [ 'name' => null, 'url' => null, + 'identifier' => null, ], 'swagger_ui_extra_configuration' => [], 'overrideResponses' => true,