Skip to content

Commit

Permalink
Revert bad version checks
Browse files Browse the repository at this point in the history
  • Loading branch information
DerManoMann committed Mar 25, 2024
1 parent 2357faf commit ed48167
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 20 deletions.
18 changes: 4 additions & 14 deletions src/Annotations/AbstractAnnotation.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,16 +165,6 @@ public function __set(string $property, $value): void
$this->_context->logger->warning('Ignoring unexpected property "' . $property . '" for ' . $this->identity() . ', expecting "' . implode('", "', array_keys($fields)) . '" in ' . $this->_context);
}

/**
* Check if one of the given version numbers matches the current OpenAPI version.
*
* @param string|array $versions One or more version numbers
*/
public function isOpenApiVersion($versions): bool
{
return $this->_context->isVersion($versions);
}

/**
* Merge given annotations to their mapped properties configured in static::$_nested.
*
Expand Down Expand Up @@ -360,7 +350,7 @@ public function jsonSerialize()
if (isset($data->ref)) {
// Only specific https://github.com/OAI/OpenAPI-Specification/blob/3.1.0/versions/3.1.0.md#reference-object
$ref = ['$ref' => $data->ref];
if ($this->isOpenApiVersion(OpenApi::VERSION_3_1_0)) {
if ($this->_context->isVersion(OpenApi::VERSION_3_1_0)) {
foreach (['summary', 'description'] as $prop) {
if (property_exists($this, $prop)) {
if (!Generator::isDefault($this->{$prop})) {
Expand All @@ -371,7 +361,7 @@ public function jsonSerialize()
}
if (property_exists($this, 'nullable') && $this->nullable === true) {
$ref = ['oneOf' => [$ref]];
if ($this->isOpenApiVersion(OpenApi::VERSION_3_1_0)) {
if ($this->_context->isVersion(OpenApi::VERSION_3_1_0)) {
$ref['oneOf'][] = ['type' => 'null'];
} else {
$ref['nullable'] = $data->nullable;
Expand All @@ -391,7 +381,7 @@ public function jsonSerialize()
$data = (object) $ref;
}

if ($this->isOpenApiVersion(OpenApi::VERSION_3_0_0)) {
if ($this->_context->isVersion(OpenApi::VERSION_3_0_0)) {
if (isset($data->exclusiveMinimum) && is_numeric($data->exclusiveMinimum)) {
$data->minimum = $data->exclusiveMinimum;
$data->exclusiveMinimum = true;
Expand All @@ -402,7 +392,7 @@ public function jsonSerialize()
}
}

if ($this->isOpenApiVersion(OpenApi::VERSION_3_1_0)) {
if ($this->_context->isVersion(OpenApi::VERSION_3_1_0)) {
if (isset($data->nullable)) {
if (true === $data->nullable) {
if (isset($data->oneOf)) {
Expand Down
4 changes: 2 additions & 2 deletions src/Annotations/License.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function jsonSerialize()
{
$data = parent::jsonSerialize();

if ($this->isOpenApiVersion(OpenApi::VERSION_3_0_0)) {
if ($this->_context->isVersion(OpenApi::VERSION_3_0_0)) {
unset($data->identifier);
}

Expand All @@ -90,7 +90,7 @@ public function validate(array $stack = [], array $skip = [], string $ref = '',
{
$valid = parent::validate($stack, $skip, $ref, $context);

if ($this->isOpenApiVersion(OpenApi::VERSION_3_1_0)) {
if ($this->_context->isVersion(OpenApi::VERSION_3_1_0)) {
if (!Generator::isDefault($this->url) && $this->identifier !== Generator::UNDEFINED) {
$this->_context->logger->warning($this->identity() . ' url and identifier are mutually exclusive');
$valid = false;
Expand Down
2 changes: 1 addition & 1 deletion src/Annotations/OpenApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ public function jsonSerialize()
{
$data = parent::jsonSerialize();

if (false === $this->isOpenApiVersion(OpenApi::VERSION_3_1_0)) {
if (!$this->_context->isVersion(OpenApi::VERSION_3_1_0)) {
unset($data->webhooks);
}

Expand Down
4 changes: 2 additions & 2 deletions src/Annotations/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ public function jsonSerialize()
{
$data = parent::jsonSerialize();

if ($this->isOpenApiVersion(OpenApi::VERSION_3_0_0)) {
if ($this->_context->isVersion(OpenApi::VERSION_3_0_0)) {
unset($data->examples);
if (isset($data->const)) {
$data->enum = [$data->const];
Expand All @@ -506,7 +506,7 @@ public function validate(array $stack = [], array $skip = [], string $ref = '',
return false;
}

if ($this->isOpenApiVersion(OpenApi::VERSION_3_0_0)) {
if ($this->_context->isVersion(OpenApi::VERSION_3_0_0)) {
if (!Generator::isDefault($this->examples)) {
$this->_context->logger->warning($this->identity() . ' is only allowed for ' . OpenApi::VERSION_3_1_0);

Expand Down
2 changes: 1 addition & 1 deletion src/Processors/AugmentProperties.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ protected function augmentType(Analysis $analysis, OA\Property $property, Contex
$property->minimum = 0;
} elseif ($type === 'non-zero-int') {
$property->type = 'integer';
if ($property->isOpenApiVersion(OA\OpenApi::VERSION_3_1_0)) {
if ($property->_context->isVersion(OA\OpenApi::VERSION_3_1_0)) {
$property->not = ['const' => 0];
} else {
$property->not = ['enum' => [0]];
Expand Down

0 comments on commit ed48167

Please sign in to comment.