Skip to content

Commit 067afb3

Browse files
authored
chore: drop binary parser (#60)
BREAKING CHANGE: binary parser is no longer bundled
1 parent 8fb793b commit 067afb3

File tree

16 files changed

+28
-184
lines changed

16 files changed

+28
-184
lines changed

docs/options.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,15 @@ $RefParser.dereference("my-schema.yaml", {
4040
-------------------
4141
The `parse` options determine how different types of files will be parsed.
4242

43-
JSON Schema $Ref Parser comes with built-in JSON, YAML, plain-text, and binary parsers, any of which you can configure or disable. You can also add [your own custom parsers](plugins/parsers.md) if you want.
44-
45-
|Option(s) |Type |Description
46-
|:----------------------------|:----------|:------------
47-
|`json`<br>`yaml`<br>`text`<br>`binary`|`object` `boolean`|These are the built-in parsers. In addition, you can add [your own custom parsers](plugins/parsers.md)<br><br>To disable a parser, just set it to `false`.
48-
|`json.order` `yaml.order` `text.order` `binary.order`|`number`|Parsers run in a specific order, relative to other parsers. For example, a parser with `order: 5` will run _before_ a parser with `order: 10`. If a parser is unable to successfully parse a file, then the next parser is tried, until one succeeds or they all fail.<br><br>You can change the order in which parsers run, which is useful if you know that most of your referenced files will be a certain type, or if you add [your own custom parser](plugins/parsers.md) that you want to run _first_.
49-
|`json.allowEmpty` `yaml.allowEmpty` `text.allowEmpty` `binary.allowEmpty`|`boolean`|All of the built-in parsers allow empty files by default. The JSON and YAML parsers will parse empty files as `undefined`. The text parser will parse empty files as an empty string. The binary parser will parse empty files as an empty byte array.<br><br>You can set `allowEmpty: false` on any parser, which will cause an error to be thrown if a file empty.
50-
|`json.canParse` `yaml.canParse` `text.canParse` `binary.canParse`|`boolean`, `RegExp`, `string`, `array`, `function`|Determines which parsers will be used for which files.<br><br>A regular expression can be used to match files by their full path. A string (or array of strings) can be used to match files by their file extension. Or a function can be used to perform more complex matching logic. See the [custom parser](plugins/parsers.md) docs for details.
51-
|`text.encoding`|`string` |The encoding to use when parsing text-based files. The default is "utf8".
43+
JSON Schema $Ref Parser comes with built-in JSON, YAML, and plain-text parsers, any of which you can configure or disable. You can also add [your own custom parsers](plugins/parsers.md) if you want.
44+
45+
| Option(s) |Type |Description
46+
|:-----------------------------------------------------------------------|:----------|:------------
47+
| `json`<br>`yaml`<br>`text` |`object` `boolean`|These are the built-in parsers. In addition, you can add [your own custom parsers](plugins/parsers.md)<br><br>To disable a parser, just set it to `false`.
48+
| `json.order` `yaml.order` `text.order` |`number`|Parsers run in a specific order, relative to other parsers. For example, a parser with `order: 5` will run _before_ a parser with `order: 10`. If a parser is unable to successfully parse a file, then the next parser is tried, until one succeeds or they all fail.<br><br>You can change the order in which parsers run, which is useful if you know that most of your referenced files will be a certain type, or if you add [your own custom parser](plugins/parsers.md) that you want to run _first_.
49+
| `json.allowEmpty` `yaml.allowEmpty` `text.allowEmpty` |`boolean`|All of the built-in parsers allow empty files by default. The JSON and YAML parsers will parse empty files as `undefined`. The text parser will parse empty files as an empty string.
50+
| `json.canParse` `yaml.canParse` `text.canParse` |`boolean`, `RegExp`, `string`, `array`, `function`|Determines which parsers will be used for which files.<br><br>A regular expression can be used to match files by their full path. A string (or array of strings) can be used to match files by their file extension. Or a function can be used to perform more complex matching logic. See the [custom parser](plugins/parsers.md) docs for details.
51+
| `text.encoding` |`string` |The encoding to use when parsing text-based files. The default is "utf8".
5252

5353

5454
`resolve` Options

docs/plugins/parsers.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Custom Parsers
22
==========================
33

4-
JSON Schema $Ref Parser comes with built-in JSON, YAML, plain-text, and binary parsers, but you can add your own parsers to support additional file types, or even replace any of the built-in parsers with your own custom implementation.
4+
JSON Schema $Ref Parser comes with built-in JSON, YAML, and plain-text parsers, but you can add your own parsers to support additional file types, or even replace any of the built-in parsers with your own custom implementation.
55

66
You can see the source code for any of the built-in parsers [right here](../../lib/parsers).
77

@@ -26,7 +26,7 @@ $RefParser.dereference(mySchema, { parse: { csv: myParser }});
2626
```
2727

2828
#### The `order` property
29-
All parsers have an `order` property, even the built-in parsers. If you don't specify an `order` property, then your parser will run last. Specifying `order: 1`, like we did in this example, will make your parser run first. Or you can squeeze your parser in-between some of the built-in parsers. For example, `order: 201` would make it run _after_ the JSON and YAML parsers, but _before_ the plain-text and binary parsers. You can see the order of all the built-in parsers by looking at [their source code](../../lib/parsers).
29+
All parsers have an `order` property, even the built-in parsers. If you don't specify an `order` property, then your parser will run last. Specifying `order: 1`, like we did in this example, will make your parser run first. Or you can squeeze your parser in-between some of the built-in parsers. For example, `order: 201` would make it run _after_ the JSON and YAML parsers, but _before_ the plain-text parser. You can see the order of all the built-in parsers by looking at [their source code](../../lib/parsers).
3030

3131
The `order` property and `canParse` property are related to each other. For each file that JSON Schema $Ref Parser needs to parse, it first determines which parsers _can_ parse that file by checking their `canParse` property. If only one parser matches a file, then _only_ that one parser is called, regardless of its `order`. If multiple parsers match a file, then those parsers are tried _in order_ until one of them successfully parses the file. Once a parser successfully parses the file, the rest of the parsers are skipped.
3232

lib/options.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
const jsonParser = require("./parsers/json");
55
const yamlParser = require("./parsers/yaml");
66
const textParser = require("./parsers/text");
7-
const binaryParser = require("./parsers/binary");
87
const fileResolver = require("./resolvers/file");
98
const httpResolver = require("./resolvers/http");
109

@@ -32,7 +31,6 @@ $RefParserOptions.defaults = {
3231
json: jsonParser,
3332
yaml: yamlParser,
3433
text: textParser,
35-
binary: binaryParser,
3634
},
3735

3836
/**

lib/parsers/binary.js

Lines changed: 0 additions & 55 deletions
This file was deleted.

test/specs/blank/blank.spec.js

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -75,33 +75,17 @@ describe("Blank files", () => {
7575
path.abs("specs/blank/files/blank.yaml"), parsedSchema.yaml,
7676
path.abs("specs/blank/files/blank.json"), parsedSchema.json,
7777
path.abs("specs/blank/files/blank.txt"), parsedSchema.text,
78-
path.abs("specs/blank/files/blank.png"), parsedSchema.binary,
7978
path.abs("specs/blank/files/blank.foo"), parsedSchema.unknown
8079
));
8180

8281
it("should dereference successfully", async () => {
8382
let schema = await $RefParser.dereference(path.rel("specs/blank/blank.yaml"));
84-
schema.binary = helper.convertNodeBuffersToPOJOs(schema.binary);
8583
expect(schema).to.deep.equal(dereferencedSchema);
8684
});
8785

8886
it("should bundle successfully", async () => {
8987
let schema = await $RefParser.bundle(path.rel("specs/blank/blank.yaml"));
90-
schema.binary = helper.convertNodeBuffersToPOJOs(schema.binary);
9188
expect(schema).to.deep.equal(dereferencedSchema);
9289
});
93-
94-
it('should throw an error if "allowEmpty" is disabled', async () => {
95-
try {
96-
await $RefParser.dereference(path.rel("specs/blank/blank.yaml"), { parse: { binary: { allowEmpty: false }}});
97-
helper.shouldNotGetCalled();
98-
}
99-
catch (err) {
100-
expect(err).to.be.an.instanceOf(SyntaxError);
101-
expect(err.message).to.contain("Error parsing ");
102-
expect(err.message).to.contain("blank/files/blank.png");
103-
expect(err.message).to.contain("Parsed value is empty");
104-
}
105-
});
10690
});
10791
});

test/specs/blank/blank.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,5 @@ yaml:
44
$ref: files/blank.yaml
55
text:
66
$ref: files/blank.txt
7-
binary:
8-
$ref: files/blank.png
97
unknown:
108
$ref: files/blank.foo

test/specs/blank/dereferenced.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,5 @@ module.exports = {
44
json: undefined,
55
yaml: undefined,
66
text: "",
7-
binary: { type: "Buffer", data: []},
87
unknown: undefined
98
};

test/specs/blank/files/blank.png

Whitespace-only changes.

test/specs/blank/parsed.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@ module.exports =
1212
text: {
1313
$ref: "files/blank.txt"
1414
},
15-
binary: {
16-
$ref: "files/blank.png"
17-
},
1815
unknown: {
1916
$ref: "files/blank.foo"
2017
},
@@ -26,7 +23,5 @@ module.exports =
2623

2724
text: "",
2825

29-
binary: { type: "Buffer", data: []},
30-
3126
unknown: undefined
3227
};

0 commit comments

Comments
 (0)