freeCodeCamp/api/src/schemas/example.ts
renovate[bot] b48d12714a
fix(deps): update dependency @sinclair/typebox to v0.26.6 (#49855)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
2023-04-03 09:13:36 +00:00

32 lines
856 B
TypeScript

import { Static, Type } from '@fastify/type-provider-typebox';
// The schema that TypeBox generates is compatible with ajv, e.g. the
// Type.Object call below puts the following object into subSchema.
/*
{
type: 'object',
properties: {
bat: { type: 'number' },
baz: { type: 'string' }
},
required: ['bat', 'baz']
}
*/
export const subSchema = Type.Object({
bat: Type.Integer(),
baz: Type.String()
});
export const responseSchema = Type.Object({
value: Type.String(),
otherValue: Type.Boolean(),
optional: Type.Optional(Type.String())
});
// The schema types would be the only code the client needs to import
// { value: string; otherValue: boolean; optional?: string | undefined;}
export type ResponseSchema = Static<typeof responseSchema>;
// { bat: number; baz: string; }
export type SubSchema = Static<typeof subSchema>;