Skip to content

Commit 8089f1e

Browse files
committed
Updates
1 parent b4aad37 commit 8089f1e

File tree

2 files changed

+35
-31
lines changed

2 files changed

+35
-31
lines changed

src/EntitySet.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ public function __construct(string $identifier, ?EntityType $entityType = null)
121121
{
122122
$this->setIdentifier($identifier);
123123
$this->sourceMap = new ObjectArray();
124+
$readonly = config('lodata.readonly');
124125

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

164165
$this->addAnnotation(
165166
(new Capabilities\V1\InsertRestrictions())
166-
->setInsertable($this instanceof CreateInterface)
167+
->setInsertable($this instanceof CreateInterface && !$readonly)
167168
);
168169

169170
$this->addAnnotation(
170171
(new Capabilities\V1\UpdateRestrictions())
171-
->setUpdatable($this instanceof UpdateInterface)
172+
->setUpdatable($this instanceof UpdateInterface && !$readonly)
172173
);
173174

174175
$this->addAnnotation(
175176
(new Capabilities\V1\DeleteRestrictions())
176-
->setDeletable($this instanceof DeleteInterface)
177+
->setDeletable($this instanceof DeleteInterface && !$readonly)
177178
);
178179

179180
$this->addAnnotation(

src/PathSegment/OpenAPI.php

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -200,44 +200,46 @@ public function emitJson(Transaction $transaction): void
200200
* 4.5.2 Paths for Single Entities
201201
* @link https://docs.oasis-open.org/odata/odata-openapi/v1.0/cn01/odata-openapi-v1.0-cn01.html#sec_PathsforSingleEntities
202202
*/
203-
if ($entityType->hasKey() && ($annotations->supportsRead() || $annotations->supportsUpdate() || $annotations->supportsDelete())) {
204-
$pathItemObject = (object) [];
205-
$paths->{"/{$entitySet->getName()}/{{$entityType->getKey()->getName()}}"} = $pathItemObject;
203+
if ($entityType->hasKey()) {
204+
if ($annotations->supportsRead() || $annotations->supportsUpdate() || $annotations->supportsDelete()) {
205+
$pathItemObject = (object) [];
206+
$paths->{"/{$entitySet->getName()}/{{$entityType->getKey()->getName()}}"} = $pathItemObject;
206207

207-
$pathItemObject->parameters = [$this->generateKeyParameter($entitySet)];
208+
$pathItemObject->parameters = [$this->generateKeyParameter($entitySet)];
208209

209-
if ($annotations->supportsRead()) {
210-
$this->generateReadRoutes($pathItemObject, $entitySet);
211-
}
210+
if ($annotations->supportsRead()) {
211+
$this->generateReadRoutes($pathItemObject, $entitySet);
212+
}
212213

213-
if ($annotations->supportsUpdate()) {
214-
$this->generateUpdateRoutes($pathItemObject, $entitySet);
215-
}
214+
if ($annotations->supportsUpdate()) {
215+
$this->generateUpdateRoutes($pathItemObject, $entitySet);
216+
}
216217

217-
if ($annotations->supportsDelete()) {
218-
$this->generateDeleteRoutes($pathItemObject, $entitySet);
218+
if ($annotations->supportsDelete()) {
219+
$this->generateDeleteRoutes($pathItemObject, $entitySet);
220+
}
219221
}
220-
}
221222

222-
foreach ($entityType->getNavigationProperties() as $navigationProperty) {
223-
$navigationSet = $entitySet->getBindingByNavigationProperty($navigationProperty)->getTarget();
223+
foreach ($entityType->getNavigationProperties() as $navigationProperty) {
224+
$navigationSet = $entitySet->getBindingByNavigationProperty($navigationProperty)->getTarget();
224225

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

228-
/** @var Description $description */
229-
if ($description = $navigationProperty->getAnnotations()->sliceByClass(Description::class)->first()) {
230-
$pathItemObject->summary = $description->toJson();
231-
}
229+
/** @var Description $description */
230+
if ($description = $navigationProperty->getAnnotations()->sliceByClass(Description::class)->first()) {
231+
$pathItemObject->summary = $description->toJson();
232+
}
232233

233-
$pathItemObject->parameters = [$this->generateKeyParameter($entitySet)];
234+
$pathItemObject->parameters = [$this->generateKeyParameter($entitySet)];
234235

235-
if ($entitySet instanceof QueryInterface) {
236-
$this->generateQueryRoutes($pathItemObject, $navigationSet, $entitySet);
237-
}
236+
if ($entitySet instanceof QueryInterface) {
237+
$this->generateQueryRoutes($pathItemObject, $navigationSet, $entitySet);
238+
}
238239

239-
if ($annotations->supportsInsert()) {
240-
$this->generateCreateRoutes($pathItemObject, $navigationSet, $entitySet);
240+
if ($annotations->supportsInsert()) {
241+
$this->generateCreateRoutes($pathItemObject, $navigationSet, $entitySet);
242+
}
241243
}
242244
}
243245
}
@@ -1090,6 +1092,7 @@ protected function uniqueTags(array $tags): array
10901092
*
10911093
* @param Property|null $property
10921094
* @param array $schema
1095+
*
10931096
* @return array
10941097
*/
10951098
public static function applyProperty(?Property $property = null, array $schema = []): array
@@ -1132,4 +1135,4 @@ public static function applyProperty(?Property $property = null, array $schema =
11321135

11331136
return $schema;
11341137
}
1135-
}
1138+
}

0 commit comments

Comments
 (0)