createValidationAnnotation(error) {
    let message;

    // join array of words
    const oxfordJoin = array => array.map((item, index) => {
      if (index === array.length - 1) {
        return `or '${item}'`;
      }

      return `'${item}'`;
    }).join(', ');

    if (error.code === 'ANY_OF_MISSING'
      && _.last(error.path) === 'type'
      && error.inner.length === 2
      && error.inner[0].code === 'ENUM_MISMATCH'
      && error.inner[1].code === 'INVALID_TYPE'
    ) {
      // Schema Object 'type' validation can contain enum mismatch and type mismatch
      // Prefer only the enum mismatch for less confusing error message
      // Schema is something like the following which causes anyOf validation
      // with two inner validation errors:
      // anyOf:
      //   - enum: ['array', 'number', ...]
      //   - type: ['string', 'array']
      this.createValidationAnnotation(error.inner[0]);
      return;
    }

    if (error.code === 'ONE_OF_MISSING'
      && error.inner.length === 2
      && error.inner[1].code === 'OBJECT_MISSING_REQUIRED_PROPERTY'
      && error.inner[1].params.length === 1 && error.inner[1].params[0] === '$ref') {
      // one of validation error containing $ref, let's skip the ref part of message
      // and only show the "main" branch. The $ref is rarely important aspect of validation.
      this.createValidationAnnotation(error.inner[0]);
      return;
    }

    if (error.code === 'ONE_OF_MISSING'
      && error.inner.every(subError => subError.code === 'OBJECT_MISSING_REQUIRED_PROPERTY')) {
      // collase a collection of "one of" required property validations into one message
      const missingProperties = oxfordJoin(error.inner.map(subError => subError.params[0]));
      message = `Object must contain either ${missingProperties} properties`;
      this.createAnnotation(annotations.VALIDATION_ERROR, error.path, message);
      return;
    }

    if (error.code === 'ENUM_MISMATCH') {
      const enumerations = oxfordJoin(error[ZSchema.schemaSymbol].enum);
      const value = error.params[0];
      message = `Value must be either ${enumerations} not '${value}'`;
    } else {
      ({ message } = error);
    }

    this.createAnnotation(annotations.VALIDATION_ERROR, error.path, message);

    if (error.inner) {
      error.inner.forEach((innerError) => {
        // TODO: I am honestly not sure what the correct behavior is
        // here. Some items will have within them a tree of other items,
        // some of which might contain more info (but it's unclear).
        // Do we treat them as their own error or do something else?
        this.createValidationAnnotation(innerError);
      });
    }
  }
// Create annotation from swagger-parser error (ZSchema validation)
Create annotation from swagger-parser error (ZSchema validation)
Create annotation from swagger - parser error ( ZSchema validation )
createValidationAnnotation(error) {
    let message;
    const oxfordJoin = array => array.map((item, index) => {
      if (index === array.length - 1) {
        return `or '${item}'`;
      }
      return `'${item}'`;
    }).join(', ');
    if (error.code === 'ANY_OF_MISSING'
      && _.last(error.path) === 'type'
      && error.inner.length === 2
      && error.inner[0].code === 'ENUM_MISMATCH'
      && error.inner[1].code === 'INVALID_TYPE'
    ) {
      this.createValidationAnnotation(error.inner[0]);
      return;
    }
    if (error.code === 'ONE_OF_MISSING'
      && error.inner.length === 2
      && error.inner[1].code === 'OBJECT_MISSING_REQUIRED_PROPERTY'
      && error.inner[1].params.length === 1 && error.inner[1].params[0] === '$ref') {
      this.createValidationAnnotation(error.inner[0]);
      return;
    }
    if (error.code === 'ONE_OF_MISSING'
      && error.inner.every(subError => subError.code === 'OBJECT_MISSING_REQUIRED_PROPERTY')) {
      const missingProperties = oxfordJoin(error.inner.map(subError => subError.params[0]));
      message = `Object must contain either ${missingProperties} properties`;
      this.createAnnotation(annotations.VALIDATION_ERROR, error.path, message);
      return;
    }
    if (error.code === 'ENUM_MISMATCH') {
      const enumerations = oxfordJoin(error[ZSchema.schemaSymbol].enum);
      const value = error.params[0];
      message = `Value must be either ${enumerations} not '${value}'`;
    } else {
      ({ message } = error);
    }
    this.createAnnotation(annotations.VALIDATION_ERROR, error.path, message);
    if (error.inner) {
      error.inner.forEach((innerError) => {
        this.createValidationAnnotation(innerError);
      });
    }
  }
createValidationAnnotation ( error ) { let message ; const oxfordJoin = array => array . map ( ( item , index ) => { if ( index === array . length - 1 ) { return ` ${ item } ` ; } return ` ${ item } ` ; } ) . join ( ', ' ) ; if ( error . code === 'ANY_OF_MISSING' && _ . last ( error . path ) === 'type' && error . inner . length === 2 && error . inner [ 0 ] . code === 'ENUM_MISMATCH' && error . inner [ 1 ] . code === 'INVALID_TYPE' ) { this . createValidationAnnotation ( error . inner [ 0 ] ) ; return ; } if ( error . code === 'ONE_OF_MISSING' && error . inner . length === 2 && error . inner [ 1 ] . code === 'OBJECT_MISSING_REQUIRED_PROPERTY' && error . inner [ 1 ] . params . length === 1 && error . inner [ 1 ] . params [ 0 ] === '$ref' ) { this . createValidationAnnotation ( error . inner [ 0 ] ) ; return ; } if ( error . code === 'ONE_OF_MISSING' && error . inner . every ( subError => subError . code === 'OBJECT_MISSING_REQUIRED_PROPERTY' ) ) { const missingProperties = oxfordJoin ( error . inner . map ( subError => subError . params [ 0 ] ) ) ; message = ` ${ missingProperties } ` ; this . createAnnotation ( annotations . VALIDATION_ERROR , error . path , message ) ; return ; } if ( error . code === 'ENUM_MISMATCH' ) { const enumerations = oxfordJoin ( error [ ZSchema . schemaSymbol ] . enum ) ; const value = error . params [ 0 ] ; message = ` ${ enumerations } ${ value } ` ; } else { ( { message } = error ) ; } this . createAnnotation ( annotations . VALIDATION_ERROR , error . path , message ) ; if ( error . inner ) { error . inner . forEach ( ( innerError ) => { this . createValidationAnnotation ( innerError ) ; } ) ; } }
Create annotation from swagger-parser error (ZSchema validation)
Create annotation from swagger - parser error ( ZSchema validation )
// join array of words // Schema Object 'type' validation can contain enum mismatch and type mismatch // Prefer only the enum mismatch for less confusing error message // Schema is something like the following which causes anyOf validation // with two inner validation errors: // anyOf: //   - enum: ['array', 'number', ...] //   - type: ['string', 'array'] // one of validation error containing $ref, let's skip the ref part of message // and only show the "main" branch. The $ref is rarely important aspect of validation. // collase a collection of "one of" required property validations into one message // TODO: I am honestly not sure what the correct behavior is // here. Some items will have within them a tree of other items, // some of which might contain more info (but it's unclear). // Do we treat them as their own error or do something else?