# @wssz/modeler-jsonschema

> Plugin for [@wssz/modeler](https://github.com/wszerad/wssz-modeler), create JSONSchema from decorated object.

Latest version **0.5.7** (published 2020-10-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install @wssz/modeler-jsonschema
pnpm add @wssz/modeler-jsonschema
yarn add @wssz/modeler-jsonschema
bun add @wssz/modeler-jsonschema
```

## Health

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

Positive: has types; no vulnerabilities; high quality score.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.5.7 |
| Published | 2020-10-10 |
| First published | 2019-08-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 30 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | wszerad91@gmail.com |
| Maintainers | wszerad |

## Links

- npm: https://www.npmjs.com/package/@wssz/modeler-jsonschema
- Repository: https://github.com/wszerad/wssz-modeler-jsonschema
- Homepage: https://github.com/wszerad/wssz-modeler-jsonschema#readme
- Issues: https://github.com/wszerad/wssz-modeler-jsonschema/issues
- npm.io page: https://npm.io/package/@wssz/modeler-jsonschema

## Dependencies (4)

- [typescript](https://npm.io/package/typescript.md) ^4.0.3
- [@wssz/modeler](https://npm.io/package/@wssz/modeler.md) ^0.5.4
- [babel-polyfill](https://npm.io/package/babel-polyfill.md) ^6.26.0
- [reflect-metadata](https://npm.io/package/reflect-metadata.md) ^0.1.13

## Recent versions

- 0.5.7 (latest) — 2020-10-10
- 0.5.6 — 2020-05-31
- 0.5.5 — 2020-04-27
- 0.5.4 — 2020-03-31
- 0.5.3 — 2020-03-08
- 0.5.2 — 2020-03-07
- 0.5.1 — 2020-03-06
- 0.5.0 — 2020-03-06
- 0.3.5 — 2020-02-02
- 0.3.4 — 2019-11-27
- 0.3.3 — 2019-11-27
- 0.3.2 — 2019-11-27
- 0.3.1 — 2019-11-15
- 0.2.6 — 2019-10-06
- 0.2.5 — 2019-09-21
- … 5 more at https://npm.io/package/@wssz/modeler-jsonschema/versions

## README

# @wssz/modeler-jsonschema
Plugin for [@wssz/modeler](https://github.com/wszerad/wssz-modeler), create JSONSchema from decorated object.

## ModelerJsonSchema

* ModelerJsonSchema.create(model, options)
    * model decorated class
    * options
    ``
     {
        useNullable: boolean
        // use nullable instead of oneOf: [{type: 'null'}, ...]
        // for OpenAPI < 3 compatibility
     }
    ``

## Usage

```ts
import { Description, Enum, Required, Type, Items } from '@wssz/modeler';
import { ModelerJsonSchema } from '@wssz/modeler-jsonschema';

enum Enums {
	A = 'test',
	B = 'test2'
}

class NestedArray extend ArrayItems {
    @Items()
    items: string[];
}

class TestClass {
	@Description('description')
	@Required()
	@Prop()
	ref: OtherClass;

	@Enum(Enums)
	@Prop()
	str: string;

    @Items(OtherClass)
	@Prop()
	arr: OtherClass[];
	
    @Items(NestedArray)
	arr2D: string[][];
}

const schema = ModelerJsonSchema.create(TestClass);
results.dependencies => 
    [OtherClass]
    
results.schema => 
    {
        type: 'object',
        properties: {
            arr2D: {
                type: 'array',
                items: {
                    type: 'array',
                    items: {
                        type: 'string'
                    }
                }
            },
            arr: {
                type: 'array',
                items: {
                    $ref: '#/definitions/OtherClass'
                }
            },
            ref: {
                description: 'description',
                $ref: '#/definitions/OtherClass',
                required: true
            },
            str: {
                type: 'string',
                enum: ['test', 'test2'],
            }
        }
    }
```
### Supported decorators
* see more at [build-in decorators](https://github.com/wszerad/wssz-modeler#Decorators)
```ts
@Prop
@Items
@Required
@Minimum
@Maximum
@ExclusiveMinimum
@ExclusiveMaximum
@MultipleOf
@MaxLength
@MinLength
@Format
@Pattern
@Enum
@MaxItems
@MinItems
@Default
@Example
@Examples
@UniqueItems
@Description
```

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