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

20
lib/ResponseDefinitions.php

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

44
openapi-full.json

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

44
openapi.json

@ -20,6 +20,20 @@
} }
}, },
"schemas": { "schemas": {
"ActorTypes": {
"type": "string",
"enum": [
"users",
"groups",
"guests",
"emails",
"circles",
"bridged",
"bots",
"federated_users",
"phones"
]
},
"Ban": { "Ban": {
"type": "object", "type": "object",
"required": [ "required": [
@ -744,7 +758,8 @@
}, },
"numVoters": { "numVoters": {
"type": "integer", "type": "integer",
"format": "int64"
"format": "int64",
"minimum": 0
}, },
"votedSelf": { "votedSelf": {
"type": "array", "type": "array",
@ -782,18 +797,21 @@
"type": "string" "type": "string"
}, },
"actorId": { "actorId": {
"type": "string"
"type": "string",
"minLength": 1
}, },
"actorType": { "actorType": {
"type": "string"
"$ref": "#/components/schemas/ActorTypes"
}, },
"id": { "id": {
"type": "integer", "type": "integer",
"format": "int64"
"format": "int64",
"minimum": 1
}, },
"maxVotes": { "maxVotes": {
"type": "integer", "type": "integer",
"format": "int64"
"format": "int64",
"minimum": 0
}, },
"options": { "options": {
"type": "array", "type": "array",
@ -802,15 +820,25 @@
} }
}, },
"question": { "question": {
"type": "string"
"type": "string",
"minLength": 1
}, },
"resultMode": { "resultMode": {
"type": "integer", "type": "integer",
"format": "int64"
"format": "int64",
"enum": [
0,
1
]
}, },
"status": { "status": {
"type": "integer", "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 webhooks = Record<string, never>;
export type components = { export type components = {
schemas: { schemas: {
/** @enum {string} */
ActorTypes: "users" | "groups" | "guests" | "emails" | "circles" | "bridged" | "bots" | "federated_users" | "phones";
Ban: { Ban: {
/** Format: int64 */ /** Format: int64 */
id: number; id: number;
@ -2065,17 +2067,23 @@ export type components = {
PollDraft: { PollDraft: {
actorDisplayName: string; actorDisplayName: string;
actorId: string; actorId: string;
actorType: string;
actorType: components["schemas"]["ActorTypes"];
/** Format: int64 */ /** Format: int64 */
id: number; id: number;
/** Format: int64 */ /** Format: int64 */
maxVotes: number; maxVotes: number;
options: string[]; options: string[];
question: 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: { PollVote: {
actorDisplayName: string; actorDisplayName: string;

18
src/types/openapi/openapi.ts

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

Loading…
Cancel
Save