Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Draft
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
15 changes: 15 additions & 0 deletions src/Metadata/ApiResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

use ApiPlatform\Metadata\GraphQl\Operation as GraphQlOperation;
use ApiPlatform\OpenApi\Model\Operation as OpenApiOperation;
use ApiPlatform\OpenApi\Model\PathItem;
use ApiPlatform\State\OptionsInterface;

/**
Expand Down Expand Up @@ -327,6 +328,7 @@ public function __construct(
protected ?bool $collectDenormalizationErrors = null,
protected ?array $hydraContext = null,
protected bool|OpenApiOperation|null $openapi = null,
protected ?PathItem $openApiPathItem = null,
/**
* The `validationContext` option configures the context of validation for the current ApiResource.
* You can, for instance, describe the validation groups that will be used:.
Expand Down Expand Up @@ -1366,6 +1368,19 @@ public function withOpenapi(bool|OpenApiOperation $openapi): static
return $self;
}

public function getOpenApiPathItem(): ?PathItem
{
return $this->openApiPathItem;
}

public function withOpenApiPathItem(PathItem $openApiPathItem): static
{
$self = clone $this;
$self->openApiPathItem = $openApiPathItem;

return $self;
}

public function getPaginationViaCursor(): ?array
{
return $this->paginationViaCursor;
Expand Down
3 changes: 3 additions & 0 deletions src/Metadata/Delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

use ApiPlatform\OpenApi\Attributes\Webhook;
use ApiPlatform\OpenApi\Model\Operation as OpenApiOperation;
use ApiPlatform\OpenApi\Model\PathItem;
use ApiPlatform\State\OptionsInterface;

#[\Attribute(\Attribute::TARGET_CLASS | \Attribute::IS_REPEATABLE)]
Expand Down Expand Up @@ -45,6 +46,7 @@ public function __construct(
?array $paginationViaCursor = null,
?array $hydraContext = null,
bool|OpenApiOperation|Webhook|null $openapi = null,
?PathItem $openApiPathItem = null,
?array $exceptionToStatus = null,
?bool $queryParameterValidationEnabled = null,
?array $links = null,
Expand Down Expand Up @@ -129,6 +131,7 @@ public function __construct(
paginationViaCursor: $paginationViaCursor,
hydraContext: $hydraContext,
openapi: $openapi,
openApiPathItem: $openApiPathItem,
exceptionToStatus: $exceptionToStatus,
queryParameterValidationEnabled: $queryParameterValidationEnabled,
links: $links,
Expand Down
3 changes: 3 additions & 0 deletions src/Metadata/Error.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

use ApiPlatform\OpenApi\Attributes\Webhook;
use ApiPlatform\OpenApi\Model\Operation as OpenApiOperation;
use ApiPlatform\OpenApi\Model\PathItem;
use ApiPlatform\State\OptionsInterface;

#[\Attribute(\Attribute::TARGET_CLASS | \Attribute::IS_REPEATABLE)]
Expand Down Expand Up @@ -45,6 +46,7 @@ public function __construct(
?array $paginationViaCursor = null,
?array $hydraContext = null,
bool|OpenApiOperation|Webhook|null $openapi = null,
?PathItem $openApiPathItem = null,
?array $exceptionToStatus = null,
?bool $queryParameterValidationEnabled = null,
?array $links = null,
Expand Down Expand Up @@ -123,6 +125,7 @@ public function __construct(
paginationViaCursor: $paginationViaCursor,
hydraContext: $hydraContext,
openapi: $openapi,
openApiPathItem: $openApiPathItem,
exceptionToStatus: $exceptionToStatus,
queryParameterValidationEnabled: $queryParameterValidationEnabled,
links: $links,
Expand Down
3 changes: 3 additions & 0 deletions src/Metadata/Get.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

use ApiPlatform\OpenApi\Attributes\Webhook;
use ApiPlatform\OpenApi\Model\Operation as OpenApiOperation;
use ApiPlatform\OpenApi\Model\PathItem;
use ApiPlatform\State\OptionsInterface;

#[\Attribute(\Attribute::TARGET_CLASS | \Attribute::IS_REPEATABLE)]
Expand Down Expand Up @@ -45,6 +46,7 @@ public function __construct(
?array $paginationViaCursor = null,
?array $hydraContext = null,
bool|OpenApiOperation|Webhook|null $openapi = null,
?PathItem $openApiPathItem = null,
?array $exceptionToStatus = null,
?bool $queryParameterValidationEnabled = null,
?array $links = null,
Expand Down Expand Up @@ -128,6 +130,7 @@ public function __construct(
paginationViaCursor: $paginationViaCursor,
hydraContext: $hydraContext,
openapi: $openapi,
openApiPathItem: $openApiPathItem,
exceptionToStatus: $exceptionToStatus,
queryParameterValidationEnabled: $queryParameterValidationEnabled,
links: $links,
Expand Down
3 changes: 3 additions & 0 deletions src/Metadata/GetCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

use ApiPlatform\OpenApi\Attributes\Webhook;
use ApiPlatform\OpenApi\Model\Operation as OpenApiOperation;
use ApiPlatform\OpenApi\Model\PathItem;
use ApiPlatform\State\OptionsInterface;

#[\Attribute(\Attribute::TARGET_CLASS | \Attribute::IS_REPEATABLE)]
Expand Down Expand Up @@ -45,6 +46,7 @@ public function __construct(
?array $paginationViaCursor = null,
?array $hydraContext = null,
bool|OpenApiOperation|Webhook|null $openapi = null,
?PathItem $openApiPathItem = null,
?array $exceptionToStatus = null,
?bool $queryParameterValidationEnabled = null,
?array $links = null,
Expand Down Expand Up @@ -129,6 +131,7 @@ public function __construct(
paginationViaCursor: $paginationViaCursor,
hydraContext: $hydraContext,
openapi: $openapi,
openApiPathItem: $openApiPathItem,
exceptionToStatus: $exceptionToStatus,
queryParameterValidationEnabled: $queryParameterValidationEnabled,
links: $links,
Expand Down
15 changes: 15 additions & 0 deletions src/Metadata/HttpOperation.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use ApiPlatform\Metadata\Exception\ProblemExceptionInterface;
use ApiPlatform\OpenApi\Attributes\Webhook;
use ApiPlatform\OpenApi\Model\Operation as OpenApiOperation;
use ApiPlatform\OpenApi\Model\PathItem;
use ApiPlatform\State\OptionsInterface;
use Symfony\Component\WebLink\Link as WebLink;

Expand Down Expand Up @@ -165,6 +166,7 @@ public function __construct(
protected ?array $paginationViaCursor = null,
protected ?array $hydraContext = null,
protected bool|OpenApiOperation|Webhook|null $openapi = null,
protected ?PathItem $openApiPathItem = null,
protected ?array $exceptionToStatus = null,
protected ?array $links = null,
protected ?array $errors = null,
Expand Down Expand Up @@ -640,6 +642,19 @@ public function withOpenapi(bool|OpenApiOperation|Webhook $openapi): static
return $self;
}

public function getOpenApiPathItem(): ?PathItem
{
return $this->openApiPathItem;
}

public function withOpenApiPathItem(PathItem $openApiPathItem): static
{
$self = clone $this;
$self->openApiPathItem = $openApiPathItem;

return $self;
}

public function getExceptionToStatus(): ?array
{
return $this->exceptionToStatus;
Expand Down
3 changes: 3 additions & 0 deletions src/Metadata/NotExposed.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

use ApiPlatform\OpenApi\Attributes\Webhook;
use ApiPlatform\OpenApi\Model\Operation as OpenApiOperation;
use ApiPlatform\OpenApi\Model\PathItem;
use ApiPlatform\State\OptionsInterface;

/**
Expand Down Expand Up @@ -57,6 +58,7 @@ public function __construct(

?array $hydraContext = null,
bool|OpenApiOperation|Webhook|null $openapi = false,
?PathItem $openApiPathItem = null,
?array $exceptionToStatus = null,

?bool $queryParameterValidationEnabled = null,
Expand Down Expand Up @@ -135,6 +137,7 @@ public function __construct(
paginationViaCursor: $paginationViaCursor,
hydraContext: $hydraContext,
openapi: $openapi,
openApiPathItem: $openApiPathItem,
exceptionToStatus: $exceptionToStatus,
queryParameterValidationEnabled: $queryParameterValidationEnabled,
links: $links,
Expand Down
3 changes: 3 additions & 0 deletions src/Metadata/Patch.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

use ApiPlatform\OpenApi\Attributes\Webhook;
use ApiPlatform\OpenApi\Model\Operation as OpenApiOperation;
use ApiPlatform\OpenApi\Model\PathItem;
use ApiPlatform\State\OptionsInterface;

#[\Attribute(\Attribute::TARGET_CLASS | \Attribute::IS_REPEATABLE)]
Expand Down Expand Up @@ -45,6 +46,7 @@ public function __construct(
?array $paginationViaCursor = null,
?array $hydraContext = null,
bool|OpenApiOperation|Webhook|null $openapi = null,
?PathItem $openApiPathItem = null,
?array $exceptionToStatus = null,
?bool $queryParameterValidationEnabled = null,
?array $links = null,
Expand Down Expand Up @@ -129,6 +131,7 @@ public function __construct(
paginationViaCursor: $paginationViaCursor,
hydraContext: $hydraContext,
openapi: $openapi,
openApiPathItem: $openApiPathItem,
exceptionToStatus: $exceptionToStatus,
queryParameterValidationEnabled: $queryParameterValidationEnabled,
links: $links,
Expand Down
3 changes: 3 additions & 0 deletions src/Metadata/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

use ApiPlatform\OpenApi\Attributes\Webhook;
use ApiPlatform\OpenApi\Model\Operation as OpenApiOperation;
use ApiPlatform\OpenApi\Model\PathItem;
use ApiPlatform\State\OptionsInterface;

#[\Attribute(\Attribute::TARGET_CLASS | \Attribute::IS_REPEATABLE)]
Expand Down Expand Up @@ -45,6 +46,7 @@ public function __construct(
?array $paginationViaCursor = null,
?array $hydraContext = null,
bool|OpenApiOperation|Webhook|null $openapi = null,
?PathItem $openApiPathItem = null,
?array $exceptionToStatus = null,
?bool $queryParameterValidationEnabled = null,
?array $links = null,
Expand Down Expand Up @@ -130,6 +132,7 @@ public function __construct(
paginationViaCursor: $paginationViaCursor,
hydraContext: $hydraContext,
openapi: $openapi,
openApiPathItem: $openApiPathItem,
exceptionToStatus: $exceptionToStatus,
queryParameterValidationEnabled: $queryParameterValidationEnabled,
links: $links,
Expand Down
3 changes: 3 additions & 0 deletions src/Metadata/Put.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

use ApiPlatform\OpenApi\Attributes\Webhook;
use ApiPlatform\OpenApi\Model\Operation as OpenApiOperation;
use ApiPlatform\OpenApi\Model\PathItem;
use ApiPlatform\State\OptionsInterface;

#[\Attribute(\Attribute::TARGET_CLASS | \Attribute::IS_REPEATABLE)]
Expand Down Expand Up @@ -45,6 +46,7 @@ public function __construct(
?array $paginationViaCursor = null,
?array $hydraContext = null,
bool|OpenApiOperation|Webhook|null $openapi = null,
?PathItem $openApiPathItem = null,
?array $exceptionToStatus = null,
?bool $queryParameterValidationEnabled = null,
?array $links = null,
Expand Down Expand Up @@ -130,6 +132,7 @@ public function __construct(
paginationViaCursor: $paginationViaCursor,
hydraContext: $hydraContext,
openapi: $openapi,
openApiPathItem: $openApiPathItem,
exceptionToStatus: $exceptionToStatus,
queryParameterValidationEnabled: $queryParameterValidationEnabled,
links: $links,
Expand Down
48 changes: 48 additions & 0 deletions src/OpenApi/Factory/OpenApiFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,54 @@ private function collectPaths(ApiResource $resource, ResourceMetadataCollection
$pathItem = $paths->getPath($path) ?? new PathItem();
}

if ($openApiPathItem = $operation->getOpenApiPathItem()) {
if ($globalPathSummary = $openApiPathItem->getSummary()) {
$pathItem = $pathItem->withSummary($globalPathSummary);

foreach (PathItem::$methods as $pathMethod) {
$getMethod = 'get'.ucfirst(strtolower($pathMethod));
$withMethod = 'with'.ucfirst(strtolower($pathMethod));

if (($existingOperation = $pathItem->{$getMethod}()) && $existingOperation instanceof Operation) {
$existingOperationSummary = $existingOperation->getSummary();

if ($existingOperationSummary === $this->getPathDescription($resourceShortName, $pathMethod, false) || $existingOperationSummary === $this->getPathDescription($resourceShortName, $pathMethod, true)) {
$pathItem = $pathItem->{$withMethod}($existingOperation->withSummary($globalPathSummary));
}
}
}
}

if ($globalPathDescription = $openApiPathItem->getDescription()) {
$pathItem = $pathItem->withDescription($globalPathDescription);

foreach (PathItem::$methods as $pathMethod) {
$getMethod = 'get'.ucfirst(strtolower($pathMethod));
$withMethod = 'with'.ucfirst(strtolower($pathMethod));

if (($existingOperation = $pathItem->{$getMethod}()) && $existingOperation instanceof Operation) {
$existingOperationDescription = $existingOperation->getDescription();

if ($existingOperationDescription === $this->getPathDescription($resourceShortName, $pathMethod, false) || $existingOperationDescription === $this->getPathDescription($resourceShortName, $pathMethod, true)) {
$pathItem = $pathItem->{$withMethod}($existingOperation->withDescription($globalPathDescription));
}
}
}
}
}

if ($openapiAttribute instanceof Operation && $openapiSummary = $openapiAttribute->getSummary()) {
$openapiOperation = $openapiOperation->withSummary($openapiSummary);
} elseif ($parentSummary = $pathItem->getSummary()) {
$openapiOperation = $openapiOperation->withSummary($parentSummary);
}

if ($openapiAttribute instanceof Operation && $openapiDescription = $openapiAttribute->getDescription()) {
$openapiOperation = $openapiOperation->withDescription($openapiDescription);
} elseif ($parentDescription = $pathItem->getDescription()) {
$openapiOperation = $openapiOperation->withDescription($parentDescription);
}

$forceSchemaCollection = $operation instanceof CollectionOperationInterface && 'GET' === $method;
$schema = new Schema('openapi');
$schema->setDefinitions($schemas);
Expand Down
Loading