https://github.com/jonluca/json-schema-walker
Walk through the properties of a json schema
https://github.com/jonluca/json-schema-walker
Last synced: about 1 year ago
JSON representation
Walk through the properties of a json schema
- Host: GitHub
- URL: https://github.com/jonluca/json-schema-walker
- Owner: jonluca
- Created: 2022-08-01T16:43:42.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2023-11-08T22:22:16.000Z (over 2 years ago)
- Last Synced: 2024-04-14T05:57:48.528Z (about 2 years ago)
- Language: TypeScript
- Size: 19.5 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# JSON Schema Walker
Loosely based on [CloudFlare's json schema tools](https://github.com/cloudflare/json-schema-tools/tree/master/workspaces/json-schema-walker)
A system that visits all schema objects in a JSON Schema document and makes callbacks before and/or after visiting all of the current schema object's subschemas.
## Usage
```typescript
import { Walker } from "json-schema-walker";
const schema = {
// your json schema
};
const walker = new Walker();
await walker.loadSchema(schema, {
cloneSchema: true,
dereference: false,
dereferenceOptions: {
dereference: {
circular: "ignore",
},
},
});
const convertSchema = (schema) => {
// do something with the schema properties
};
await walker.walk(convertSchema, walker.vocabularies.DRAFT_07);
const updatedSchema = walker.rootSchema;
```
## Circular references
Passing the options
```json
{
"dereferenceOptions": {
"dereference": {
"circular": "ignore"
}
}
}
```
will dereference all non-circular references in your schema.