Skip to content

Commit

Permalink
refactor(OpenAPI): Use proper type inheritance for chat messages
Browse files Browse the repository at this point in the history
Signed-off-by: provokateurin <kate@provokateurin.de>
  • Loading branch information
provokateurin committed Apr 10, 2024
1 parent 22dc629 commit 158c7bb
Show file tree
Hide file tree
Showing 10 changed files with 424 additions and 592 deletions.
4 changes: 2 additions & 2 deletions lib/Model/ProxyCacheMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
* @method void setMetaData(?string $metaData)
* @method string|null getMetaData()
*
* @psalm-import-type TalkRoomProxyMessage from ResponseDefinitions
* @psalm-import-type TalkChatBaseMessage from ResponseDefinitions
*/
class ProxyCacheMessage extends Entity implements \JsonSerializable {
public const METADATA_REPLY_TO_ACTOR_TYPE = 'replyToActorType';
Expand Down Expand Up @@ -108,7 +108,7 @@ public function getParsedMetaData(): array {
}

/**
* @return TalkRoomProxyMessage
* @return TalkChatBaseMessage
*/
public function jsonSerialize(): array {
$expirationTimestamp = 0;
Expand Down
28 changes: 10 additions & 18 deletions lib/ResponseDefinitions.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,21 +93,24 @@
* conversation?: string,
* }
*
* @psalm-type TalkChatMessage = array{
* @psalm-type TalkChatBaseMessage = array{
* actorDisplayName: string,
* actorId: string,
* actorType: string,
* deleted?: true,
* expirationTimestamp: int,
* id: int,
* isReplyable: bool,
* markdown: bool,
* message: string,
* messageParameters: array<string, TalkRichObjectParameter>,
* messageType: string,
* systemMessage: string,
* }
*
* @psalm-type TalkChatMessage = TalkChatBaseMessage&array{
* deleted?: true,
* id: int,
* isReplyable: bool,
* markdown: bool,
* reactions: array<string, integer>|\stdClass,
* referenceId: string,
* systemMessage: string,
* timestamp: int,
* token: string,
* lastEditActorDisplayName?: string,
Expand All @@ -117,18 +120,7 @@
* silent?: bool,
* }
*
* @psalm-type TalkRoomProxyMessage = array{
* actorDisplayName: string,
* actorId: string,
* actorType: string,
* expirationTimestamp: int,
* message: string,
* messageParameters: array<string, TalkRichObjectParameter>,
* messageType: string,
* systemMessage: string,
* }
*
* @psalm-type TalkRoomLastMessage = TalkChatMessage|TalkRoomProxyMessage
* @psalm-type TalkRoomLastMessage = TalkChatMessage|TalkChatBaseMessage
*
* @psalm-type TalkChatMessageWithParent = TalkChatMessage&array{parent?: TalkChatMessage}
*
Expand Down
175 changes: 73 additions & 102 deletions openapi-backend-sipbridge.json
Original file line number Diff line number Diff line change
Expand Up @@ -208,24 +208,17 @@
}
}
},
"ChatMessage": {
"ChatBaseMessage": {
"type": "object",
"required": [
"actorDisplayName",
"actorId",
"actorType",
"expirationTimestamp",
"id",
"isReplyable",
"markdown",
"message",
"messageParameters",
"messageType",
"reactions",
"referenceId",
"systemMessage",
"timestamp",
"token"
"systemMessage"
],
"properties": {
"actorDisplayName": {
Expand All @@ -237,26 +230,10 @@
"actorType": {
"type": "string"
},
"deleted": {
"type": "boolean",
"enum": [
true
]
},
"expirationTimestamp": {
"type": "integer",
"format": "int64"
},
"id": {
"type": "integer",
"format": "int64"
},
"isReplyable": {
"type": "boolean"
},
"markdown": {
"type": "boolean"
},
"message": {
"type": "string"
},
Expand All @@ -269,44 +246,81 @@
"messageType": {
"type": "string"
},
"reactions": {
"type": "object",
"additionalProperties": {
"type": "integer",
"format": "int64"
}
},
"referenceId": {
"type": "string"
},
"systemMessage": {
"type": "string"
},
"timestamp": {
"type": "integer",
"format": "int64"
},
"token": {
"type": "string"
},
"lastEditActorDisplayName": {
"type": "string"
},
"lastEditActorId": {
"type": "string"
},
"lastEditActorType": {
"type": "string"
},
"lastEditTimestamp": {
"type": "integer",
"format": "int64"
},
"silent": {
"type": "boolean"
}
}
},
"ChatMessage": {
"allOf": [
{
"$ref": "#/components/schemas/ChatBaseMessage"
},
{
"type": "object",
"required": [
"id",
"isReplyable",
"markdown",
"reactions",
"referenceId",
"timestamp",
"token"
],
"properties": {
"deleted": {
"type": "boolean",
"enum": [
true
]
},
"id": {
"type": "integer",
"format": "int64"
},
"isReplyable": {
"type": "boolean"
},
"markdown": {
"type": "boolean"
},
"reactions": {
"type": "object",
"additionalProperties": {
"type": "integer",
"format": "int64"
}
},
"referenceId": {
"type": "string"
},
"timestamp": {
"type": "integer",
"format": "int64"
},
"token": {
"type": "string"
},
"lastEditActorDisplayName": {
"type": "string"
},
"lastEditActorId": {
"type": "string"
},
"lastEditActorType": {
"type": "string"
},
"lastEditTimestamp": {
"type": "integer",
"format": "int64"
},
"silent": {
"type": "boolean"
}
}
}
]
},
"OCSMeta": {
"type": "object",
"required": [
Expand Down Expand Up @@ -712,52 +726,9 @@
"$ref": "#/components/schemas/ChatMessage"
},
{
"$ref": "#/components/schemas/RoomProxyMessage"
"$ref": "#/components/schemas/ChatBaseMessage"
}
]
},
"RoomProxyMessage": {
"type": "object",
"required": [
"actorDisplayName",
"actorId",
"actorType",
"expirationTimestamp",
"message",
"messageParameters",
"messageType",
"systemMessage"
],
"properties": {
"actorDisplayName": {
"type": "string"
},
"actorId": {
"type": "string"
},
"actorType": {
"type": "string"
},
"expirationTimestamp": {
"type": "integer",
"format": "int64"
},
"message": {
"type": "string"
},
"messageParameters": {
"type": "object",
"additionalProperties": {
"$ref": "#/components/schemas/RichObjectParameter"
}
},
"messageType": {
"type": "string"
},
"systemMessage": {
"type": "string"
}
}
}
}
},
Expand Down
Loading

0 comments on commit 158c7bb

Please sign in to comment.