Skip to content

Commit

Permalink
fix(schema): accept null for userVote
Browse files Browse the repository at this point in the history
  • Loading branch information
zenlex committed May 30, 2024
1 parent 73281ee commit 42647f3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
5 changes: 3 additions & 2 deletions public/docs/api/v0/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@
"oneOf": [
{
"type": "object",
"required": ["status", "results", "authorName"],
"required": ["status", "results", "authorName", "userVote"],
"properties": {
"authorName": { "type": "string" },
"status": { "type": "string", "enum": ["closed"] },
Expand Down Expand Up @@ -481,7 +481,8 @@
"enum": ["-2", "-1", "0", "1", "2"]
},
"comment": { "type": "string", "maxLength": 255 }
}
},
"nullable": true
},
"Expirable": {
"type": "object",
Expand Down
24 changes: 13 additions & 11 deletions src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export type ProposalState =
* @enum closed
*/
status: 'closed';
userVote?: Vote | undefined;
userVote: Vote;
results: Array<Vote>;
}
| {
Expand Down Expand Up @@ -143,13 +143,13 @@ const ProposalState: z.ZodType<ProposalState> = z.union([
z.object({
authorName: z.string(),
status: z.literal('closed'),
userVote: Vote.optional(),
userVote: Vote.nullable(),
results: z.array(Vote),
}),
z.object({
authorName: z.string().min(4),
status: z.literal('open'),
userVote: Vote.optional(),
userVote: Vote.nullish(),
}),
]);
const ProposalIndex: z.ZodType<ProposalIndex> = Paginated.and(
Expand Down Expand Up @@ -481,14 +481,16 @@ const endpoints = makeApi([
{
name: 'body',
type: 'Body',
schema: z.object({
value: z
.enum(['-2', '-1', '0', '1', '2'])
.describe(
'Ranking values: -2 (strong disinterest), -1 (slight disinterest), 0 (neutral), 1 (slight interest), 2 (strong interest)',
),
comment: z.string().max(255).optional(),
}),
schema: z
.object({
value: z
.enum(['-2', '-1', '0', '1', '2'])
.describe(
'Ranking values: -2 (strong disinterest), -1 (slight disinterest), 0 (neutral), 1 (slight interest), 2 (strong interest)',
),
comment: z.string().max(255).optional(),
})
.nullable(),
},
{
name: 'Authorization',
Expand Down

0 comments on commit 42647f3

Please sign in to comment.