Skip to content

Commit

Permalink
Rolled-back PR APIDevTools#103 to address some implementation problems
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesMessinger committed Oct 23, 2018
1 parent d91c780 commit d8b0769
Show file tree
Hide file tree
Showing 8 changed files with 1 addition and 105 deletions.
3 changes: 0 additions & 3 deletions docs/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,3 @@ The `dereference` options control how JSON Schema $Ref Parser will dereference `
|Option(s) |Type |Description
|:---------------------|:-------------------|:------------
|`circular`|`boolean` or `"ignore"`|Determines whether [circular `$ref` pointers](README.md#circular-refs) are handled.<br><br>If set to `false`, then a `ReferenceError` will be thrown if the schema contains any circular references.<br><br> If set to `"ignore"`, then circular references will simply be ignored. No error will be thrown, but the [`$Refs.circular`](refs.md#circular) property will still be set to `true`.
|`saveOriginalRefs` | `boolean` | If set to true `dereference` will preserve information about original
`$ref` in the object metadata which can be later retrieved using [`$RefParser.getMetadata`](ref-parser.md#getmetadata)

21 changes: 0 additions & 21 deletions docs/ref-parser.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ This is the default export of JSON Schema $Ref Parser. You can creates instance
- [`schema`](#schema)
- [`$refs`](#refs)

##### Static Methods
- [`getMetadata()`](#getmetadata)

##### Methods
- [`dereference()`](#dereferenceschema-options-callback)
- [`bundle()`](#bundleschema-options-callback)
Expand Down Expand Up @@ -49,24 +46,6 @@ parser.dereference("my-schema.json")
});
```

### `getMetadata()`

Extracts metadata saved by [`dereference`](#dereferenceschema-options-callback).

When using [`dereference`](#dereferenceschema-options-callback) information about original `$ref` is lost. To preserve it [`dereference.saveOriginalRefs`](options.md#dereference-options) option can be used.

```js
// var obj = dereferenced value
var meta = $RefParser.getMetadata(obj.properties.a)
```

Metadata object contains the following information:

- `$ref` - original `$ref`
- `pathFromRoot` - path from the root of the document
- `path` - absolute path



### `dereference(schema, [options], [callback])`

Expand Down
11 changes: 1 addition & 10 deletions lib/dereference.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
var $Ref = require('./ref'),
Pointer = require('./pointer'),
ono = require('ono'),
url = require('./util/url'),
setMetadata = require('./util/meta').setMetadata;
url = require('./util/url');

module.exports = dereference;

Expand Down Expand Up @@ -126,14 +125,6 @@ function dereference$Ref ($ref, path, pathFromRoot, parents, $refs, options) {
dereferencedValue.$ref = pathFromRoot;
}

if (options.dereference.saveOriginalRefs) {
setMetadata(dereferencedValue, {
$ref: $ref.$ref,
path: path,
pathFromRoot: pathFromRoot,
});
}

return {
circular: circular,
value: dereferencedValue
Expand Down
4 changes: 0 additions & 4 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,11 @@ var Options = require('./options'),
bundle = require('./bundle'),
dereference = require('./dereference'),
url = require('./util/url'),
getMetadata = require('./util/meta').getMetadata,
setMetadata = require('./util/meta').setMetadata,
maybe = require('call-me-maybe'),
ono = require('ono');

module.exports = $RefParser;
module.exports.YAML = require('./util/yaml');
module.exports.getMetadata = getMetadata;
module.exports.setMetdata = setMetadata;

/**
* This class parses a JSON schema, builds a map of its JSON references and their resolved values,
Expand Down
28 changes: 0 additions & 28 deletions lib/util/meta.js

This file was deleted.

1 change: 0 additions & 1 deletion test/specs/metadata/external.yaml

This file was deleted.

29 changes: 0 additions & 29 deletions test/specs/metadata/metadata.spec.js

This file was deleted.

9 changes: 0 additions & 9 deletions test/specs/metadata/spec.yaml

This file was deleted.

0 comments on commit d8b0769

Please sign in to comment.