Socket
Book a DemoInstallSign in
Socket

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

Package Overview
Dependencies
Maintainers
6
Versions
61
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

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

It is convert typescript interface to JSON-Schema and add that JSON to ORM model as static field.

latest
Source
npmnpm
Version
0.55.8
Version published
Maintainers
6
Created
Source

@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

Keywords

babel

FAQs

Package last updated on 16 Dec 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts