@@ -5,12 +5,14 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
55## Development Commands
66
77### Building
8+
89``` bash
910yarn build # Compile TypeScript to dist/
1011yarn typecheck # Run TypeScript type checking without emitting files
1112```
1213
1314### Testing
15+
1416``` bash
1517yarn test # Run all tests with coverage (Vitest)
1618yarn test:node # Run tests in Node.js environment
@@ -20,26 +22,32 @@ yarn test:update # Update test snapshots
2022```
2123
2224### Code Quality
25+
2326``` bash
2427yarn lint # Run ESLint on lib/ directory
2528yarn prettier # Format all code files
2629```
2730
2831### Running Individual Tests
32+
2933To run a single test file:
34+
3035``` bash
3136npx vitest test/specs/circular/circular.spec.ts
3237```
3338
3439To run tests matching a pattern:
40+
3541``` bash
3642npx vitest --grep " circular"
3743```
3844
3945## Architecture Overview
4046
4147### Core Purpose
48+
4249This library parses, resolves, and dereferences JSON Schema ` $ref ` pointers. It handles references to:
50+
4351- External files (local filesystem)
4452- HTTP/HTTPS URLs
4553- Internal JSON pointers within schemas
@@ -49,7 +57,9 @@ This library parses, resolves, and dereferences JSON Schema `$ref` pointers. It
4957### Key Architecture Components
5058
5159#### 1. $RefParser (lib/index.ts)
60+
5261The main entry point and orchestrator class. Provides four primary operations:
62+
5363- ** parse()** : Reads a single schema file (JSON/YAML) without resolving references
5464- ** resolve()** : Parses and resolves all ` $ref ` pointers, returns a ` $Refs ` object mapping references to values
5565- ** bundle()** : Converts external ` $ref ` pointers to internal ones (single file output)
@@ -58,35 +68,44 @@ The main entry point and orchestrator class. Provides four primary operations:
5868All methods support both callback and Promise-based APIs, with multiple overload signatures.
5969
6070#### 2. $Refs (lib/refs.ts)
71+
6172A map/registry of all resolved JSON references and their values. Tracks:
73+
6274- All file paths/URLs encountered
6375- Circular reference detection
6476- Helper methods to query references by type (file, http, etc.)
6577
6678#### 3. Pointer (lib/pointer.ts)
79+
6780Represents a single JSON pointer (` #/definitions/person ` ) and implements JSON Pointer RFC 6901 spec:
81+
6882- Parses JSON pointer syntax (` / ` , ` ~0 ` , ` ~1 ` escaping)
6983- Resolves pointers to actual values within objects
7084- Handles edge cases (null values, missing properties)
7185
7286#### 4. $Ref (lib/ref.ts)
87+
7388Wraps a single reference with metadata:
89+
7490- The reference path/URL
7591- The resolved value
7692- Path type (file, http, etc.)
7793- Error information (when continueOnError is enabled)
7894
7995#### 5. Plugin System
96+
8097Two types of plugins, both configurable via options:
8198
8299** Parsers** (lib/parsers/):
100+
83101- JSON parser (json.ts)
84102- YAML parser (yaml.ts) - uses js-yaml
85103- Text parser (text.ts)
86104- Binary parser (binary.ts)
87105- Execute in order based on ` order ` property and ` canParse() ` matching
88106
89107** Resolvers** (lib/resolvers/):
108+
90109- File resolver (file.ts) - reads from filesystem (Node.js only)
91110- HTTP resolver (http.ts) - fetches from URLs using native fetch
92111- Custom resolvers can be added via options
@@ -100,7 +119,9 @@ Two types of plugins, both configurable via options:
100119** lib/dereference.ts** : Replaces all ` $ref ` pointers with actual values, handles circular references
101120
102121#### 7. Options System (lib/options.ts)
122+
103123Hierarchical configuration with defaults for:
124+
104125- Which parsers/resolvers to enable
105126- Circular reference handling (boolean or "ignore")
106127- External reference resolution (relative vs root)
@@ -132,12 +153,14 @@ Hierarchical configuration with defaults for:
132153## Testing Strategy
133154
134155Tests are organized in test/specs/ by scenario:
135- - Each scenario has test files (* .spec.ts) and fixture data
156+
157+ - Each scenario has test files (\* .spec.ts) and fixture data
136158- Tests validate parse, resolve, bundle, and dereference operations
137159- Extensive coverage of edge cases: circular refs, deep nesting, special characters in paths
138160- Browser-specific tests use test/fixtures/server.ts for HTTP mocking
139161
140162Test utilities:
163+
141164- test/utils/helper.js: Common test patterns
142165- test/utils/path.js: Path handling for cross-platform tests
143166- test/utils/serializeJson.ts: Custom snapshot serializer
0 commit comments