Repository: freeCodeCamp/freeCodeCamp
File: curriculum/schema/challenge-schema.js (JavaScript)

Code before:
  isLastChallengeInBlock: Joi.boolean().required(),
  videoUrl: Joi.string().allow(''),
  fillInTheBlank: Joi.object().keys({
    sentence: Joi.string().required(),
    blanks: Joi.array()
      .items(
        Joi.object().keys({
          answer: Joi.string().required(),
          feedback: Joi.string().allow(null)
        })
      )
      .required()
  }),
  forumTopicId: Joi.number(),
  id: Joi.objectId().required(),
  lang: Joi.string(),
  inputType: Joi.when('challengeType', {
    is: challengeTypes.fillInTheBlank,
    then: Joi.when('superBlock', {
      is: Joi.valid(SuperBlocks.A1Chinese, SuperBlocks.A2Chinese),
      then: Joi.string().valid('pinyin-tone', 'pinyin-to-hanzi').optional(),
      otherwise: Joi.forbidden()
    }),
    otherwise: Joi.forbidden()
  }),
  instructions: Joi.string().when('challengeType', {
    is: [challengeTypes.pythonProject, challengeTypes.codeAllyCert],
    then: Joi.string().min(1).required(),
    otherwise: Joi.string().allow('')
  }),
  isComingSoon: Joi.bool(),
  module: Joi.string().when('superBlock', {
    is: chapterBasedSuperBlocks,
    then: Joi.required(),
    otherwise: Joi.optional()
  }),
  msTrophyId: Joi.when('challengeType', {
    is: [challengeTypes.msTrophy],
    then: Joi.string().required()
  }),
  notes: Joi.string().allow(''),
  order: Joi.number(),
  prerequisites: Joi.when('challengeType', {
    is: [challengeTypes.exam],
    then: Joi.array().items(prerequisitesJoi)
  }),
  // video challenges only:
  videoId: Joi.when('challengeType', {
    is: [challengeTypes.video],
    then: Joi.string().required()
  }),

Review comment (suggestion):
@miyaliu666 I'm adding a validation here for Chinese challenges.

This check means a challenge can have `inputType` if:
- It belongs to one of the Chinese super blocks, and
- It's a fill-in-the-blank challenge

The possible values are `pinyin-tone` and `pinyin-to-hanzi`.

I'm not marking the property as required yet, so we don't have to coordinate the merge order. But I'd like to confirm if we should make it required later, meaning all Chinese fill-in-the-blank challenges must specify `inputType`. I don't think we'll have a Chinese fill-in-the-blank challenge that uses the default input.

Code after:
  ).required(),
  isLastChallengeInBlock: Joi.boolean().required(),
  videoUrl: Joi.string().allow(''),
  fillInTheBlank: Joi.object().keys({
    sentence: Joi.string().required(),
    blanks: Joi.array()
      .items(
        Joi.object().keys({
          answer: Joi.string().required(),
          feedback: Joi.string().allow(null)
        })
      )
      .required()
  }),
  forumTopicId: Joi.number(),
  id: Joi.objectId().required(),
  lang: Joi.string().when('superBlock', {
    is: languageSuperBlocks,
    then: Joi.valid('en-US', 'es', 'zh-CN').required(),
    otherwise: Joi.valid('en')
  }),
  inputType: Joi.when('challengeType', {
    is: challengeTypes.fillInTheBlank,
    then: Joi.when('superBlock', {
      is: Joi.valid(SuperBlocks.A1Chinese, SuperBlocks.A2Chinese),
      then: Joi.string().valid('pinyin-tone', 'pinyin-to-hanzi').optional(),
      otherwise: Joi.forbidden()
    }),
    otherwise: Joi.forbidden()
  }),
  instructions: Joi.string().when('challengeType', {
    is: [challengeTypes.pythonProject, challengeTypes.codeAllyCert],
    then: Joi.string().min(1).required(),
    otherwise: Joi.string().allow('')
  }),
  isComingSoon: Joi.bool(),
  module: Joi.string().when('superBlock', {
    is: chapterBasedSuperBlocks,
    then: Joi.required(),
    otherwise: Joi.optional()
  }),
  msTrophyId: Joi.when('challengeType', {
    is: [challengeTypes.msTrophy],
    then: Joi.string().required()
  }),
  notes: Joi.string().allow(''),
  order: Joi.number(),
  prerequisites: Joi.when('challengeType', {
    is: [challengeTypes.exam],
    then: Joi.array().items(prerequisitesJoi)
  }),