Skip to content

Commit

Permalink
core: Fix OpenAPI for reference API
Browse files Browse the repository at this point in the history
Signed-off-by: jld3103 <jld3103yt@gmail.com>
  • Loading branch information
provokateurin committed Sep 14, 2023
1 parent 30a7eab commit 53af2e8
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 73 deletions.
6 changes: 3 additions & 3 deletions core/Controller/CollaborationResourcesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
use Psr\Log\LoggerInterface;

/**
* @psalm-import-type CoreOpenGraphObject from ResponseDefinitions
* @psalm-import-type CoreResource from ResponseDefinitions
* @psalm-import-type CoreCollection from ResponseDefinitions
*/
class CollaborationResourcesController extends OCSController {
Expand Down Expand Up @@ -313,7 +313,7 @@ protected function prepareCollection(ICollection $collection): array {
}

/**
* @return CoreOpenGraphObject[]
* @return CoreResource[]
*/
protected function prepareResources(array $resources): array {
$result = [];
Expand All @@ -331,7 +331,7 @@ protected function prepareResources(array $resources): array {
}

/**
* @return CoreOpenGraphObject
* @return CoreResource
*/
protected function prepareResource(IResource $resource): array {
if (!$resource->canAccess($this->userSession->getUser())) {
Expand Down
4 changes: 2 additions & 2 deletions core/Controller/ReferenceApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function __construct(
* @param string $text Text to extract from
* @param bool $resolve Resolve the references
* @param int $limit Maximum amount of references to extract
* @return DataResponse<Http::STATUS_OK, array{references: array<string, CoreReference|mixed|null>}, array{}>
* @return DataResponse<Http::STATUS_OK, array{references: array<string, CoreReference|null>}, array{}>
*/
public function extract(string $text, bool $resolve = false, int $limit = 1): DataResponse {
$references = $this->referenceManager->extractReferences($text);
Expand Down Expand Up @@ -99,7 +99,7 @@ public function resolveOne(string $reference): DataResponse {
*
* @param string[] $references References to resolve
* @param int $limit Maximum amount of references to resolve
* @return DataResponse<Http::STATUS_OK, array{references: array<string, CoreReference|mixed|null>}, array{}>
* @return DataResponse<Http::STATUS_OK, array{references: array<string, CoreReference|null>}, array{}>
*/
public function resolve(array $references, int $limit = 1): DataResponse {
$result = [];
Expand Down
18 changes: 10 additions & 8 deletions core/ResponseDefinitions.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,22 +61,24 @@
* }
*
* @psalm-type CoreOpenGraphObject = array{
* id: string,
* name: string,
* description: ?string,
* thumb: ?string,
* link: string,
* }
*
* @psalm-type CoreResource = array{
* richObjectType: string,
* richObject: array<string, mixed>,
* openGraphObject: array{
* id: string,
* name: string,
* description: ?string,
* thumb: ?string,
* link: string,
* },
* openGraphObject: CoreOpenGraphObject,
* accessible: bool,
* }
*
* @psalm-type CoreCollection = array{
* id: int,
* name: string,
* resources: CoreOpenGraphObject[],
* resources: CoreResource[],
* }
*
* @psalm-type CoreReference = array{
Expand Down
107 changes: 48 additions & 59 deletions core/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"resources": {
"type": "array",
"items": {
"$ref": "#/components/schemas/OpenGraphObject"
"$ref": "#/components/schemas/Resource"
}
}
}
Expand Down Expand Up @@ -226,52 +226,29 @@
"OpenGraphObject": {
"type": "object",
"required": [
"richObjectType",
"richObject",
"openGraphObject",
"accessible"
"id",
"name",
"description",
"thumb",
"link"
],
"properties": {
"richObjectType": {
"id": {
"type": "string"
},
"richObject": {
"type": "object",
"additionalProperties": {
"type": "object"
}
"name": {
"type": "string"
},
"openGraphObject": {
"type": "object",
"required": [
"id",
"name",
"description",
"thumb",
"link"
],
"properties": {
"id": {
"type": "string"
},
"name": {
"type": "string"
},
"description": {
"type": "string",
"nullable": true
},
"thumb": {
"type": "string",
"nullable": true
},
"link": {
"type": "string"
}
}
"description": {
"type": "string",
"nullable": true
},
"accessible": {
"type": "boolean"
"thumb": {
"type": "string",
"nullable": true
},
"link": {
"type": "string"
}
}
},
Expand Down Expand Up @@ -333,6 +310,32 @@
}
}
},
"Resource": {
"type": "object",
"required": [
"richObjectType",
"richObject",
"openGraphObject",
"accessible"
],
"properties": {
"richObjectType": {
"type": "string"
},
"richObject": {
"type": "object",
"additionalProperties": {
"type": "object"
}
},
"openGraphObject": {
"$ref": "#/components/schemas/OpenGraphObject"
},
"accessible": {
"type": "boolean"
}
}
},
"Status": {
"type": "object",
"required": [
Expand Down Expand Up @@ -3334,15 +3337,8 @@
"references": {
"type": "object",
"additionalProperties": {
"nullable": true,
"oneOf": [
{
"$ref": "#/components/schemas/Reference"
},
{
"type": "object"
}
]
"$ref": "#/components/schemas/Reference",
"nullable": true
}
}
}
Expand Down Expand Up @@ -3441,15 +3437,8 @@
"references": {
"type": "object",
"additionalProperties": {
"nullable": true,
"oneOf": [
{
"$ref": "#/components/schemas/Reference"
},
{
"type": "object"
}
]
"$ref": "#/components/schemas/Reference",
"nullable": true
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions lib/public/Collaboration/Reference/IReference.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,9 @@ public function getRichObject(): array;
* @since 25.0.0
*/
public function getOpenGraphObject(): array;

/**
* @return array{richObjectType: string, richObject: array<string, mixed>, openGraphObject: array{id: string, name: string, description: ?string, thumb: ?string, link: string}, accessible: bool}
*/
public function jsonSerialize(): array;

Check failure on line 133 in lib/public/Collaboration/Reference/IReference.php

View workflow job for this annotation

GitHub Actions / static-code-analysis-ocp

InvalidDocblock

lib/public/Collaboration/Reference/IReference.php:133:2: InvalidDocblock: @SInCE is required for methods in OCP. (see https://psalm.dev/008)
}
2 changes: 1 addition & 1 deletion lib/public/Collaboration/Reference/Reference.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ public static function fromCache(array $cache): IReference {
* @since 25.0.0
* @return array{richObjectType: string, richObject: array<string, mixed>, openGraphObject: OpenGraphObject, accessible: bool}
*/
public function jsonSerialize() {
public function jsonSerialize(): array {
return [
'richObjectType' => $this->getRichObjectType(),
'richObject' => $this->getRichObject(),
Expand Down

0 comments on commit 53af2e8

Please sign in to comment.