Skip to content

Commit 1c0f45a

Browse files
committed
Update docs and typings
1 parent d3ac54f commit 1c0f45a

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

docs/ref-parser.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ This is the default export of JSON Schema $Ref Parser. You can creates instance
66
##### Properties
77
- [`schema`](#schema)
88
- [`$refs`](#refs)
9+
- [`errors`](#errors)
910

1011
##### Methods
1112
- [`dereference()`](#dereferenceschema-options-callback)
@@ -42,6 +43,13 @@ await parser.dereference("my-schema.json");
4243
parser.$refs.paths(); // => ["my-schema.json"]
4344
```
4445

46+
### `errors`
47+
The `errors` property contains all list of errors that occurred during the bundling/resolving/dereferencing process.
48+
All errors share error properties:
49+
- path - json path to the document property
50+
- message
51+
- source - the uri of document where the faulty document was referenced
52+
4553

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

lib/index.d.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ declare class $RefParser {
2525
*/
2626
$refs: $RefParser.$Refs
2727

28+
/**
29+
* List of all errors
30+
*
31+
* See https://github.com/APIDevTools/json-schema-ref-parser/blob/master/docs/ref-parser.md#errors
32+
*/
33+
errors: Array<$RefParser.GenericError | $RefParser.ResolverError | $RefParser.ParserError | $RefParser.MissingPointerError>;
34+
2835
/**
2936
* Dereferences all `$ref` pointers in the JSON Schema, replacing each reference with its resolved value. This results in a schema object that does not contain any `$ref` pointers. Instead, it's a normal JavaScript object tree that can easily be crawled and used just like any other JavaScript object. This is great for programmatic usage, especially when using tools that don't understand JSON references.
3037
*
@@ -210,6 +217,12 @@ declare namespace $RefParser {
210217
[key: string]: Partial<ResolverOptions>
211218
}
212219

220+
/**
221+
* Determines how lenient the processing should be.
222+
* If this option is enable, the processing will be performed in a bail mode - will abort upon the first exception.
223+
*/
224+
failFast?: boolean;
225+
213226
/**
214227
* The `dereference` options control how JSON Schema `$Ref` Parser will dereference `$ref` pointers within the JSON schema.
215228
*/
@@ -398,4 +411,15 @@ declare namespace $RefParser {
398411
set($ref: string, value: JSONSchema4Type | JSONSchema6Type): void
399412
}
400413

414+
export class GenericError extends Error {
415+
readonly message: string;
416+
readonly path: Array<string | number>;
417+
readonly source: string;
418+
}
419+
420+
export class ParserError extends GenericError {}
421+
export class ResolverError extends GenericError {
422+
readonly code?: string;
423+
}
424+
export class MissingPointerError extends GenericError {}
401425
}

0 commit comments

Comments
 (0)