| 1 |
<?php declare(strict_types=1); |
| 2 |
|
| 3 |
/** |
| 4 |
* @license Apache 2.0 |
| 5 |
*/ |
| 6 |
|
| 7 |
namespace OpenApi\Annotations; |
| 8 |
|
| 9 |
use OpenApi\Analysis; |
| 10 |
use OpenApi\Generator; |
| 11 |
|
| 12 |
/** |
| 13 |
* License information for the exposed API. |
| 14 |
* |
| 15 |
* @see [License Object](https://spec.openapis.org/oas/v3.1.1.html#license-object) |
| 16 |
* |
| 17 |
* @Annotation |
| 18 |
*/ |
| 19 |
class License extends AbstractAnnotation |
| 20 |
{ |
| 21 |
/** |
| 22 |
* The license name used for the API. |
| 23 |
* |
| 24 |
* @var string |
| 25 |
*/ |
| 26 |
public $name = Generator::UNDEFINED; |
| 27 |
|
| 28 |
/** |
| 29 |
* An SPDX license expression for the API. The <code>identifier</code> field is mutually exclusive of the <code>url</code> field. |
| 30 |
* |
| 31 |
* @since OpenAPI 3.1.0 |
| 32 |
* @var string |
| 33 |
*/ |
| 34 |
public $identifier = Generator::UNDEFINED; |
| 35 |
|
| 36 |
/** |
| 37 |
* A URL to the license used for the API. This MUST be in the form of a URL. |
| 38 |
* |
| 39 |
* The <code>url</code> field is mutually exclusive of the <code>identifier</code> field. |
| 40 |
* |
| 41 |
* @var string |
| 42 |
*/ |
| 43 |
public $url = Generator::UNDEFINED; |
| 44 |
|
| 45 |
/** |
| 46 |
* @inheritdoc |
| 47 |
*/ |
| 48 |
public static $_types = [ |
| 49 |
'name' => 'string', |
| 50 |
'identifier' => 'string', |
| 51 |
'url' => 'string', |
| 52 |
]; |
| 53 |
|
| 54 |
/** |
| 55 |
* @inheritdoc |
| 56 |
*/ |
| 57 |
public static $_required = ['name']; |
| 58 |
|
| 59 |
/** |
| 60 |
* @inheritdoc |
| 61 |
*/ |
| 62 |
public static $_parents = [ |
| 63 |
Info::class, |
| 64 |
]; |
| 65 |
|
| 66 |
/** |
| 67 |
* @inheritdoc |
| 68 |
*/ |
| 69 |
public static $_nested = [ |
| 70 |
Attachable::class => ['attachables'], |
| 71 |
]; |
| 72 |
|
| 73 |
public function jsonSerialize(): \stdClass |
| 74 |
{ |
| 75 |
$data = parent::jsonSerialize(); |
| 76 |
|
| 77 |
if ($this->_context->isVersion('3.0.x')) { |
| 78 |
unset($data->identifier); |
| 79 |
} |
| 80 |
|
| 81 |
return $data; |
| 82 |
} |
| 83 |
|
| 84 |
#[\Override] |
| 85 |
public function validate(?Analysis $analysis = null, string $version = OpenApi::DEFAULT_VERSION, ?object $context = null): bool |
| 86 |
{ |
| 87 |
$isValid = parent::validate($analysis, $version, $context); |
| 88 |
|
| 89 |
if (!OpenApi::versionMatch($version, '3.0.x')) { |
| 90 |
if (!Generator::isDefault($this->url) && !Generator::isDefault($this->identifier)) { |
| 91 |
$this->_context->logger->warning($this->identity() . ' url and identifier are mutually exclusive in ' . $this->_context); |
| 92 |
$isValid = false; |
| 93 |
} |
| 94 |
} |
| 95 |
|
| 96 |
return $isValid; |
| 97 |
} |
| 98 |
} |