@startupjs/babel-plugin-ts-interface-to-json-schema

0.55.8 • Public • Published

@startupjs/babel-plugin-ts-interface-to-json-schema

Transforms typescript interface to JSON-schema and add schema as static field to ORM model.

TS interface to json-schema

For compilation interface to schema I used typescript-json-schema For add specific things of json-schema you should use API

Example

import { BaseModel } from 'startupjs/orm'

interface IEventModel {
  name: string
  /**
   * @default [1.23, 65.21, -123.40, 0, 1000000.0001]
   */
  amount: number[]
}

export default class EventModel extends BaseModel {
  methodOne() {
    return 1
  }
  methodTwo() {
    return 2
  }
}

↓ ↓ ↓ ↓ ↓ ↓

import { BaseModel } from 'startupjs/orm'

interface IEventModel {
  name: string
  /**
   * @default [1.23, 65.21, -123.40, 0, 1000000.0001]
   */

  amount: number[]
}

export default class EventModel extends BaseModel {
  static schema = {
    type: 'object',
    properties: {
      name: {
        type: 'string'
      },
      amount: {
        default: [1.23, 65.21, -123.4, 0, 1000000.0001],
        type: 'array',
        items: {
          type: 'number'
        }
      }
    },
    $schema: 'http://json-schema.org/draft-07/schema#'
  }

  methodOne() {
    return 1
  }

  methodTwo() {
    return 2
  }
}

License

MIT

Package Sidebar

Install

npm i @startupjs/babel-plugin-ts-interface-to-json-schema

Weekly Downloads

56

Version

0.55.8

License

MIT

Unpacked Size

4.77 kB

Total Files

3

Last publish

Collaborators

  • cray0000
  • yska
  • zag2art
  • fctsvirus
  • maestro.sc
  • byshock