mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-07 00:07:07 +00:00
joi: make SchemaMap to allow plain objects
This commit is contained in:
Vendored
+5
-9
@@ -162,7 +162,7 @@ export interface ValidationResult<T> {
|
||||
}
|
||||
|
||||
export interface SchemaMap {
|
||||
[key: string]: Schema | SchemaMap | (Schema | SchemaMap)[];
|
||||
[key: string]: string | number | boolean | object | null | Schema | SchemaMap | (Schema | SchemaMap)[];
|
||||
}
|
||||
|
||||
export interface Schema extends AnySchema<Schema> {
|
||||
@@ -575,20 +575,16 @@ export interface ArraySchema extends AnySchema<ArraySchema> {
|
||||
*
|
||||
* @param type - a joi schema object to validate each array item against.
|
||||
*/
|
||||
items(...types: Schema[]): ArraySchema;
|
||||
items(...types: SchemaMap[]): ArraySchema;
|
||||
items(types: Schema[]): ArraySchema;
|
||||
items(types: SchemaMap[]): ArraySchema;
|
||||
items(...types: (Schema | SchemaMap)[]): ArraySchema;
|
||||
items(types: (Schema | SchemaMap)[]): ArraySchema;
|
||||
|
||||
/**
|
||||
* Lists the types in sequence order for the array values where:
|
||||
* @param type - a joi schema object to validate against each array item in sequence order. type can be an array of values, or multiple values can be passed as individual arguments.
|
||||
* If a given type is .required() then there must be a matching item with the same index position in the array. Errors will contain the number of items that didn't match. Any unmatched item having a label will be mentioned explicitly.
|
||||
*/
|
||||
ordered(...types: Schema[]): ArraySchema;
|
||||
ordered(...types: SchemaMap[]): ArraySchema;
|
||||
ordered(types: Schema[]): ArraySchema;
|
||||
ordered(types: SchemaMap[]): ArraySchema;
|
||||
ordered(...types: (Schema | SchemaMap)[]): ArraySchema;
|
||||
ordered(types: (Schema | SchemaMap)[]): ArraySchema;
|
||||
|
||||
/**
|
||||
* Specifies the minimum number of items in the array.
|
||||
|
||||
+15
-4
@@ -181,6 +181,17 @@ schemaMap = {
|
||||
],
|
||||
c: arrSchema
|
||||
};
|
||||
schemaMap = {
|
||||
a: 1,
|
||||
b: {
|
||||
b1: '1',
|
||||
b2: 2
|
||||
},
|
||||
c: [
|
||||
{ c1: true },
|
||||
{ c2: null }
|
||||
]
|
||||
}
|
||||
|
||||
// --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
|
||||
|
||||
@@ -892,9 +903,9 @@ const Joi3 = Joi.extend({
|
||||
language: {
|
||||
asd: 'must be exactly asd(f)',
|
||||
},
|
||||
pre (value, state, options) {
|
||||
pre(value, state, options) {
|
||||
},
|
||||
describe (description) {
|
||||
describe(description) {
|
||||
},
|
||||
rules: [
|
||||
{
|
||||
@@ -902,10 +913,10 @@ const Joi3 = Joi.extend({
|
||||
params: {
|
||||
allowF: Joi.boolean().default(false),
|
||||
},
|
||||
setup (params) {
|
||||
setup(params) {
|
||||
const fIsAllowed = params.allowF;
|
||||
},
|
||||
validate (params, value, state, options) {
|
||||
validate(params, value, state, options) {
|
||||
if (value === 'asd' || params.allowF && value === 'asdf') {
|
||||
return value;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user