Use the $RefParser class
mainThe $RefParser class is the default export of the library. You can use it in two ways:
- Instance methods: Create a new instance using
new $RefParser()to access properties likeschemaand$refswhich store the state of the last operation. - Static methods: Call methods directly on the class (e.g.,
$RefParser.dereference()) if you do not need to maintain state.
When using instance methods, the resulting schema or $refs object is stored in the parser.schema or parser.$refs properties respectively.
let parser = new $RefParser();
// Instance usage
let schema = await parser.dereference("my-schema.json");
console.log(parser.schema); // The dereferenced schema
console.log(parser.$refs); // The $Refs object