chore: validation reuses endpoints schema

This commit is contained in:
Dan Ribbens
2022-08-17 13:06:58 -04:00
parent 040833ead8
commit 771bbaedbc
5 changed files with 35 additions and 17 deletions

View File

@@ -1,5 +1,6 @@
import joi from 'joi';
import { componentSchema } from '../../utilities/componentSchema';
import { endpointsSchema } from '../../config/schema';
const strategyBaseSchema = joi.object().keys({
refresh: joi.boolean(),
@@ -61,14 +62,7 @@ const collectionSchema = joi.object().keys({
afterRefresh: joi.array().items(joi.func()),
afterForgotPassword: joi.array().items(joi.func()),
}),
endpoints: joi.array().items(joi.object({
path: joi.string(),
method: joi.string().valid('get', 'head', 'post', 'put', 'patch', 'delete', 'connect', 'options'),
handler: joi.alternatives().try(
joi.array().items(joi.func()),
joi.func(),
),
})),
endpoints: endpointsSchema,
auth: joi.alternatives().try(
joi.object({
tokenExpiration: joi.number(),

View File

@@ -5,6 +5,15 @@ const component = joi.alternatives().try(
joi.func(),
);
export const endpointsSchema = joi.array().items(joi.object({
path: joi.string(),
method: joi.string().valid('get', 'head', 'post', 'put', 'patch', 'delete', 'connect', 'options'),
handler: joi.alternatives().try(
joi.array().items(joi.func()),
joi.func(),
),
}));
export default joi.object({
serverURL: joi.string()
.uri()
@@ -33,6 +42,7 @@ export default joi.object({
outputFile: joi.string(),
}),
collections: joi.array(),
endpoints: endpointsSchema,
globals: joi.array(),
admin: joi.object({
user: joi.string(),

View File

@@ -1,5 +1,6 @@
import joi from 'joi';
import { componentSchema } from '../../utilities/componentSchema';
import { endpointsSchema } from '../../config/schema';
const globalSchema = joi.object().keys({
slug: joi.string().required(),
@@ -18,14 +19,7 @@ const globalSchema = joi.object().keys({
beforeRead: joi.array().items(joi.func()),
afterRead: joi.array().items(joi.func()),
}),
endpoints: joi.array().items(joi.object({
path: joi.string(),
method: joi.string().valid('get', 'head', 'post', 'put', 'patch', 'delete', 'connect', 'options'),
handler: joi.alternatives().try(
joi.array().items(joi.func()),
joi.func(),
),
})),
endpoints: endpointsSchema,
access: joi.object({
read: joi.func(),
readVersions: joi.func(),