Skip to content

cjinhuo/thrift-to-json-schema

Repository files navigation

overview

parse Thrift to JSON schema with typescript

demo

demo Online Demo

install

pnpm add @trasm/thrift-jsma

usage

import { parseThriftToJsonSchema,parseThriftToTypeBox } from '@trasm/thrift-jsma'
  const structString = `
    # @flag header
    struct EmptyStruct {
    string field_string
    # @schema maxLength:66
    double field_double
    i32 field_i32
    i64 field_i64
    bool field_bool
    optional string field_optional_string
    }
  `
  const jsonSchema = parseThriftToJsonSchema(structString)
  const jsonTypeBox = parseThriftToTypeBox(structString)

syntax

flag

@flag header: means current struct is root node.

scheme

@schema xxx: means add additional constraint for field, such as add '@schema maxLength:66' for string type

references