Skip to content

Commit ab6eafb

Browse files
committed
Merge remote-tracking branch 'upstream/master' into multi-defs
2 parents baaa7f4 + 1a077fd commit ab6eafb

File tree

139 files changed

+3456
-3437
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

139 files changed

+3456
-3437
lines changed

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
azure-pipelines.yml
22
package.json
3+
test/valid-data/**/*.json

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ts-json-schema-generator",
3-
"version": "0.85.0",
3+
"version": "0.86.1",
44
"description": "Generate JSON schema from your Typescript sources",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",
@@ -83,6 +83,8 @@
8383
"format": "yarn lint --fix",
8484
"test": "jest test/ --verbose",
8585
"test:fast": "FAST_TEST=1 jest test/ --verbose",
86+
"test:coverage": "yarn jest test/ --collectCoverage=true",
87+
"test:update": "UPDATE_SCHEMA=true yarn test:fast",
8688
"debug": "node -r ts-node/register --inspect-brk ts-json-schema-generator.ts",
8789
"dbg": "node -r ts-node/register --inspect-brk ts-json-schema-generator.ts -p test/valid-data/duplicates-composition/main.ts -t MyObject",
8890
"run": "ts-node ts-json-schema-generator.ts"

src/TypeFormatter/UnionTypeFormatter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export class UnionTypeFormatter implements SubTypeFormatter {
3636

3737
const flattenedDefinitions: JSONSchema7[] = [];
3838

39-
// Flatten anOf inside anyOf unless the anyOf has an annotation
39+
// Flatten anyOf inside anyOf unless the anyOf has an annotation
4040
for (const def of definitions) {
4141
if (Object.keys(def) === ["anyOf"]) {
4242
flattenedDefinitions.push(...(def.anyOf as any));

test/utils.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import Ajv from "ajv";
22
import addFormats from "ajv-formats";
33
import { readFileSync, writeFileSync } from "fs";
4+
import stringify from "json-stable-stringify";
45
import { resolve } from "path";
56
import ts from "typescript";
67
import { createFormatter } from "../factory/formatter";
@@ -46,12 +47,13 @@ export function assertValidSchema(
4647
const expected: any = JSON.parse(readFileSync(resolve(`${basePath}/${relativePath}/schema.json`), "utf8"));
4748
const actual: any = JSON.parse(JSON.stringify(schema));
4849

49-
// uncomment to write test files
50-
writeFileSync(
51-
resolve(`${basePath}/${relativePath}/schema.json`),
52-
JSON.stringify(schema, null, 4) + "\n",
53-
"utf8"
54-
);
50+
if (process.env.UPDATE_SCHEMA) {
51+
writeFileSync(
52+
resolve(`${basePath}/${relativePath}/schema.json`),
53+
stringify(schema, { space: 2 }) + "\n",
54+
"utf8"
55+
);
56+
}
5557

5658
expect(typeof actual).toBe("object");
5759
expect(actual).toEqual(expected);
Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
{
2-
"$schema": "http://json-schema.org/draft-07/schema#",
3-
"$ref": "#/definitions/MyObject",
4-
"definitions": {
5-
"MyObject": {
6-
"type": "object",
7-
"customNumberProperty": 14,
8-
"customStringProperty": "string-value",
9-
"customComplexProperty": {
10-
"a": 1,
11-
"b": 2
12-
},
13-
"customMultilineProperty": [
14-
"value1",
15-
"value2",
16-
"value3"
17-
],
18-
"customUnquotedProperty": "not-a-valid-json",
19-
"additionalProperties": false
20-
}
2+
"$ref": "#/definitions/MyObject",
3+
"$schema": "http://json-schema.org/draft-07/schema#",
4+
"definitions": {
5+
"MyObject": {
6+
"additionalProperties": false,
7+
"customComplexProperty": {
8+
"a": 1,
9+
"b": 2
10+
},
11+
"customMultilineProperty": [
12+
"value1",
13+
"value2",
14+
"value3"
15+
],
16+
"customNumberProperty": 14,
17+
"customStringProperty": "string-value",
18+
"customUnquotedProperty": "not-a-valid-json",
19+
"type": "object"
2120
}
2221
}
Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
{
2-
"$schema": "http://json-schema.org/draft-07/schema#",
3-
"$ref": "#/definitions/MyObject",
4-
"definitions": {
5-
"MyObject": {
6-
"type": "object",
7-
"required": [
8-
"value1",
9-
"value2"
10-
],
11-
"properties": {
12-
"value1": {},
13-
"value2": {}
14-
},
15-
"additionalProperties": false
2+
"$ref": "#/definitions/MyObject",
3+
"$schema": "http://json-schema.org/draft-07/schema#",
4+
"definitions": {
5+
"MyObject": {
6+
"additionalProperties": false,
7+
"properties": {
8+
"value1": {
9+
},
10+
"value2": {
1611
}
12+
},
13+
"required": [
14+
"value1",
15+
"value2"
16+
],
17+
"type": "object"
1718
}
19+
}
1820
}
Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
{
2-
"$schema": "http://json-schema.org/draft-07/schema#",
3-
"$ref": "#/definitions/MyType",
4-
"definitions": {
5-
"MyType": {
6-
"type": "array",
7-
"minItems": 0,
8-
"maxItems": 2,
9-
"items": {
10-
"type": "string"
11-
}
12-
}
2+
"$ref": "#/definitions/MyType",
3+
"$schema": "http://json-schema.org/draft-07/schema#",
4+
"definitions": {
5+
"MyType": {
6+
"items": {
7+
"type": "string"
8+
},
9+
"maxItems": 2,
10+
"minItems": 0,
11+
"type": "array"
1312
}
13+
}
1414
}
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
2-
"$schema": "http://json-schema.org/draft-07/schema#",
3-
"$ref": "#/definitions/MyType",
4-
"definitions": {
5-
"MyType": {
6-
"type": "array",
7-
"minItems": 1,
8-
"items": {
9-
"type": "string"
10-
}
11-
}
2+
"$ref": "#/definitions/MyType",
3+
"$schema": "http://json-schema.org/draft-07/schema#",
4+
"definitions": {
5+
"MyType": {
6+
"items": {
7+
"type": "string"
8+
},
9+
"minItems": 1,
10+
"type": "array"
1211
}
12+
}
1313
}
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
2-
"$schema": "http://json-schema.org/draft-07/schema#",
3-
"$ref": "#/definitions/MyType",
4-
"definitions": {
5-
"MyType": {
6-
"type": "array",
7-
"minItems": 2,
8-
"items": {
9-
"type": "string"
10-
}
11-
}
2+
"$ref": "#/definitions/MyType",
3+
"$schema": "http://json-schema.org/draft-07/schema#",
4+
"definitions": {
5+
"MyType": {
6+
"items": {
7+
"type": "string"
8+
},
9+
"minItems": 2,
10+
"type": "array"
1211
}
12+
}
1313
}
Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
{
2-
"$schema": "http://json-schema.org/draft-07/schema#",
3-
"$ref": "#/definitions/MyType",
4-
"definitions": {
5-
"MyType": {
6-
"type": "array",
7-
"minItems": 2,
8-
"maxItems": 3,
9-
"items": {
10-
"type": "string"
11-
}
12-
}
2+
"$ref": "#/definitions/MyType",
3+
"$schema": "http://json-schema.org/draft-07/schema#",
4+
"definitions": {
5+
"MyType": {
6+
"items": {
7+
"type": "string"
8+
},
9+
"maxItems": 3,
10+
"minItems": 2,
11+
"type": "array"
1312
}
13+
}
1414
}
Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
{
2-
"$schema": "http://json-schema.org/draft-07/schema#",
3-
"$ref": "#/definitions/MyType",
4-
"definitions": {
5-
"MyType": {
6-
"type": "array",
7-
"minItems": 3,
8-
"maxItems": 3,
9-
"items": {
10-
"type": "string"
11-
}
12-
}
2+
"$ref": "#/definitions/MyType",
3+
"$schema": "http://json-schema.org/draft-07/schema#",
4+
"definitions": {
5+
"MyType": {
6+
"items": {
7+
"type": "string"
8+
},
9+
"maxItems": 3,
10+
"minItems": 3,
11+
"type": "array"
1312
}
13+
}
1414
}
Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
{
2-
"$schema": "http://json-schema.org/draft-07/schema#",
3-
"$ref": "#/definitions/MyObject",
4-
"definitions": {
5-
"MyObject": {
6-
"type": "object",
7-
"required": [
8-
"required"
9-
],
10-
"properties": {
11-
"required": {
12-
"type": "string"
13-
},
14-
"optional": {
15-
"type": "number"
16-
}
17-
},
18-
"additionalProperties": {
19-
"type": [
20-
"string",
21-
"number"
22-
]
23-
}
2+
"$ref": "#/definitions/MyObject",
3+
"$schema": "http://json-schema.org/draft-07/schema#",
4+
"definitions": {
5+
"MyObject": {
6+
"additionalProperties": {
7+
"type": [
8+
"string",
9+
"number"
10+
]
11+
},
12+
"properties": {
13+
"optional": {
14+
"type": "number"
15+
},
16+
"required": {
17+
"type": "string"
2418
}
19+
},
20+
"required": [
21+
"required"
22+
],
23+
"type": "object"
2524
}
25+
}
2626
}
Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
{
2-
"$schema": "http://json-schema.org/draft-07/schema#",
3-
"$ref": "#/definitions/MyObject",
4-
"definitions": {
5-
"MyObject": {
6-
"type": "object",
7-
"required": [
8-
"a",
9-
"b",
10-
"c"
11-
],
12-
"properties": {
13-
"a": {
14-
"type": "number"
15-
},
16-
"b": {
17-
"type": "string"
18-
},
19-
"c": {
20-
"type": "boolean"
21-
}
22-
},
23-
"additionalProperties": false
2+
"$ref": "#/definitions/MyObject",
3+
"$schema": "http://json-schema.org/draft-07/schema#",
4+
"definitions": {
5+
"MyObject": {
6+
"additionalProperties": false,
7+
"properties": {
8+
"a": {
9+
"type": "number"
10+
},
11+
"b": {
12+
"type": "string"
13+
},
14+
"c": {
15+
"type": "boolean"
2416
}
17+
},
18+
"required": [
19+
"a",
20+
"b",
21+
"c"
22+
],
23+
"type": "object"
2524
}
25+
}
2626
}

0 commit comments

Comments
 (0)