Skip to content

Commit

Permalink
fix: better meta validation errors (freeCodeCamp#57180)
Browse files Browse the repository at this point in the history
  • Loading branch information
ojeytonwilliams authored Nov 16, 2024
1 parent 63db50a commit 653629f
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions curriculum/schema/meta-schema.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const Joi = require('joi');

const { SuperBlocks } = require('../../shared/config/curriculum');

const slugRE = new RegExp('^[a-z0-9-]+$');
const slugWithSlashRE = new RegExp('^[a-z0-9-/]+$');

Expand All @@ -25,7 +27,10 @@ const schema = Joi.object()
),
isUpcomingChange: Joi.boolean().required(),
dashedName: Joi.string().regex(slugRE).required(),
superBlock: Joi.string().regex(slugWithSlashRE).required(),
superBlock: Joi.string()
.regex(slugWithSlashRE)
.valid(...Object.values(SuperBlocks))
.required(),
order: Joi.number().when('superBlock', {
is: 'full-stack-developer',
then: Joi.forbidden(),
Expand Down Expand Up @@ -73,5 +78,5 @@ const schema = Joi.object()
.unknown(false);

exports.metaSchemaValidator = meta => {
return schema.validate(meta);
return schema.validate(meta, { abortEarly: false });
};

0 comments on commit 653629f

Please sign in to comment.