Skip to content

Commit

Permalink
feat(project): Agrega validación de props de OAs
Browse files Browse the repository at this point in the history
  • Loading branch information
lupomontero committed Jun 11, 2024
1 parent fb39bb8 commit 360f16a
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ export const transformLearningObjectives = async (dir, opts, meta = {}) => {
const known = !shouldValidate ? null : await loadYaml(`${opts.lo}/data.yml`);
const knownFlattened = !shouldValidate ? null : flattenLearningObjectives(known);

const allowedProps = ['id', 'optional', 'exclude'];
const parseLearningObjectives = (arr, isVariant = false) => {
const parsed = arr.map((strOrObj) => {
const obj = (
Expand All @@ -127,6 +128,12 @@ export const transformLearningObjectives = async (dir, opts, meta = {}) => {
);
}

if (Object.keys(obj).some(key => !allowedProps.includes(key))) {
throw new Error(
`Invalid learning objective prop: ${util.inspect(strOrObj)}`,
);
}

if (shouldValidate && !knownFlattened.includes(obj.id)) {
throw Object.assign(
new Error(`Unknown learning objectives: ${obj.id}.`),
Expand Down

0 comments on commit 360f16a

Please # to comment.