Files
freeCodeCamp/api/schemas/example.ts
Oliver Eyton-Williams c2d149ba85 feat(api): create a demo type provider for typebox (#49536)
* feat: create a demo type provider for typebox

* feat: validate reply + share type

* fix: prettify
2023-03-15 14:21:25 +00:00

32 lines
843 B
TypeScript

import { Static, Type } from '@sinclair/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>;