Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions projects/api/src/contracts/_internal/z.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,18 @@ export function float(schema: z.ZodNumber) {
/**
* Helper function to mark a number schema as a double in OpenAPI metadata
*/
export function double(schema: z.ZodNumber) {
// Use type assertion to access the openapi method added by extendZodWithOpenApi
return (schema as z.ZodNumber & { openapi: (meta: unknown) => z.ZodNumber })
.openapi({
type: 'number',
format: 'double',
});
}

/**
* Helper function to mark a number schema as an int64 in OpenAPI metadata
*/
export function int64(schema: z.ZodNumber) {
// Use type assertion to access the openapi method added by extendZodWithOpenApi
return (schema as z.ZodNumber & { openapi: (meta: unknown) => z.ZodNumber })
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { int64, z } from '../../../_internal/z.ts';
import { double, z } from '../../../_internal/z.ts';
import { listResponseSchema } from '../../../models/index.ts';

/** Zod schema for the search list response. */
export const searchListResponseSchema = z.object({
score: int64(z.number().int()),
score: double(z.number()),
type: z.literal('list'),
list: listResponseSchema.nullish(),
});
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { movieResponseSchema } from '../../../_internal/response/movieResponseSchema.ts';
import { int64, z } from '../../../_internal/z.ts';
import { double, z } from '../../../_internal/z.ts';

/** Zod schema for the search movie response. */
export const searchMovieResponseSchema = z.object({
score: int64(z.number().int()),
score: double(z.number()),
type: z.literal('movie'),
movie: movieResponseSchema.nullish(),
});
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { int64, z } from '../../../_internal/z.ts';
import { double, z } from '../../../_internal/z.ts';
import { personResponseSchema } from '../../../people/schema/response/personResponseSchema.ts';

/** Zod schema for the search person response. */
export const searchPersonResponseSchema = z.object({
score: int64(z.number().int()),
score: double(z.number()),
type: z.literal('person'),
person: personResponseSchema.nullish(),
});
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { showResponseSchema } from '../../../_internal/response/showResponseSchema.ts';
import { int64, z } from '../../../_internal/z.ts';
import { double, z } from '../../../_internal/z.ts';

/** Zod schema for the search show response. */
export const searchShowResponseSchema = z.object({
score: int64(z.number().int()),
score: double(z.number()),
type: z.literal('show'),
show: showResponseSchema.nullish(),
});
Loading