Table of Contents generated with DocToc
- yup to swagger mapping (under each method, the effect of
yuptoswagger.jsis listed)yupreach(schema: Schema, path: string, value?: object, context?: object): SchemaaddMethod(schemaType: Schema, name: string, method: ()=> Schema): voidref(path: string, options: { contextPrefix: string }): Reflazy((value: any) => Schema): LazyValidationError(errors: string | Array<string>, value: any, path: string)
SchemaSchema.clone(): SchemaSchema.label(label: string): SchemaSchema.meta(metadata: object): SchemaSchema.describe(options?: ResolveOptions): SchemaDescriptionSchema.concat(schema: Schema): SchemaSchema.validate(value: any, options?: object): Promise<InferType<Schema>, ValidationError>Schema.validateSync(value: any, options?: object): InferType<Schema>Schema.validateAt(path: string, value: any, options?: object): Promise<InferType<Schema>, ValidationError>Schema.validateSyncAt(path: string, value: any, options?: object): InferType<Schema>Schema.isValid(value: any, options?: object): Promise<boolean>Schema.isValidSync(value: any, options?: object): booleanSchema.cast(value: any, options = {}): InferType<Schema>Schema.isType(value: any): value is InferType<Schema>Schema.strict(enabled: boolean = false): SchemaSchema.strip(enabled: boolean = true): SchemaSchema.withMutation(builder: (current: Schema) => void): voidSchema.default(value: any): Schema{ type: '..', default: value, ... }
Schema.getDefault(options?: object): AnySchema.nullable(): Schema{ type: '..', nullable: true, ... }
Schema.nonNullable(): Schemaremoves nullable field
Schema.defined(): SchemaSchema.optional(): Schemaremoves required field
Schema.required(message?: string | function): Schemaadd's the field to 'required' array property if type is object
Schema.notRequired(): SchemaAlias:optional()effectively reverses the above operation
Schema.typeError(message: string): SchemaSchema.oneOf(arrayOfValues: Array<any>, message?: string | function): SchemaAlias:equals{ type: '..', enum: arrayOfValues, ... }
Schema.notOneOf(arrayOfValues: Array<any>, message?: string | function){ type: '..', not: { enum: arrayOfValues }, ... }
Schema.when(keys: string | string[], builder: object | (values: any[], schema) => Schema): SchemaSchema.test(name: string, message: string | function | any, test: function): SchemaSchema.test(options: object): SchemaSchema.transform((currentValue: any, originalValue: any) => any): Schema
- mixed
- string
string.required(message?: string | function): Schemaadd's the field to 'required' array property if the string property is inside an object
string.length(limit: number | Ref, message?: string | function): Schema{ type: '..', minLength: limit, maxLength: limit, ... }
string.min(limit: number | Ref, message?: string | function): Schema{ type: '..', minLength: number, ... }
string.max(limit: number | Ref, message?: string | function): Schema{ type: '..', maxLength: number, ... }
string.matches(regex: Regex, message?: string | function): Schema{ type: '..', matches: regex, ... }string.matches(regex: Regex, options: { message: string, excludeEmptyString: bool }): Schema{ type: '..', matches: regex, ... }
string.email(message?: string | function): Schema{ type: '..', format: 'email', ... }
string.url(message?: string | function): Schema{ type: '..', format: 'url', ... }
string.uuid(message?: string | function): Schema{ type: '..', format: 'uuid', ... }
string.ensure(): Schema{ type: '..', default: '', ... }
string.trim(message?: string | function): Schemastring.lowercase(message?: string | function): Schemastring.uppercase(message?: string | function): Schema
- number
number.min(limit: number | Ref, message?: string | function): Schema{ type: 'number', minimum: number, ... }
number.max(limit: number | Ref, message?: string | function): Schema{ type: 'number', maximum: number, ... }
number.lessThan(max: number | Ref, message?: string | function): Schema{ type: 'number', maximum: (number - 1), ... }
number.moreThan(min: number | Ref, message?: string | function): Schema{ type: 'number', minimum: (number + 1), ... }
number.positive(message?: string | function): Schema{ type: 'number', minimum: 1, ... }
number.negative(message?: string | function): Schema{ type: 'number', maximum: -1, ... }
number.integer(message?: string | function): Schema{ type: 'integer', maximum: -1, ... }(type is changed)
number.truncate(): Schemanumber.round(type: 'floor' | 'ceil' | 'trunc' | 'round' = 'round'): Schema
- boolean (inherits from Schema)
- date
date.min(limit: Date | string | Ref, message?: string | function): Schema{ type: 'string', format: 'date', minLength: Date, ... }- eg.
{"type":"string","format":"date","minLength":"1970-01-01T00:00:00.000Z"}
date.max(limit: Date | string | Ref, message?: string | function): Schema{ type: 'string', format: 'date', maxLength: Date, ... }- eg.
{"type":"string","format":"date","maxLength":"1970-01-01T00:00:00.000Z"}
- array
array.of(type: Schema): this-> adds items property
array.json(): thisarray.length(length: number | Ref, message?: string | function): this{ type: 'array', minItems: number, maxItems: number }
array.min(limit: number | Ref, message?: string | function): this{ type: 'array', minItems: number }
array.max(limit: number | Ref, message?: string | function): this{ type: 'array', maxItems: number }
array.ensure(): this{ type: 'array', default: [] }- if on validation/cast a single non-array value is given, it wraps it in an array and is passed to default [ref]
array.compact(rejector: (value) => boolean): Schema
- tuple
yup.tuple()->{"type":"array","items":{"oneOf":[{"type":"string"}]}}yup.tuple([ yup.string(), yup.number() ])->{"type":"array","items":{"oneOf":[{"type":"string"},{"type":"number"}]}}
- object
- Object schema defaults
object.shape(fields: object, noSortEdges?: Array<[string, string]>): Schemaobject.json(): thisobject.concat(schemaB: ObjectSchema): ObjectSchemaobject.pick(keys: string[]): Schemaobject.omit(keys: string[]): Schemaobject.from(fromKey: string, toKey: string, alias: boolean = false): thisobject.noUnknown(onlyKnownKeys: boolean = true, message?: string | function): Schemaobject.camelCase(): Schemaobject.constantCase(): Schema