-
Notifications
You must be signed in to change notification settings - Fork 937
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
feat: move OpenApi 3.1.0 conversions to processor #1531
Draft
DjordyKoert
wants to merge
7
commits into
zircote:master
Choose a base branch
from
DjordyKoert:refactor/jsonSerialize-to-processors
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
eaf1511
feat: move nullable openapi 3.1.0 conversion to processor
DjordyKoert 6a02698
only get schema types
DjordyKoert ee6189e
feat: move exclusiveMinimum openapi 3.1.0 conversion to processor
DjordyKoert 0ae8749
feat: move exclusiveMinimum openapi 3.1.0 conversion to processor
DjordyKoert ad2bb4f
remove processor handled nullable conversion
DjordyKoert f5d0469
use isDefault() for default check
DjordyKoert 2eedbb3
change oneOf overwriting check
DjordyKoert File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* @license Apache 2.0 | ||
*/ | ||
|
||
namespace OpenApi\Processors; | ||
|
||
use OpenApi\Analysis; | ||
use OpenApi\Annotations as OA; | ||
use OpenApi\Generator; | ||
|
||
final class OpenApi31Processor implements ProcessorInterface | ||
{ | ||
public function __invoke(Analysis $analysis) | ||
{ | ||
if ($analysis->openapi->openapi !== OA\OpenApi::VERSION_3_1_0) { | ||
return; | ||
} | ||
|
||
/** @var OA\Schema[] $annotations */ | ||
$annotations = $analysis->getAnnotationsOfType(OA\Schema::class); | ||
|
||
foreach ($annotations as $annotation) { | ||
$this->processReference($annotation); | ||
$this->processNullable($annotation); | ||
$this->processExclusiveMinimum($annotation); | ||
$this->processExclusiveMaximum($annotation); | ||
} | ||
} | ||
|
||
private function processReference(OA\Schema $annotation): void | ||
{ | ||
if (Generator::isDefault($annotation->ref)) { | ||
return; | ||
} | ||
|
||
|
||
} | ||
|
||
private function processNullable(OA\Schema $annotation): void | ||
{ | ||
$nullable = $annotation->nullable; | ||
$annotation->nullable = Generator::UNDEFINED; // Unregister nullable property | ||
|
||
if (true !== $nullable) { | ||
return; | ||
} | ||
|
||
if (!Generator::isDefault($annotation->ref)) { | ||
if (!Generator::isDefault($annotation->oneOf)) { | ||
return; | ||
} | ||
|
||
$annotation->oneOf = [new OA\Schema(['ref' => $annotation->ref]), new OA\Schema(['type' => 'null'])]; | ||
$annotation->ref = Generator::UNDEFINED; | ||
|
||
return; | ||
} | ||
|
||
if (is_array($annotation->oneOf)) { | ||
$annotation->oneOf[] = new OA\Schema(['type' => 'null']); | ||
} elseif (is_array($annotation->anyOf)) { | ||
$annotation->anyOf[] = new OA\Schema(['type' => 'null']); | ||
} elseif (is_array($annotation->allOf)) { | ||
$annotation->allOf[] = new OA\Schema(['type' => 'null']); | ||
} elseif (!Generator::isDefault($annotation->type)) { | ||
$annotation->type = (array) $annotation->type; | ||
$annotation->type[] = 'null'; | ||
} | ||
} | ||
|
||
private function processExclusiveMinimum(OA\Schema $annotation): void | ||
{ | ||
if (Generator::isDefault($annotation->minimum) || Generator::isDefault($annotation->exclusiveMinimum)) { | ||
return; | ||
} | ||
|
||
if (true === $annotation->exclusiveMinimum) { | ||
$annotation->exclusiveMinimum = $annotation->minimum; | ||
$annotation->minimum = Generator::UNDEFINED; | ||
} elseif (false === $annotation->exclusiveMinimum) { | ||
$annotation->exclusiveMinimum = Generator::UNDEFINED; | ||
} | ||
} | ||
|
||
private function processExclusiveMaximum(OA\Schema $annotation): void | ||
{ | ||
if (Generator::isDefault($annotation->maximum) || Generator::isDefault($annotation->exclusiveMaximum)) { | ||
return; | ||
} | ||
|
||
if (true === $annotation->exclusiveMaximum) { | ||
$annotation->exclusiveMaximum = $annotation->maximum; | ||
$annotation->maximum = Generator::UNDEFINED; | ||
} elseif (false === $annotation->exclusiveMaximum) { | ||
$annotation->exclusiveMaximum = Generator::UNDEFINED; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/DjordyKoert/swagger-php/blob/2eedbb3a9693762720a7aff34d6a2af8303bc593/src/Annotations/AbstractAnnotation.php#L358
$ref
no longer exists after going through the OpenApi31Processor because it gets set toGenerator::UNDEFINED
which makes it no longer copy the description.I have another work in progress branch to test if a new annotation
Reference
can be implemented for this with instead. https://github.com/DjordyKoert/swagger-php/blob/feat/reference-object-annotation/src/Annotations/Reference.php