src/json-schema.js
function findReferences(schema) {
  if (schema.$ref) {
    return [schema.$ref];
  }

  let references = [];

  if (schema.allOf) {
    references = references.concat(...schema.allOf.map(findReferences));
  }

  if (schema.anyOf) {
    references = references.concat(...schema.anyOf.map(findReferences));
  }

  if (schema.oneOf) {
    references = references.concat(...schema.oneOf.map(findReferences));
  }

  if (schema.not) {
    references = references.concat(...findReferences(schema.not));
  }

  // Array

  if (schema.items) {
    if (Array.isArray(schema.items)) {
      references = references.concat(...schema.items.map(findReferences));
    } else {
      references = references.concat(findReferences(schema.items));
    }
  }

  if (schema.additionalItems && typeof schema.additionalItems === 'object') {
    references = references.concat(findReferences(schema.additionalItems));
  }

  // Object

  if (schema.properties) {
    Object.keys(schema.properties).forEach((key) => {
      references = references.concat(findReferences(schema.properties[key]));
    });
  }

  if (schema.patternProperties) {
    Object.keys(schema.patternProperties).forEach((key) => {
      references = references.concat(findReferences(schema.patternProperties[key]));
    });
  }

  if (schema.additionalProperties && typeof schema.additionalProperties === 'object') {
    references = references.concat(findReferences(schema.additionalProperties));
  }

  return references;
}
function findReferences(schema) {
  if (schema.$ref) {
    return [schema.$ref];
  }

  let references = [];

  if (schema.allOf) {
    references = references.concat(...schema.allOf.map(findReferences));
  }

  if (schema.anyOf) {
    references = references.concat(...schema.anyOf.map(findReferences));
  }

  if (schema.oneOf) {
    references = references.concat(...schema.oneOf.map(findReferences));
  }

  if (schema.not) {
    references = references.concat(...findReferences(schema.not));
  }

  // Array

  if (schema.items) {
    if (Array.isArray(schema.items)) {
      references = references.concat(...schema.items.map(findReferences));
    } else {
      references = references.concat(findReferences(schema.items));
    }
  }

  if (schema.additionalItems && typeof schema.additionalItems === 'object') {
    references = references.concat(findReferences(schema.additionalItems));
  }

  // Object

  if (schema.properties) {
    Object.keys(schema.properties).forEach((key) => {
      references = references.concat(findReferences(schema.properties[key]));
    });
  }

  if (schema.patternProperties) {
    Object.keys(schema.patternProperties).forEach((key) => {
      references = references.concat(findReferences(schema.patternProperties[key]));
    });
  }

  if (schema.additionalProperties && typeof schema.additionalProperties === 'object') {
    references = references.concat(findReferences(schema.additionalProperties));
  }

  return references;
}
function findReferences ( schema ) { if ( schema . $ref ) { return [ schema . $ref ] ; } let references = [ ] ; if ( schema . allOf ) { references = references . concat ( ... schema . allOf . map ( findReferences ) ) ; } if ( schema . anyOf ) { references = references . concat ( ... schema . anyOf . map ( findReferences ) ) ; } if ( schema . oneOf ) { references = references . concat ( ... schema . oneOf . map ( findReferences ) ) ; } if ( schema . not ) { references = references . concat ( ... findReferences ( schema . not ) ) ; } // Array if ( schema . items ) { if ( Array . isArray ( schema . items ) ) { references = references . concat ( ... schema . items . map ( findReferences ) ) ; } else { references = references . concat ( findReferences ( schema . items ) ) ; } } if ( schema . additionalItems && typeof schema . additionalItems === 'object' ) { references = references . concat ( findReferences ( schema . additionalItems ) ) ; } // Object if ( schema . properties ) { Object . keys ( schema . properties ) . forEach ( ( key ) => { references = references . concat ( findReferences ( schema . properties [ key ] ) ) ; } ) ; } if ( schema . patternProperties ) { Object . keys ( schema . patternProperties ) . forEach ( ( key ) => { references = references . concat ( findReferences ( schema . patternProperties [ key ] ) ) ; } ) ; } if ( schema . additionalProperties && typeof schema . additionalProperties === 'object' ) { references = references . concat ( findReferences ( schema . additionalProperties ) ) ; } return references ; }
Traverses the entire schema to find all of the references
@returns array of each reference that is found in the schema
Traverses the entire schema to find all of the references