Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
27pchrisl committed Mar 23, 2024
1 parent b4aad37 commit 8089f1e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 31 deletions.
7 changes: 4 additions & 3 deletions src/EntitySet.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ public function __construct(string $identifier, ?EntityType $entityType = null)
{
$this->setIdentifier($identifier);
$this->sourceMap = new ObjectArray();
$readonly = config('lodata.readonly');

if ($entityType) {
$this->setType($entityType);
Expand Down Expand Up @@ -163,17 +164,17 @@ public function __construct(string $identifier, ?EntityType $entityType = null)

$this->addAnnotation(
(new Capabilities\V1\InsertRestrictions())
->setInsertable($this instanceof CreateInterface)
->setInsertable($this instanceof CreateInterface && !$readonly)
);

$this->addAnnotation(
(new Capabilities\V1\UpdateRestrictions())
->setUpdatable($this instanceof UpdateInterface)
->setUpdatable($this instanceof UpdateInterface && !$readonly)
);

$this->addAnnotation(
(new Capabilities\V1\DeleteRestrictions())
->setDeletable($this instanceof DeleteInterface)
->setDeletable($this instanceof DeleteInterface && !$readonly)
);

$this->addAnnotation(
Expand Down
59 changes: 31 additions & 28 deletions src/PathSegment/OpenAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,44 +200,46 @@ public function emitJson(Transaction $transaction): void
* 4.5.2 Paths for Single Entities
* @link https://docs.oasis-open.org/odata/odata-openapi/v1.0/cn01/odata-openapi-v1.0-cn01.html#sec_PathsforSingleEntities
*/
if ($entityType->hasKey() && ($annotations->supportsRead() || $annotations->supportsUpdate() || $annotations->supportsDelete())) {
$pathItemObject = (object) [];
$paths->{"/{$entitySet->getName()}/{{$entityType->getKey()->getName()}}"} = $pathItemObject;
if ($entityType->hasKey()) {
if ($annotations->supportsRead() || $annotations->supportsUpdate() || $annotations->supportsDelete()) {
$pathItemObject = (object) [];
$paths->{"/{$entitySet->getName()}/{{$entityType->getKey()->getName()}}"} = $pathItemObject;

$pathItemObject->parameters = [$this->generateKeyParameter($entitySet)];
$pathItemObject->parameters = [$this->generateKeyParameter($entitySet)];

if ($annotations->supportsRead()) {
$this->generateReadRoutes($pathItemObject, $entitySet);
}
if ($annotations->supportsRead()) {
$this->generateReadRoutes($pathItemObject, $entitySet);
}

if ($annotations->supportsUpdate()) {
$this->generateUpdateRoutes($pathItemObject, $entitySet);
}
if ($annotations->supportsUpdate()) {
$this->generateUpdateRoutes($pathItemObject, $entitySet);
}

if ($annotations->supportsDelete()) {
$this->generateDeleteRoutes($pathItemObject, $entitySet);
if ($annotations->supportsDelete()) {
$this->generateDeleteRoutes($pathItemObject, $entitySet);
}
}
}

foreach ($entityType->getNavigationProperties() as $navigationProperty) {
$navigationSet = $entitySet->getBindingByNavigationProperty($navigationProperty)->getTarget();
foreach ($entityType->getNavigationProperties() as $navigationProperty) {
$navigationSet = $entitySet->getBindingByNavigationProperty($navigationProperty)->getTarget();

$pathItemObject = (object) [];
$paths->{"/{$entitySet->getName()}/{{$entityType->getKey()->getName()}}/{$navigationProperty->getName()}"} = $pathItemObject;
$pathItemObject = (object) [];
$paths->{"/{$entitySet->getName()}/{{$entityType->getKey()->getName()}}/{$navigationProperty->getName()}"} = $pathItemObject;

/** @var Description $description */
if ($description = $navigationProperty->getAnnotations()->sliceByClass(Description::class)->first()) {
$pathItemObject->summary = $description->toJson();
}
/** @var Description $description */
if ($description = $navigationProperty->getAnnotations()->sliceByClass(Description::class)->first()) {
$pathItemObject->summary = $description->toJson();
}

$pathItemObject->parameters = [$this->generateKeyParameter($entitySet)];
$pathItemObject->parameters = [$this->generateKeyParameter($entitySet)];

if ($entitySet instanceof QueryInterface) {
$this->generateQueryRoutes($pathItemObject, $navigationSet, $entitySet);
}
if ($entitySet instanceof QueryInterface) {
$this->generateQueryRoutes($pathItemObject, $navigationSet, $entitySet);
}

if ($annotations->supportsInsert()) {
$this->generateCreateRoutes($pathItemObject, $navigationSet, $entitySet);
if ($annotations->supportsInsert()) {
$this->generateCreateRoutes($pathItemObject, $navigationSet, $entitySet);
}
}
}
}
Expand Down Expand Up @@ -1090,6 +1092,7 @@ protected function uniqueTags(array $tags): array
*
* @param Property|null $property
* @param array $schema
*
* @return array
*/
public static function applyProperty(?Property $property = null, array $schema = []): array
Expand Down Expand Up @@ -1132,4 +1135,4 @@ public static function applyProperty(?Property $property = null, array $schema =

return $schema;
}
}
}

0 comments on commit 8089f1e

Please sign in to comment.