From 42a3162e0b18c74be82cbf1330197eed408e1229 Mon Sep 17 00:00:00 2001 From: spiffytech Date: Tue, 26 Apr 2016 13:00:27 -0400 Subject: [PATCH 1/2] Joi: support alternatives() without parameters. Fix alternatives() not returning interface with try() member. --- joi/joi-tests.ts | 3 +++ joi/joi.d.ts | 5 +++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/joi/joi-tests.ts b/joi/joi-tests.ts index a00543fe4e..bfb039eced 100644 --- a/joi/joi-tests.ts +++ b/joi/joi-tests.ts @@ -732,6 +732,9 @@ namespace common { // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- +schema = Joi.alternatives(); +schema = Joi.alternatives().try(schemaArr); + schema = Joi.alternatives(schemaArr); schema = Joi.alternatives(schema, anySchema, boolSchema); diff --git a/joi/joi.d.ts b/joi/joi.d.ts index d9ee7c20d1..6b9d1dbefa 100644 --- a/joi/joi.d.ts +++ b/joi/joi.d.ts @@ -747,8 +747,9 @@ declare module 'joi' { /** * Generates a type that will match one of the provided alternative schemas */ - export function alternatives(types: Schema[]): Schema; - export function alternatives(type1: Schema, type2: Schema, ...types: Schema[]): Schema; + export function alternatives(): AlternativesSchema; + export function alternatives(types: Schema[]): AlternativesSchema; + export function alternatives(type1: Schema, type2: Schema, ...types: Schema[]): AlternativesSchema; /** * Validates a value using the given schema and options. From 748690dd90f6a45dfedc875f04eb62976cffcc9d Mon Sep 17 00:00:00 2001 From: spiffytech Date: Tue, 26 Apr 2016 13:12:33 -0400 Subject: [PATCH 2/2] Joi: support non-array variant of alternatives().try() --- joi/joi-tests.ts | 1 + joi/joi.d.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/joi/joi-tests.ts b/joi/joi-tests.ts index bfb039eced..f12552ead1 100644 --- a/joi/joi-tests.ts +++ b/joi/joi-tests.ts @@ -734,6 +734,7 @@ namespace common { schema = Joi.alternatives(); schema = Joi.alternatives().try(schemaArr); +schema = Joi.alternatives().try(schema, schema); schema = Joi.alternatives(schemaArr); schema = Joi.alternatives(schema, anySchema, boolSchema); diff --git a/joi/joi.d.ts b/joi/joi.d.ts index 6b9d1dbefa..8f9fa6db95 100644 --- a/joi/joi.d.ts +++ b/joi/joi.d.ts @@ -691,6 +691,7 @@ declare module 'joi' { export interface AlternativesSchema extends AnySchema { try(schemas: Schema[]): AlternativesSchema; + try(type1: Schema, type2: Schema, ...types: Schema[]): AlternativesSchema; when(ref: string, options: WhenOptions): AlternativesSchema; when(ref: Reference, options: WhenOptions): AlternativesSchema; }