public static fromJSON()

in integ/lib/thinkbox-docker-image-overrides.ts [39:66]


  public static fromJSON(json: string): ECRImageOverrides {
    const obj = JSON.parse(json);

    // Validate the input JSON
    const errors = [];
    [
      'repositoryArn',
      'imageOverrides',
    ].forEach(prop => {
      if (!(prop in obj)) {
        errors.push(`Property ${prop} was expected but not found in ${obj}`);
      }
    });
    if (!(obj.imageOverrides instanceof Object)) {
      errors.push(`Expected Object for imageOverrides but found ${typeof(obj.imageOverrides)}`);
    }
    Object.keys(obj.imageOverrides).forEach(key => {
      if (!Object.values(Recipes).includes(key as Recipes)) {
        errors.push(`Key ${key} in imageOverrides is invalid. Must be in: [${Object.values(Recipes)}].`);
      }
    });

    if (errors.length > 0) {
      throw new Error(`Invalid JSON for ECRImageOverrides: ${errors.join('\n')}`);
    }

    return obj as ECRImageOverrides;
  }