function parseReferenceObject(context, componentName, element, returnReferenceElement) {
  const { namespace } = context;
  const { components } = context.state;

  const parseRef = (ref) => {
    if (!ref.toValue().startsWith('#/components/')) {
      return createError(namespace, "Only local references to '#/components' within the same file are supported", ref);
    }
    const referenceParts = ref.toValue().split('/');

    if (referenceParts[2] !== componentName) {
      return createError(namespace, `Only references to '${componentName}' are permitted from this location`, ref);
    }

    if (referenceParts.length !== 4) {
      return createError(namespace,
        `Only references to a reusable component inside '#/components/${componentName}' are supported`, ref);
    }

    if (!components) {
      return createError(namespace, "'#/components' is not defined", ref);
    }

    const component = components.get(referenceParts[2]);
    if (!component) {
      return createError(namespace, `'#/components/${componentName}' is not defined`, ref);
    }

    const componentId = referenceParts[3];
    if (!component.hasKey(componentId)) {
      return createError(namespace, `'${ref.toValue()}' is not defined`, ref);
    }

    if (returnReferenceElement) {
      let Element;

      const referenced = component.get(componentId);
      if (referenced instanceof context.namespace.elements.DataStructure) {
        Element = referenced.content.constructor;
      } else {
        ({ Element } = context.namespace.elements);
      }

      const element = new Element();
      element.element = componentId;
      return element;
    }

    return new namespace.elements.ParseResult(
      component
        .filter((value, key) => key.toValue() === componentId && value)
        .map(value => dereference(namespace, component, ref, value))
    );
  };

  const parseMember = R.cond([
    [hasKey('$ref'), parseString(context, name, true)],
    [isExtension, createWarning(namespace, `Extensions are not permitted in '${name}'`)],
    [R.T, createInvalidMemberWarning(namespace, name)],
  ]);

  const parseReference = pipeParseResult(namespace,
    parseObject(context, name, parseMember, requiredKeys),
    object => object.get('$ref'),
    parseRef);

  return parseReference(element);
}
/**
 * Parse Reference Object
 *
 * @param namespace {Namespace}
 * @param componentName {string}
 * @param element {Element}
 * @returns ParseResult - A parse result containing error if the referenced
 * object was not found, the referenced element, or if the referenced
 * element was not successfully parsed, an empty parse result.
 *
 * @see https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md#referenceObject
 * @private
 */
Parse Reference Object
@param namespace {Namespace}
@param componentName {string}
@param element {Element}
@returns ParseResult - A parse result containing error if the referenced
object was not found, the referenced element, or if the referenced
element was not successfully parsed, an empty parse result.


Parse Reference Object @param namespace { Namespace } @param componentName { string } @param element { Element } @returns ParseResult - A parse result containing error if the referenced object was not found the referenced element or if the referenced element was not successfully parsed an empty parse result .
function parseReferenceObject(context, componentName, element, returnReferenceElement) {
  const { namespace } = context;
  const { components } = context.state;
  const parseRef = (ref) => {
    if (!ref.toValue().startsWith('#/components/')) {
      return createError(namespace, "Only local references to '#/components' within the same file are supported", ref);
    }
    const referenceParts = ref.toValue().split('/');
    if (referenceParts[2] !== componentName) {
      return createError(namespace, `Only references to '${componentName}' are permitted from this location`, ref);
    }
    if (referenceParts.length !== 4) {
      return createError(namespace,
        `Only references to a reusable component inside '#/components/${componentName}' are supported`, ref);
    }
    if (!components) {
      return createError(namespace, "'#/components' is not defined", ref);
    }
    const component = components.get(referenceParts[2]);
    if (!component) {
      return createError(namespace, `'#/components/${componentName}' is not defined`, ref);
    }
    const componentId = referenceParts[3];
    if (!component.hasKey(componentId)) {
      return createError(namespace, `'${ref.toValue()}' is not defined`, ref);
    }
    if (returnReferenceElement) {
      let Element;
      const referenced = component.get(componentId);
      if (referenced instanceof context.namespace.elements.DataStructure) {
        Element = referenced.content.constructor;
      } else {
        ({ Element } = context.namespace.elements);
      }
      const element = new Element();
      element.element = componentId;
      return element;
    }
    return new namespace.elements.ParseResult(
      component
        .filter((value, key) => key.toValue() === componentId && value)
        .map(value => dereference(namespace, component, ref, value))
    );
  };
  const parseMember = R.cond([
    [hasKey('$ref'), parseString(context, name, true)],
    [isExtension, createWarning(namespace, `Extensions are not permitted in '${name}'`)],
    [R.T, createInvalidMemberWarning(namespace, name)],
  ]);
  const parseReference = pipeParseResult(namespace,
    parseObject(context, name, parseMember, requiredKeys),
    object => object.get('$ref'),
    parseRef);
  return parseReference(element);
}
function parseReferenceObject ( context , componentName , element , returnReferenceElement ) { const { namespace } = context ; const { components } = context . state ; const parseRef = ( ref ) => { if ( ! ref . toValue ( ) . startsWith ( '#/components/' ) ) { return createError ( namespace , "Only local references to '#/components' within the same file are supported" , ref ) ; } const referenceParts = ref . toValue ( ) . split ( '/' ) ; if ( referenceParts [ 2 ] !== componentName ) { return createError ( namespace , ` ${ componentName } ` , ref ) ; } if ( referenceParts . length !== 4 ) { return createError ( namespace , ` ${ componentName } ` , ref ) ; } if ( ! components ) { return createError ( namespace , "'#/components' is not defined" , ref ) ; } const component = components . get ( referenceParts [ 2 ] ) ; if ( ! component ) { return createError ( namespace , ` ${ componentName } ` , ref ) ; } const componentId = referenceParts [ 3 ] ; if ( ! component . hasKey ( componentId ) ) { return createError ( namespace , ` ${ ref . toValue ( ) } ` , ref ) ; } if ( returnReferenceElement ) { let Element ; const referenced = component . get ( componentId ) ; if ( referenced instanceof context . namespace . elements . DataStructure ) { Element = referenced . content . constructor ; } else { ( { Element } = context . namespace . elements ) ; } const element = new Element ( ) ; element . element = componentId ; return element ; } return new namespace . elements . ParseResult ( component . filter ( ( value , key ) => key . toValue ( ) === componentId && value ) . map ( value => dereference ( namespace , component , ref , value ) ) ) ; } ; const parseMember = R . cond ( [ [ hasKey ( '$ref' ) , parseString ( context , name , true ) ] , [ isExtension , createWarning ( namespace , ` ${ name } ` ) ] , [ R . T , createInvalidMemberWarning ( namespace , name ) ] , ] ) ; const parseReference = pipeParseResult ( namespace , parseObject ( context , name , parseMember , requiredKeys ) , object => object . get ( '$ref' ) , parseRef ) ; return parseReference ( element ) ; }
Parse Reference Object
 @param namespace {Namespace}
 @param componentName {string}
 @param element {Element}
 @returns ParseResult - A parse result containing error if the referenced
 object was not found, the referenced element, or if the referenced
 element was not successfully parsed, an empty parse result.
Parse Reference Object @param namespace { Namespace } @param componentName { string } @param element { Element } @returns ParseResult - A parse result containing error if the referenced object was not found the referenced element or if the referenced element was not successfully parsed an empty parse result .