UNPKG

schema2typebox

Version:

Creates typebox code from JSON schemas

76 lines (71 loc) 2.79 kB
/** * ATTENTION. This code was AUTO GENERATED by schema2typebox. * While I don't know your use case, there is a high chance that direct changes * to this file get lost. Consider making changes to the underlying JSON schema * you use to generate this file instead. The default file is called * "schema.json", perhaps have a look there! :] */ import { Kind, SchemaOptions, Static, TSchema, TUnion, Type, TypeRegistry, } from "@sinclair/typebox"; import { Value } from "@sinclair/typebox/value"; TypeRegistry.Set( "ExtendedOneOf", (schema: any, value) => 1 === schema.oneOf.reduce( (acc: number, schema: any) => acc + (Value.Check(schema, value) ? 1 : 0), 0 ) ); const OneOf = <T extends TSchema[]>( oneOf: [...T], options: SchemaOptions = {} ) => Type.Unsafe<Static<TUnion<T>>>({ ...options, [Kind]: "ExtendedOneOf", oneOf, }); export type DayOfWeek = Static<typeof DayOfWeek>; export const DayOfWeek = OneOf( [ Type.Literal("Friday", { description: "The day of the week between Thursday and Saturday.", }), Type.Literal("Monday", { description: "The day of the week between Sunday and Tuesday.", }), Type.Literal("PublicHolidays", { description: 'This stands for any day that is a public holiday; it is a placeholder for all official public holidays in some particular location. While not technically a "day of the week", it can be used with [[OpeningHoursSpecification]]. In the context of an opening hours specification it can be used to indicate opening hours on public holidays, overriding general opening hours for the day of the week on which a public holiday occurs.', }), Type.Literal("Saturday", { description: "The day of the week between Friday and Sunday.", }), Type.Literal("Sunday", { description: "The day of the week between Saturday and Monday.", }), Type.Literal("Thursday", { description: "The day of the week between Wednesday and Friday.", }), Type.Literal("Tuesday", { description: "The day of the week between Monday and Wednesday.", }), Type.Literal("Wednesday", { description: "The day of the week between Tuesday and Thursday.", }), ], { $schema: "https://json-schema.org/draft/2020-12/schema", $id: "schema:DayOfWeek", description: "The day of the week, e.g. used to specify to which day the opening hours of an OpeningHoursSpecification refer.\n\nOriginally, URLs from [GoodRelations](http://purl.org/goodrelations/v1) were used (for [[Monday]], [[Tuesday]], [[Wednesday]], [[Thursday]], [[Friday]], [[Saturday]], [[Sunday]] plus a special entry for [[PublicHolidays]]); these have now been integrated directly into schema.org.\n ", } );