Files
kittyBE/src/schemas/linkSchema.ts

65 lines
1.8 KiB
TypeScript

import z from 'zod';
// GET /api/v1/link/short
const shortLinkRequestSchemaQuery = z.object({
// https://zod.dev/v4?id=stringbool
length: z.coerce
.number('Length must be a number')
.min( 3, 'Length is too small (try something longer than 3)')
.max(128, 'Length is too long (try something shorter than 128)')
.optional(),
alphanum: z.stringbool('Alphanum must be a boolean')
.optional(),
case: z.enum(['lower', 'upper'])
.optional(),
withSubdomain: z.stringbool('WithSubdomain must be a boolean')
.optional()
});
export const shortLinkRequestSchema = z.object({
query: shortLinkRequestSchemaQuery
});
export type ShortLinkRequestDTO = z.TypeOf<typeof shortLinkRequestSchema>;
// GET /api/v1/link/fromWordlist
const sentenceLinkRequestSchemaQuery = z.object({
// https://zod.dev/v4?id=stringbool
withSubdomain: z.stringbool('WithSubdomain must be a boolean')
.optional()
});
export const sentenceLinkRequestSchema = z.object({
query: sentenceLinkRequestSchemaQuery
});
export type SentenceLinkRequestDTO = z.TypeOf<typeof sentenceLinkRequestSchema>;
// response for both /api/v1/link/short and /api/v1/link/fromWordlist
/**
* @swagger
* components:
* schemas:
* LinkResponseDTO:
* type: object
* required:
* - status
* - uri
* - subdomain
* properties:
* status:
* type: string
* default: ok on success, otherwise ErrorDTO with error
* uri:
* type: string
* default: generated uri
* subdomain:
* type: string
* default: subdomain or null
*/
export type LinkResponseDTO = {
status: 'ok';
uri: string;
subdomain?: string | null; // null when server does not support generating subdomains
};