Browse Source

feat(polls): Stronger API typing

Signed-off-by: Joas Schilling <coding@schilljs.com>
pull/13506/head
Joas Schilling 1 year ago
parent
commit
3e37c32bdd
No known key found for this signature in database GPG Key ID: F72FA5B49FFA96B0
  1. 10
      lib/Model/Poll.php
  2. 20
      lib/ResponseDefinitions.php
  3. 44
      openapi-full.json
  4. 44
      openapi.json
  5. 18
      src/types/openapi/openapi-full.ts
  6. 18
      src/types/openapi/openapi.ts

10
lib/Model/Poll.php

@ -13,29 +13,39 @@ use OCA\Talk\ResponseDefinitions;
use OCP\AppFramework\Db\Entity;
/**
* @psalm-method int<1, max> getId()
* @method void setRoomId(int $roomId)
* @method int getRoomId()
* @psalm-method int<1, max> getRoomId()
* @method void setQuestion(string $question)
* @method string getQuestion()
* @psalm-method non-empty-string getQuestion()
* @method void setOptions(string $options)
* @method string getOptions()
* @method void setVotes(string $votes)
* @method string getVotes()
* @method void setNumVoters(int $numVoters)
* @method int getNumVoters()
* @psalm-method int<0, max> getNumVoters()
* @method void setActorType(string $actorType)
* @method string getActorType()
* @psalm-method TalkActorTypes getActorType()
* @method void setActorId(string $actorId)
* @method string getActorId()
* @psalm-method non-empty-string getActorId()
* @method void setDisplayName(string $displayName)
* @method string getDisplayName()
* @method void setStatus(int $status)
* @method int getStatus()
* @psalm-method self::STATUS_* getStatus()
* @method void setResultMode(int $resultMode)
* @method int getResultMode()
* @psalm-method self::MODE_* getResultMode()
* @method void setMaxVotes(int $maxVotes)
* @method int getMaxVotes()
* @psalm-method int<0, max> getMaxVotes()
*
* @psalm-import-type TalkActorTypes from ResponseDefinitions
* @psalm-import-type TalkPoll from ResponseDefinitions
* @psalm-import-type TalkPollDraft from ResponseDefinitions
*/

20
lib/ResponseDefinitions.php

