Skip to content

Commit 653629f

Browse files
fix: better meta validation errors (freeCodeCamp#57180)
1 parent 63db50a commit 653629f

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

curriculum/schema/meta-schema.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
const Joi = require('joi');
22

3+
const { SuperBlocks } = require('../../shared/config/curriculum');
4+
35
const slugRE = new RegExp('^[a-z0-9-]+$');
46
const slugWithSlashRE = new RegExp('^[a-z0-9-/]+$');
57

@@ -25,7 +27,10 @@ const schema = Joi.object()
2527
),
2628
isUpcomingChange: Joi.boolean().required(),
2729
dashedName: Joi.string().regex(slugRE).required(),
28-
superBlock: Joi.string().regex(slugWithSlashRE).required(),
30+
superBlock: Joi.string()
31+
.regex(slugWithSlashRE)
32+
.valid(...Object.values(SuperBlocks))
33+
.required(),
2934
order: Joi.number().when('superBlock', {
3035
is: 'full-stack-developer',
3136
then: Joi.forbidden(),
@@ -73,5 +78,5 @@ const schema = Joi.object()
7378
.unknown(false);
7479

7580
exports.metaSchemaValidator = meta => {
76-
return schema.validate(meta);
81+
return schema.validate(meta, { abortEarly: false });
7782
};

0 commit comments

Comments
 (0)