whitlockjc / json-refs

Various utilities for JSON Pointers (http://tools.ietf.org/html/rfc6901) and JSON References (http://tools.ietf.org/html/draft-pbryan-zyp-json-ref-03).

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

.resolved not showing resolved reference but .refs shows properly resolved???

terencechow opened this issue · comments

Using resolveRefs I am not getting any errors but the result is not resolved. What am I doing wrong? I see that the refs have the proper values, but the resolved result doesn't show that.

What am I doing wrong?

Folder structure:

|-index.yaml
|-paths
     |-index.yaml
     |-accounts.yaml

index.yaml:

paths:
    $ref: ./paths/index.yaml

paths/index.yaml:

$ref: ./accounts.yaml

And paths/accounts.yaml:

/accounts:
    get: 
        ...

Basically I expect to see

paths:
    /accounts
         get:
             ...

But I see:

paths: 
    $ref:   ./accounts.yaml

Here is my code:


const swaggerYaml = yaml.safeLoad(fs.readFileSync(`${swaggerRootDir}/index.yaml`, 'utf8').toString())

var options = {
  filter: ['relative'],
  location: `${swaggerRootDir}/index.yaml`,
  loaderOptions: {
    processContent: function (res, callback) {
      callback(yaml.safeLoad(res.text))
    }
  }
}

resolveRefs(swaggerYaml, options).then(function (results) {
  console.log(yaml.dump(results.refs)) # --> prints out proper object at 'value'
  console.log(yaml.dump(results.resolved)) # --> prints out $ref: './accounts.yaml'
})
.catch((err) => {
  console.log('ERROR', err)
})

Looks like I had an error in my yaml.

Don't scare me like that. (joke)