src/dt2js.js
function schemaForm (data, reqStack = [], prop) {
  if (!(data instanceof Object)) {
    return data
  }
  const lastEl = reqStack[reqStack.length - 1]
  if (data.type && data.required !== false && lastEl && prop) {
    if (lastEl.props.indexOf(prop) > -1 && (prop[0] + prop[prop.length - 1]) !== '//') {
      lastEl.reqs.push(prop)
    }
  }
  delete data.required
  const isObj = data.type === 'object'
  if (isObj) {
    reqStack.push({
      'reqs': [],
      'props': Object.keys(data.properties || {})
    })
  }

  const updateWith = processNested(data, reqStack)

  data = utils.updateObjWith(data, updateWith)
  if (isObj) {
    let reqs = reqStack.pop().reqs
    // Strip duplicates from reqs
    reqs = reqs.filter(function (value, index, self) {
      return self.indexOf(value) === index
    })
    if (reqs.length > 0) {
      data.required = reqs
    }
  }

  if (data.type) {
    data = convertType(data)
    data = convertDateType(data)
  }
  if (data.displayName) {
    data = convertDisplayName(data)
  }
  if (data.properties) {
    convertPatternProperties(data)
  }
  return data
}
function schemaForm (data, reqStack = [], prop) {
  if (!(data instanceof Object)) {
    return data
  }
  const lastEl = reqStack[reqStack.length - 1]
  if (data.type && data.required !== false && lastEl && prop) {
    if (lastEl.props.indexOf(prop) > -1 && (prop[0] + prop[prop.length - 1]) !== '//') {
      lastEl.reqs.push(prop)
    }
  }
  delete data.required
  const isObj = data.type === 'object'
  if (isObj) {
    reqStack.push({
      'reqs': [],
      'props': Object.keys(data.properties || {})
    })
  }

  const updateWith = processNested(data, reqStack)

  data = utils.updateObjWith(data, updateWith)
  if (isObj) {
    let reqs = reqStack.pop().reqs
    // Strip duplicates from reqs
    reqs = reqs.filter(function (value, index, self) {
      return self.indexOf(value) === index
    })
    if (reqs.length > 0) {
      data.required = reqs
    }
  }

  if (data.type) {
    data = convertType(data)
    data = convertDateType(data)
  }
  if (data.displayName) {
    data = convertDisplayName(data)
  }
  if (data.properties) {
    convertPatternProperties(data)
  }
  return data
}
function schemaForm ( data , reqStack = [ ] , prop ) { if ( ! ( data instanceof Object ) ) { return data } const lastEl = reqStack [ reqStack . length - 1 ] if ( data . type && data . required !== false && lastEl && prop ) { if ( lastEl . props . indexOf ( prop ) > - 1 && ( prop [ 0 ] + prop [ prop . length - 1 ] ) !== '//' ) { lastEl . reqs . push ( prop ) } } delete data . required const isObj = data . type === 'object' if ( isObj ) { reqStack . push ( { 'reqs' : [ ] , 'props' : Object . keys ( data . properties || { } ) } ) } const updateWith = processNested ( data , reqStack ) data = utils . updateObjWith ( data , updateWith ) if ( isObj ) { let reqs = reqStack . pop ( ) . reqs // Strip duplicates from reqs reqs = reqs . filter ( function ( value , index , self ) { return self . indexOf ( value ) === index } ) if ( reqs . length > 0 ) { data . required = reqs } } if ( data . type ) { data = convertType ( data ) data = convertDateType ( data ) } if ( data . displayName ) { data = convertDisplayName ( data ) } if ( data . properties ) { convertPatternProperties ( data ) } return data }
Convert canonical form of RAML type to valid JSON schema.

@param  {Object} data - Data to be converted.
@param  {Array} reqStack - Stack of required properties.
@param  {string} [prop] - Property name nested objects of which are processed.
@returns  {Object}
Convert canonical form of RAML type to valid JSON schema .