Skip to content
Open
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
130 changes: 61 additions & 69 deletions src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,85 +24,77 @@ type Schema = {
anyOf?: SchemaObject[],
};

type ObjectSchema = {
type: "object",
/**
* An object is a collection of property/value pairs. The properties keyword is used to define the object properties – you need to list the property names and specify a schema for each property.
*/
properties?: Record<string, SchemaObject>,
/**
* By default, all object properties are optional. You can specify the required properties in the required list
*/
required?: string[],
additionalProperties?: SchemaObject | ReferenceObject | boolean,
minProperties?: number,
maxProperties?: number,
};
type TypeSpecifics = {
object: {
/**
* An object is a collection of property/value pairs. The properties keyword is used to define the object properties – you need to list the property names and specify a schema for each property.
*/
properties?: Record<string, SchemaObject>,
/**
* By default, all object properties are optional. You can specify the required properties in the required list
*/
required?: string[],
additionalProperties?: SchemaObject | ReferenceObject | boolean,
minProperties?: number,
maxProperties?: number,
},

type StringSchema = {
type: "string",
format?: "date" | "date-time" | "password" | "byte" | "binary" | "email" | "uuid" | "uri" | "hostname" | "ipv4" | "ipv6",
contentMediaType?: string,
contentEncoding?: "base16" | "base32" | "base64" | "base64url",
pattern?: string,
default?: string,
enum?: string[],
minLength?: number,
maxLength?: number,
};
string: {
format?: "date" | "date-time" | "password" | "byte" | "binary" | "email" | "uuid" | "uri" | "hostname" | "ipv4" | "ipv6",
contentMediaType?: string,
contentEncoding?: "base16" | "base32" | "base64" | "base64url",
pattern?: string,
default?: string,
enum?: string[],
minLength?: number,
maxLength?: number,
},

type NumberSchema = {
type: "number",
format?: "float" | "double",
minimum?: number,
exclusiveMinimum?: number,
maximum?: number,
exclusiveMaximum?: number,
default?: number,
multipleOf?: number,
};
number: {
format?: "float" | "double",
minimum?: number,
exclusiveMinimum?: number,
maximum?: number,
exclusiveMaximum?: number,
default?: number,
multipleOf?: number,
},

type IntegerSchema = {
type: "integer",
format?: "int32" | "int64",
minimum?: number,
exclusiveMinimum?: number,
maximum?: number,
exclusiveMaximum?: number,
default?: number,
multipleOf?: number,
};

type ArraySchema = {
type: "array",
items?: SchemaObject,
prefixItems?: SchemaObject[],
minItems?: number,
maxItems?: number,
uniqueItems?: boolean,
};
integer: {
format?: "int32" | "int64",
minimum?: number,
exclusiveMinimum?: number,
maximum?: number,
exclusiveMaximum?: number,
default?: number,
multipleOf?: number,
},

type NullSchema = {
type: "null",
};
array: {
items?: SchemaObject,
prefixItems?: SchemaObject[],
minItems?: number,
maxItems?: number,
uniqueItems?: boolean,
},

type BooleanSchema = {
type: "boolean",
};
null: object,
boolean: object,
}

type UnknownSchema = {
type?: undefined,
};

type UnionSchema = {
type: (keyof TypeSpecifics)[],
} & {
[T in keyof TypeSpecifics]: TypeSpecifics[T];
}[keyof TypeSpecifics];

/**
* The Schema Object allows the definition of input and output data types. These types can be objects, but also primitives and arrays. This object is a superset of the JSON Schema Specification Draft 2020-12.
*/
export type SchemaObject = Schema & (
ObjectSchema |
StringSchema |
NumberSchema |
IntegerSchema |
ArraySchema |
NullSchema |
BooleanSchema
) | (ReferenceObject & UnknownSchema);
export type SchemaObject = Schema & ({
[T in keyof TypeSpecifics]: { type: T } & TypeSpecifics[T];
}[keyof TypeSpecifics] | UnionSchema) | (ReferenceObject & UnknownSchema);