Skip to content

Commit 82ca0d2

Browse files
authored
Merge pull request #13 from lexmin0412/master
Add English docs
2 parents 0e0774a + b8337ff commit 82ca0d2

14 files changed

+2245
-5
lines changed

CONTRIBUTING.en-US.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Contribution Guide
2+
3+
## Feature
4+
5+
- Describe what kind of feature it is
6+
- Check if your feature is included in the previous issues
7+
8+
## Documentation
9+
10+
- All new features need to have a documentation
11+
- Documentation needs to describe the use case from different perspective
12+
- Documentation needs to describe how to use it
13+
14+
## Unit Test
15+
16+
- All new features need to have a test case
17+
- Test cases should be passed if you modified the old code
18+
19+
## Commit
20+
21+
- All commits need to follow the [angular commit-message-format](https://github.com/angular/angular.js/blob/master/DEVELOPERS.md#-git-commit-guidelines)
22+
- Linting before committing
23+
24+
## Release
25+
26+
- Release schedule are decided by the project owner on need

README.en-US.md

Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
1+
# fast-typescript-to-jsonschema
2+
3+
[![npm version](https://img.shields.io/npm/v/fast-typescript-to-jsonschema.svg)](https://www.npmjs.com/package/fast-typescript-to-jsonschema)
4+
![Test](https://github.com/yunke-yunfly/fast-typescript-to-jsonschema/workflows/Test/badge.svg)
5+
6+
English | [简体中文](./README.md)
7+
8+
a tool generate json schema from typescript.
9+
10+
## Feature
11+
12+
- compile Typescript to get all type information
13+
- convert properties, extends, annotations, and initial values to jsonschema
14+
15+
## Usage
16+
17+
1. install
18+
19+
```bash
20+
yarn add fast-typescript-to-jsonschema -D
21+
```
22+
23+
2. create `type.ts`
24+
25+
```ts
26+
interface ITest {
27+
attr1: string;
28+
attr2: number;
29+
attr3?: boolean;
30+
}
31+
```
32+
33+
3. create `test.js`
34+
35+
```js
36+
const { default: genTypeSchema } = require('fast-typescript-to-jsonschema');
37+
const path = require('path');
38+
39+
// target file
40+
const file = path.resolve(__dirname, './type.ts');
41+
42+
// generate data
43+
genTypeSchema.genJsonDataFormFile(file);
44+
45+
// get all jsonschema data of current file
46+
const json = genTypeSchema.genJsonData();
47+
48+
// get jsonschema of specific type
49+
const jsonSchema = genTypeSchema.getJsonSchema(file, 'ITest');
50+
51+
// result
52+
console.log(jsonSchema);
53+
```
54+
55+
4. execute script
56+
57+
```js
58+
node ./test.js
59+
```
60+
61+
`jsonSchema` result:
62+
63+
```json
64+
{
65+
"additionalProperties": false,
66+
"properties": {
67+
"attr1": {
68+
"type": "string",
69+
},
70+
"attr2": {
71+
"type": "number",
72+
},
73+
"attr3": {
74+
"type": "boolean",
75+
},
76+
},
77+
"required": [
78+
"attr1",
79+
"attr2",
80+
],
81+
"type": "object",
82+
}
83+
```
84+
85+
see more examples at [example](https://github.com/yunke-yunfly/fast-typescript-to-jsonschema/tree/master/example).
86+
87+
## Comments
88+
89+
Example1
90+
91+
```ts
92+
interface Interface_1 {
93+
attr: string;
94+
}
95+
```
96+
97+
result:
98+
99+
```json
100+
{
101+
"additionalProperties": false,
102+
"properties": {
103+
"attr": {
104+
"type": "string",
105+
},
106+
},
107+
"required": [
108+
"attr",
109+
],
110+
"type": "object",
111+
}
112+
```
113+
114+
Example2
115+
116+
```ts
117+
interface Interface_4 {
118+
attr: string[];
119+
}
120+
```
121+
122+
result:
123+
124+
```json
125+
{
126+
"additionalProperties": false,
127+
"properties": {
128+
"attr": {
129+
"items": {
130+
"type": "string",
131+
},
132+
"type": "array",
133+
},
134+
},
135+
"required": [
136+
"attr",
137+
],
138+
"type": "object",
139+
}
140+
```
141+
142+
> Read more supported types [here](docs/index.en-US.md)
143+
144+
- [Interface](docs/interface.en-US.md)
145+
- [1.1 Basic Types](docs/interface.en-US.md#11-basic-types)
146+
- [1.2 Union Types](docs/interface.en-US.md#12-union-types)
147+
- [1.3 Intersection Types](docs/interface.en-US.md#13-intersection-types)
148+
- [1.4 Array Types](docs/interface.en-US.md#14-array-types)
149+
- [1.4.1 Basic Array Types](docs/interface.en-US.md#141-basic-array-types)
150+
- [1.4.2 Complex Array Types](docs/interface.en-US.md#142-complex-array-types)
151+
- [1.5 Nesting](docs/interface.en-US.md#15-nesting)
152+
- [1.5.1 Nested Basic Types](docs/interface.en-US.md#151-nested-basic-types)
153+
- [1.5.2 Nested Union Types](docs/interface.en-US.md#152-nested-union-types)
154+
- [1.5.3 Nested Intersection Types](docs/interface.en-US.md#153-nested-intersection-types)
155+
- [1.5.4 Nested Intersection Array Types](docs/interface.en-US.md#154-nested-intersection-array-types)
156+
- [1.5.5 Nested loop](docs/interface.en-US.md#155-nested-loop)
157+
- [1.6 Index Types](docs/interface.en-US.md#16-index-types)
158+
- [Modules](docs/module.en-US.md#modules)
159+
- [1.1 Basic Modules](docs/module.en-US.md#11-basic-modules)
160+
- [1.2 Named Export Modules](docs/module.en-US.md#12-named-export-modules)
161+
- [Extending Types](docs/extends.en-US.md#extending-types)
162+
- [1.1 Basic Extending Types](docs/extends.en-US.md#11-basic-extending-types)
163+
- [1.2 Multiple Extending Types ](docs/extends.en-US.md#12-multiple-extending-types)
164+
- [Enums](docs/enum.en-US.md#enums)
165+
- [1.1 Numeric Enums](docs/enum.en-US.md#11-numeric-enums)
166+
- [1.2 String Enums](docs/enum.en-US.md#12-string-enums)
167+
- [1.3 Computed Enums](docs/enum.en-US.md#13-computed-enums)
168+
- [1.4 Complex Enums](docs/enum.en-US.md#14-complex-enums)
169+
- [1.4.1 Basic Interface to Enums](docs/enum.en-US.md#141-basic-interface-to-enums)
170+
- [1.4.2 Complex Interface to Enums](docs/enum.en-US.md#142-complex-interface-to-enums)
171+
- [Generics](docs/generic.en-US.md#generics)
172+
- [1.1 Basic Generics](docs/generic.en-US.md#11-basic-generics)
173+
- [1.2 Complex Generics](docs/generic.en-US.md#12-complex-generics)
174+
- [Namespaces](docs/namespace.en-US.md#namespaces)
175+
- [1.1 Basic Namespaces](docs/namespace.en-US.md#11-basic-namespaces)
176+
- [1.2 Complex Namespaces](docs/namespace.en-US.md#12-complex-namespaces)
177+
- [Type](docs/type.en-US.md#type)
178+
- [1.1 Basic Types](docs/type.en-US.md#11-basic-types)
179+
- [1.2 Complex Types](docs/type.en-US.md#12-complex-types)
180+
- [1.2.1 Union Types](docs/type.en-US.md#121-union-types)
181+
- [1.2.2 Union Array Types](docs/type.en-US.md#122-union-array-types)
182+
- [1.2.2 Import Enums](docs/type.en-US.md#122-import-enums)
183+
- [Utility Types](docs/toolFn.en-US.md#utility-types)
184+
- [1.1 Utility for Objects](docs/toolFn.en-US.md#11-utility-for-objects)
185+
- [1.1.1 Omit](docs/toolFn.en-US.md#111-omit)
186+
- [1.1.1.1 Basic Omit](docs/toolFn.en-US.md#1111-basic-omit)
187+
- [1.1.1.2 Union Omit](docs/toolFn.en-US.md#1112-union-omit)
188+
- [1.1.1.3 Import Omit](docs/toolFn.en-US.md#1113-import-omit)
189+
- [1.1.2 Pick](docs/toolFn.en-US.md#112-pick)
190+
- [1.1.2.1 Basic Pick](docs/toolFn.en-US.md#1121-basic-pick)
191+
- [1.1.2.2 Import Pick](docs/toolFn.en-US.md#1122-import-pick)
192+
- [1.1.3 Record](docs/toolFn.en-US.md#112-record)
193+
- [1.1.2.1 Basic Record](docs/toolFn.en-US.md#1121-basic-record)
194+
- [1.1.2.2 Import Record](docs/toolFn.en-US.md#1122-import-record)
195+
- [Type Annotations](docs/note.en-US.md#type-annotations)
196+
- [1.1 Single-line annotations](docs/note.en-US.md#11-single-line-annotations)
197+
- [1.2 Single-line annotations with default value](docs/note.en-US.md#12-single-line-annotations-with-default-value)
198+
- [1.3 Multi-line annotations](docs/note.en-US.md#13-multi-line-annotations)
199+
- [1.4 Multi-line annotations with default value](docs/note.en-US.md#14-multi-line-annotations-with-default-value)
200+
- [1.5 Mixed annotations with default value](docs/note.en-US.md#15-mixed-annotations-with-default-value)
201+
202+
## Contribution
203+
204+
Contributions are extremely welcomed by our team, you can contribute to this repository by several ways below.
205+
206+
- Submit [GitHub Issue](https://github.com/yunke-yunfly/fast-typescript-to-jsonschema/issues) to report errors or ask questions
207+
- Create [Pull Request](https://github.com/yunke-yunfly/fast-typescript-to-jsonschema/pulls) to improve our code
208+
- [Contribution guide](./CONTRIBUTING.en-US.md)

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
![Test](https://github.com/yunke-yunfly/fast-typescript-to-jsonschema/workflows/Test/badge.svg)
55
[![codecov](https://codecov.io/gh/yunke-yunfly/fast-typescript-to-jsonschema/branch/master/graph/badge.svg)](https://app.codecov.io/gh/yunke-yunfly/fast-typescript-to-jsonschema)
66

7+
中文 | [English](./README.en-US.md)
8+
79
生成typescript类型的jsonschema数据
810

911
## 特性
@@ -13,13 +15,13 @@
1315

1416
## 使用
1517

16-
- 1.安装依赖
18+
1.安装依赖
1719

1820
```js
1921
yarn add fast-typescript-to-jsonschema -D
2022
```
2123

22-
- 2.创建`type.ts`文件,内容如下:
24+
2.创建`type.ts`文件,内容如下:
2325

2426
```ts
2527
interface ITest {
@@ -29,7 +31,7 @@ interface ITest {
2931
}
3032
```
3133

32-
- 3.创建`test.js`文件,内容如下:
34+
3.创建`test.js`文件,内容如下:
3335

3436
```js
3537
const { default: genTypeSchema } = require('fast-typescript-to-jsonschema');
@@ -51,7 +53,7 @@ const jsonSchema = genTypeSchema.getJsonSchema(file, 'ITest');
5153
console.log(jsonSchema);
5254
```
5355

54-
- 4.执行脚本
56+
4.执行脚本
5557

5658
```js
5759
node ./test.js

0 commit comments

Comments
 (0)