From 617eac56d0817b37ca5fe2615a036af149e1b861 Mon Sep 17 00:00:00 2001 From: Tiger Oakes Date: Fri, 8 Feb 2019 23:11:42 -0800 Subject: [PATCH] Update koa-joi-router output object types --- types/koa-joi-router/index.d.ts | 4 +++- types/koa-joi-router/koa-joi-router-tests.ts | 12 ++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/types/koa-joi-router/index.d.ts b/types/koa-joi-router/index.d.ts index 54cf148240..8ee1563370 100644 --- a/types/koa-joi-router/index.d.ts +++ b/types/koa-joi-router/index.d.ts @@ -31,6 +31,8 @@ declare namespace createRouter { type Method = (path: string|RegExp, handlerOrConfig: Handler | object, ...handlers: Handler[]) => Router; + type OutputValidation = { body: Joi.SchemaLike } | { headers: Joi.SchemaLike }; + interface Spec { method: string|string[]; path: string|RegExp; @@ -47,7 +49,7 @@ declare namespace createRouter { formOptions?: CoBody.Options; jsonOptions?: CoBody.Options; multipartOptions?: CoBody.Options; - output?: {[status: string]: Joi.SchemaLike}; + output?: {[status: string]: OutputValidation}; continueOnError?: boolean; }; meta?: any; diff --git a/types/koa-joi-router/koa-joi-router-tests.ts b/types/koa-joi-router/koa-joi-router-tests.ts index 160c3834c1..050ad4d5a1 100644 --- a/types/koa-joi-router/koa-joi-router-tests.ts +++ b/types/koa-joi-router/koa-joi-router-tests.ts @@ -41,8 +41,16 @@ const spec4: router.Spec = { validate: { type: 'json', output: { - 201: Joi.object(), - '400,404': Joi.object(), + 201: { + body: Joi.object(), + }, + '400,404': { + headers: Joi.object(), + body: Joi.object(), + }, + '500-599': { + headers: Joi.object(), + }, }, jsonOptions: { limit: '10kb'