# @microfleet/schema-tools

> This package resolves JSON Schemas that `@microfleet/plugin-validator` and `@microfleet/core` uses for Response and Request validation. Additionally, this package parse resolved JSON Schema into specific data structures for additional schema structure pro

Latest version **0.1.3** (published 2020-09-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install @microfleet/schema-tools
pnpm add @microfleet/schema-tools
yarn add @microfleet/schema-tools
bun add @microfleet/schema-tools
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: no vulnerabilities; high maintenance score.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 0.1.3 |
| Published | 2020-09-17 |
| First published | 2020-09-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 5 |
| Unpacked size | 65.5 KB |
| Known vulnerabilities | 0 (+3 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Vitaly Aminev |
| Maintainers | torinasakura, avvs |

## Links

- npm: https://www.npmjs.com/package/@microfleet/schema-tools
- Repository: https://github.com/microfleet/docgen
- Homepage: https://github.com/microfleet/docgen#readme
- Issues: https://github.com/microfleet/docgen/issues
- npm.io page: https://npm.io/package/@microfleet/schema-tools

## Dependencies (5)

- [lodash](https://npm.io/package/lodash.md) ^4.17.19
- [deasync](https://npm.io/package/deasync.md) ^0.1.20
- [json-ptr](https://npm.io/package/json-ptr.md) ^1.3.2
- [fast-glob](https://npm.io/package/fast-glob.md) ^3.2.4
- [common-errors](https://npm.io/package/common-errors.md) ^1.2.0

## Recent versions

- 0.1.3 (latest) — 2020-09-17
- 0.1.2 — 2020-09-15

## README

# Microfleet Json Schema Tools

This package resolves JSON Schemas that `@microfleet/plugin-validator` and `@microfleet/core` uses for Response and Request validation. Additionally, this package parse resolved JSON Schema into specific data structures for additional schema structure processing or documentation generation.

## Install
`yarn add @microfleet/schema-tools`

## Usage

### Resolve references

Example schemas:
```json
// schemas/common.json
{
  "$id": "common",
  "definitions": {
    "myDefinition": {
      "type": "string",
      "minLength": 10,
    }
  }
}
```

```json
// schemas/validation.json
{
  "type": "object",
  "properties": {
    "myProperty": {
      "$ref": "common#/definitions/myDefinition"
    }
  }
}
```

Resolve references:

```javascript
const { RefParser } = require('@microfleet/schema-tools');
const schema = require('schemas/validation.json');

const rp = new RefParser({
  schemaDirs: [ './schemas' ],
})

// Find schemas in provided paths and resolve their local references
await rp.findSchemas()

// Resolve reference and assign `$xRef` property with resolved reference information
const resolved = rp.resolve(schema)
// or
const resolved = rp.resolve(rp.schemas['validation'])
```

Build a Schema tree that will repeat the schema structure but will contain corresponding class instances for each schema type:

```javascript
const { SchemaNode } = require('@microfleet/schema-tools')
const schemaTree = SchemaNode.parse(resolved)
```

For advanced schema tree usage examples, please read project tests or [@microfleet/schema2md](../../schema2md/) sources.

---
_Source: https://npm.io/package/@microfleet/schema-tools · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
