2.1.2 • Published 2 years ago
@hoth/typescript-to-json-schema v2.1.2
typescript-to-json-schema
TypeScript to JsonSchema Transpiler
Usage
Programmatic use
import {resolve} from 'path';
import {generateSchema} from '@hoth/typescript-to-json-schema';
const {schemas} = generateSchema([resolve('demo.ts')]);
Annotations
For example
company.ts
:
import { integer } from "@hoth/typescript-to-json-schema";
type employee = {
/**
* 雇员名字
*
* @maxLength 50
* @minLength 1
*/
name: string;
/**
* 雇员年龄
*
* @minimum 18
*/
age: integer;
};
interface Department {
/**
* 是否开始
*/
open: boolean | null;
/**
* 员工
*
* @maxItems 1000
*/
employee: employee[]
}
export interface Company {
/**
* 部门
*
* @minItems 1
*/
departments: Department[]
}
output
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "http://www.baidu.com/schemas/company.json",
"$ref": "#/definitions/company",
"definitions": {
"department": {
"type": "object",
"properties": {
"open": {
"oneOf": [
{
"type": "boolean"
},
{
"type": "null"
}
],
"description": "是否开始"
},
"employee": {
"type": "array",
"items": {
"$ref": "#/definitions/employee"
},
"maxItems": 1000,
"description": "员工"
}
},
"required": [
"open",
"employee"
]
},
"company": {
"type": "object",
"properties": {
"departments": {
"type": "array",
"items": {
"$ref": "#/definitions/department"
},
"minItems": 1,
"description": "部门"
}
},
"required": [
"departments"
]
},
"employee": {
"type": "object",
"properties": {
"name": {
"type": "string",
"minLength": 1,
"maxLength": 50,
"description": "雇员名字"
},
"age": {
"type": "integer",
"minimum": 18,
"description": "雇员年龄"
}
},
"required": [
"name",
"age"
]
}
}
}
2.1.2
2 years ago
2.1.1
2 years ago
2.1.0
3 years ago
2.1.0-5
3 years ago
2.1.0-4
3 years ago
2.1.0-1
3 years ago
2.1.0-3
3 years ago
2.1.0-2
3 years ago
2.0.1
3 years ago
2.0.1-0
3 years ago
2.0.0
3 years ago
1.1.0-2
3 years ago
1.1.0-1
3 years ago
1.1.0-0
3 years ago
1.0.22
3 years ago
1.0.26
3 years ago
1.0.25
3 years ago
1.0.24
3 years ago
1.0.23
3 years ago
1.0.21
4 years ago
1.0.19
4 years ago
1.0.20
4 years ago
1.0.18
5 years ago
1.0.17
5 years ago
1.0.16
5 years ago
1.0.15
5 years ago
1.0.14
5 years ago
1.0.13
5 years ago
1.0.12
5 years ago
1.0.11
5 years ago
1.0.10
5 years ago
1.0.9
5 years ago
1.0.8
5 years ago
1.0.7
5 years ago
1.0.6
5 years ago
1.0.5
5 years ago
1.0.4
5 years ago
1.0.3
5 years ago
1.0.2
5 years ago
1.0.1
5 years ago
1.0.0
5 years ago