Skip to content

feat(openapi): license identifier #7141

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 12, 2025
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
2 changes: 1 addition & 1 deletion src/OpenApi/Factory/OpenApiFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 6 additions & 0 deletions src/OpenApi/Options.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
private array $tags = [],
private ?string $errorResourceClass = null,
private ?string $validationErrorResourceClass = null,
private ?string $licenseIdentifier = null,
) {
}

Expand Down Expand Up @@ -172,4 +173,9 @@
{
return $this->validationErrorResourceClass;
}

public function getLicenseIdentifier(): ?string

Check warning on line 177 in src/OpenApi/Options.php

View check run for this annotation

Codecov / codecov/patch

src/OpenApi/Options.php#L177

Added line #L177 was not covered by tests
{
return $this->licenseIdentifier;

Check warning on line 179 in src/OpenApi/Options.php

View check run for this annotation

Codecov / codecov/patch

src/OpenApi/Options.php#L179

Added line #L179 was not covered by tests
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bundle/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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')
Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Bundle/Resources/config/openapi.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
<argument>%api_platform.swagger.persist_authorization%</argument>
<argument>%api_platform.swagger.http_auth%</argument>
<argument>%api_platform.openapi.tags%</argument>
<argument>%api_platform.openapi.license.identifier%</argument>
</service>
<service id="ApiPlatform\OpenApi\Options" alias="api_platform.openapi.options" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@
'license' => [
'name' => null,
'url' => null,
'identifier' => null,

Check warning on line 219 in tests/Symfony/Bundle/DependencyInjection/ConfigurationTest.php

View check run for this annotation

Codecov / codecov/patch

tests/Symfony/Bundle/DependencyInjection/ConfigurationTest.php#L219

Added line #L219 was not covered by tests
],
'swagger_ui_extra_configuration' => [],
'overrideResponses' => true,
Expand Down
Loading