@ -10,6 +10,8 @@ declare(strict_types=1);
namespace OCA\Talk;
/**
* @psalm-type TalkActorTypes = 'users'|'groups'|'guests'|'emails'|'circles'|'bridged'|'bots'|'federated_users'|'phones'
*
* @psalm-type TalkBan = array{
* id: int,
* moderatorActorType: string,
@ -199,19 +201,19 @@ namespace OCA\Talk;
*
* @psalm-type TalkPollDraft = array{
* actorDisplayName: string,
* actorId: string,
* actorType: string,
* id: int,
* maxVotes: int,
* options: string[],
* question: string,
* resultMode: int,
* status: int,
* actorId: non-empty-string,
* actorType: TalkActorTypes,
* id: int<1, max>,
* maxVotes: int<0, max>,
* options: list<string>,
* question: non-empty-string,
* resultMode: 0|1,
* status: 0|1|2,
* }
*
* @psalm-type TalkPoll = TalkPollDraft&array{
* details?: TalkPollVote[],
* numVoters?: int,
* numVoters?: int<0, max>,
* votedSelf?: int[],
* votes?: array<string, int>,
* }

44
openapi-full.json

@ -20,6 +20,20 @@
}
},
"schemas": {
"ActorTypes": {
"type": "string",
"enum": [
"users",
"groups",
"guests",
"emails",
"circles",
"bridged",
"bots",
"federated_users",
"phones"
]
},
"Ban": {
"type": "object",
"required": [
@ -857,7 +871,8 @@
},
"numVoters": {
"type": "integer",
"format": "int64"
"format": "int64",
"minimum": 0
},
"votedSelf": {
"type": "array",
@ -895,18 +910,21 @@
"type": "string"
},
"actorId": {
"type": "string"
"type": "string",
"minLength": 1
},
"actorType": {
"type": "string"
"$ref": "#/components/schemas/ActorTypes"
},
"id": {
"type": "integer",
"format": "int64"
"format": "int64",
"minimum": 1
},
"maxVotes": {
"type": "integer",
"format": "int64"
"format": "int64",
"minimum": 0
},
"options": {
"type": "array",
@ -915,15 +933,25 @@
}
},
"question": {
"type": "string"
"type": "string",
"minLength": 1
},
"resultMode": {
"type": "integer",
"format": "int64"
"format": "int64",
"enum": [
0,
1
]
},
"status": {
"type": "integer",
"format": "int64"
"format": "int64",
"enum": [
0,
1,
2
]
}
}
},

44
openapi.json

@ -20,6 +20,20 @@
}
},
"schemas": {
"ActorTypes": {
"type": "string",
"enum": [
"users",
"groups",
"guests",
"emails",
"circles",
"bridged",
"bots",
"federated_users",
"phones"
]
},
"Ban": {
"type": "object",
"required": [
@ -744,7 +758,8 @@
},
"numVoters": {
"type": "integer",
"format": "int64"
"format": "int64",
"minimum": 0
},
"votedSelf": {
"type": "array",
@ -782,18 +797,21 @@
"type": "string"
},
"actorId": {
"type": "string"
"type": "string",
"minLength": 1
},
"actorType": {
"type": "string"
"$ref": "#/components/schemas/ActorTypes"
},
"id": {
"type": "integer",
"format": "int64"
"format": "int64",
"minimum": 1
},
"maxVotes": {
"type": "integer",
"format": "int64"
"format": "int64",
"minimum": 0
},
"options": {
"type": "array",
@ -802,15 +820,25 @@
}
},
"question": {
"type": "string"
"type": "string",
"minLength": 1
},
"resultMode": {
"type": "integer",
"format": "int64"
"format": "int64",
"enum": [
0,
1
]
},
"status": {
"type": "integer",
"format": "int64"
"format": "int64",
"enum": [
0,
1,
2
]
}
}
},

18
src/types/openapi/openapi-full.ts

@ -1825,6 +1825,8 @@ export type paths = {
export type webhooks = Record<string, never>;
export type components = {
schemas: {
/** @enum {string} */
ActorTypes: "users" | "groups" | "guests" | "emails" | "circles" | "bridged" | "bots" | "federated_users" | "phones";
Ban: {
/** Format: int64 */
id: number;
@ -2065,17 +2067,23 @@ export type components = {
PollDraft: {
actorDisplayName: string;
actorId: string;
actorType: string;
actorType: components["schemas"]["ActorTypes"];
/** Format: int64 */
id: number;
/** Format: int64 */
maxVotes: number;
options: string[];
question: string;
/** Format: int64 */
resultMode: number;
/** Format: int64 */
status: number;
/**
* Format: int64
* @enum {integer}
*/
resultMode: 0 | 1;
/**
* Format: int64
* @enum {integer}
*/
status: 0 | 1 | 2;
};
PollVote: {
actorDisplayName: string;

18
src/types/openapi/openapi.ts

@ -1336,6 +1336,8 @@ export type paths = {
export type webhooks = Record<string, never>;
export type components = {
schemas: {
/** @enum {string} */
ActorTypes: "users" | "groups" | "guests" | "emails" | "circles" | "bridged" | "bots" | "federated_users" | "phones";
Ban: {
/** Format: int64 */
id: number;
@ -1546,17 +1548,23 @@ export type components = {
PollDraft: {
actorDisplayName: string;
actorId: string;
actorType: string;
actorType: components["schemas"]["ActorTypes"];
/** Format: int64 */
id: number;
/** Format: int64 */
maxVotes: number;
options: string[];
question: string;
/** Format: int64 */
resultMode: number;
/** Format: int64 */
status: number;
/**
* Format: int64
* @enum {integer}
*/
resultMode: 0 | 1;
/**
* Format: int64
* @enum {integer}
*/
status: 0 | 1 | 2;
};
PollVote: {
actorDisplayName: string;

Loading…
Cancel
Save