Skip to content

Commit 812128a

Browse files
committed
[Test] Add test case verifying that #228 is fixed (fix #228)
1 parent d3cd7b4 commit 812128a

File tree

3 files changed

+292
-0
lines changed

3 files changed

+292
-0
lines changed

test/__snapshots__/test/test.ts.md

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8874,3 +8874,139 @@ Generated by [AVA](https://avajs.dev).
88748874
"additionalProperties": false,␊
88758875
"required": []␊
88768876
}`
8877+
8878+
## realWorld.jsonschema.js
8879+
8880+
> Expected output to match snapshot for e2e test: realWorld.jsonschema.js
8881+
8882+
`/* tslint:disable */␊
8883+
/**␊
8884+
* This file was automatically generated by json-schema-to-typescript.␊
8885+
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,␊
8886+
* and run json-schema-to-typescript to regenerate this file.␊
8887+
*/␊
8888+
8889+
export type CoreSchemaMetaSchema = CoreSchemaMetaSchema1 & CoreSchemaMetaSchema2;␊
8890+
export type NonNegativeInteger = number;␊
8891+
export type NonNegativeIntegerDefault0 = NonNegativeInteger;␊
8892+
export type CoreSchemaMetaSchema2 =␊
8893+
| {␊
8894+
$id?: string;␊
8895+
$schema?: string;␊
8896+
$ref?: string;␊
8897+
$comment?: string;␊
8898+
title?: string;␊
8899+
description?: string;␊
8900+
default?: true;␊
8901+
readOnly?: boolean;␊
8902+
writeOnly?: boolean;␊
8903+
examples?: true[];␊
8904+
multipleOf?: number;␊
8905+
maximum?: number;␊
8906+
exclusiveMaximum?: number;␊
8907+
minimum?: number;␊
8908+
exclusiveMinimum?: number;␊
8909+
maxLength?: NonNegativeInteger;␊
8910+
minLength?: NonNegativeIntegerDefault0;␊
8911+
pattern?: string;␊
8912+
additionalItems?: CoreSchemaMetaSchema2;␊
8913+
items?: CoreSchemaMetaSchema2 | SchemaArray;␊
8914+
maxItems?: NonNegativeInteger;␊
8915+
minItems?: NonNegativeIntegerDefault0;␊
8916+
uniqueItems?: boolean;␊
8917+
contains?: CoreSchemaMetaSchema2;␊
8918+
maxProperties?: NonNegativeInteger;␊
8919+
minProperties?: NonNegativeIntegerDefault0;␊
8920+
required?: StringArray;␊
8921+
additionalProperties?: CoreSchemaMetaSchema2;␊
8922+
definitions?: {␊
8923+
[k: string]: CoreSchemaMetaSchema2;␊
8924+
};␊
8925+
properties?: {␊
8926+
[k: string]: CoreSchemaMetaSchema2;␊
8927+
};␊
8928+
patternProperties?: {␊
8929+
[k: string]: CoreSchemaMetaSchema2;␊
8930+
};␊
8931+
dependencies?: {␊
8932+
[k: string]: CoreSchemaMetaSchema2 | StringArray;␊
8933+
};␊
8934+
propertyNames?: CoreSchemaMetaSchema2;␊
8935+
const?: true;␊
8936+
enum?: [true, ...unknown[]];␊
8937+
type?: SimpleTypes | [SimpleTypes, ...SimpleTypes[]];␊
8938+
format?: string;␊
8939+
contentMediaType?: string;␊
8940+
contentEncoding?: string;␊
8941+
if?: CoreSchemaMetaSchema2;␊
8942+
then?: CoreSchemaMetaSchema2;␊
8943+
else?: CoreSchemaMetaSchema2;␊
8944+
allOf?: SchemaArray;␊
8945+
anyOf?: SchemaArray;␊
8946+
oneOf?: SchemaArray;␊
8947+
not?: CoreSchemaMetaSchema2;␊
8948+
[k: string]: unknown;␊
8949+
}␊
8950+
| boolean;␊
8951+
export type SchemaArray = [CoreSchemaMetaSchema2, ...CoreSchemaMetaSchema2[]];␊
8952+
export type StringArray = string[];␊
8953+
export type SimpleTypes = "array" | "boolean" | "integer" | "null" | "number" | "object" | "string";␊
8954+
8955+
export interface CoreSchemaMetaSchema1 {␊
8956+
$id?: string;␊
8957+
$schema?: string;␊
8958+
$ref?: string;␊
8959+
$comment?: string;␊
8960+
title?: string;␊
8961+
description?: string;␊
8962+
default?: true;␊
8963+
readOnly?: boolean;␊
8964+
writeOnly?: boolean;␊
8965+
examples?: true[];␊
8966+
multipleOf?: number;␊
8967+
maximum?: number;␊
8968+
exclusiveMaximum?: number;␊
8969+
minimum?: number;␊
8970+
exclusiveMinimum?: number;␊
8971+
maxLength?: NonNegativeInteger;␊
8972+
minLength?: NonNegativeIntegerDefault0;␊
8973+
pattern?: string;␊
8974+
additionalItems?: CoreSchemaMetaSchema2;␊
8975+
items?: CoreSchemaMetaSchema2 | SchemaArray;␊
8976+
maxItems?: NonNegativeInteger;␊
8977+
minItems?: NonNegativeIntegerDefault0;␊
8978+
uniqueItems?: boolean;␊
8979+
contains?: CoreSchemaMetaSchema2;␊
8980+
maxProperties?: NonNegativeInteger;␊
8981+
minProperties?: NonNegativeIntegerDefault0;␊
8982+
required?: StringArray;␊
8983+
additionalProperties?: CoreSchemaMetaSchema2;␊
8984+
definitions?: {␊
8985+
[k: string]: CoreSchemaMetaSchema2;␊
8986+
};␊
8987+
properties?: {␊
8988+
[k: string]: CoreSchemaMetaSchema2;␊
8989+
};␊
8990+
patternProperties?: {␊
8991+
[k: string]: CoreSchemaMetaSchema2;␊
8992+
};␊
8993+
dependencies?: {␊
8994+
[k: string]: CoreSchemaMetaSchema2 | StringArray;␊
8995+
};␊
8996+
propertyNames?: CoreSchemaMetaSchema2;␊
8997+
const?: true;␊
8998+
enum?: [true, ...unknown[]];␊
8999+
type?: SimpleTypes | [SimpleTypes, ...SimpleTypes[]];␊
9000+
format?: string;␊
9001+
contentMediaType?: string;␊
9002+
contentEncoding?: string;␊
9003+
if?: CoreSchemaMetaSchema2;␊
9004+
then?: CoreSchemaMetaSchema2;␊
9005+
else?: CoreSchemaMetaSchema2;␊
9006+
allOf?: SchemaArray;␊
9007+
anyOf?: SchemaArray;␊
9008+
oneOf?: SchemaArray;␊
9009+
not?: CoreSchemaMetaSchema2;␊
9010+
[k: string]: unknown;␊
9011+
}␊
9012+
`

test/__snapshots__/test/test.ts.snap

550 Bytes
Binary file not shown.

test/e2e/realWorld.jsonschema.ts

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
// @see https://github.com/bcherny/json-schema-to-typescript/issues/228
2+
export const input = {
3+
$schema: 'http://json-schema.org/draft-07/schema#',
4+
$id: 'http://json-schema.org/draft-07/schema#',
5+
title: 'Core schema meta-schema',
6+
definitions: {
7+
schemaArray: {
8+
type: 'array',
9+
minItems: 1,
10+
items: {$ref: '#'}
11+
},
12+
nonNegativeInteger: {
13+
type: 'integer',
14+
minimum: 0
15+
},
16+
nonNegativeIntegerDefault0: {
17+
allOf: [{$ref: '#/definitions/nonNegativeInteger'}, {default: 0}]
18+
},
19+
simpleTypes: {
20+
enum: ['array', 'boolean', 'integer', 'null', 'number', 'object', 'string']
21+
},
22+
stringArray: {
23+
type: 'array',
24+
items: {type: 'string'},
25+
uniqueItems: true,
26+
default: []
27+
}
28+
},
29+
type: ['object', 'boolean'],
30+
properties: {
31+
$id: {
32+
type: 'string',
33+
format: 'uri-reference'
34+
},
35+
$schema: {
36+
type: 'string',
37+
format: 'uri'
38+
},
39+
$ref: {
40+
type: 'string',
41+
format: 'uri-reference'
42+
},
43+
$comment: {
44+
type: 'string'
45+
},
46+
title: {
47+
type: 'string'
48+
},
49+
description: {
50+
type: 'string'
51+
},
52+
default: true,
53+
readOnly: {
54+
type: 'boolean',
55+
default: false
56+
},
57+
writeOnly: {
58+
type: 'boolean',
59+
default: false
60+
},
61+
examples: {
62+
type: 'array',
63+
items: true
64+
},
65+
multipleOf: {
66+
type: 'number',
67+
exclusiveMinimum: 0
68+
},
69+
maximum: {
70+
type: 'number'
71+
},
72+
exclusiveMaximum: {
73+
type: 'number'
74+
},
75+
minimum: {
76+
type: 'number'
77+
},
78+
exclusiveMinimum: {
79+
type: 'number'
80+
},
81+
maxLength: {$ref: '#/definitions/nonNegativeInteger'},
82+
minLength: {$ref: '#/definitions/nonNegativeIntegerDefault0'},
83+
pattern: {
84+
type: 'string',
85+
format: 'regex'
86+
},
87+
additionalItems: {$ref: '#'},
88+
items: {
89+
anyOf: [{$ref: '#'}, {$ref: '#/definitions/schemaArray'}],
90+
default: true
91+
},
92+
maxItems: {$ref: '#/definitions/nonNegativeInteger'},
93+
minItems: {$ref: '#/definitions/nonNegativeIntegerDefault0'},
94+
uniqueItems: {
95+
type: 'boolean',
96+
default: false
97+
},
98+
contains: {$ref: '#'},
99+
maxProperties: {$ref: '#/definitions/nonNegativeInteger'},
100+
minProperties: {$ref: '#/definitions/nonNegativeIntegerDefault0'},
101+
required: {$ref: '#/definitions/stringArray'},
102+
additionalProperties: {$ref: '#'},
103+
definitions: {
104+
type: 'object',
105+
additionalProperties: {$ref: '#'},
106+
default: {}
107+
},
108+
properties: {
109+
type: 'object',
110+
additionalProperties: {$ref: '#'},
111+
default: {}
112+
},
113+
patternProperties: {
114+
type: 'object',
115+
additionalProperties: {$ref: '#'},
116+
propertyNames: {format: 'regex'},
117+
default: {}
118+
},
119+
dependencies: {
120+
type: 'object',
121+
additionalProperties: {
122+
anyOf: [{$ref: '#'}, {$ref: '#/definitions/stringArray'}]
123+
}
124+
},
125+
propertyNames: {$ref: '#'},
126+
const: true,
127+
enum: {
128+
type: 'array',
129+
items: true,
130+
minItems: 1,
131+
uniqueItems: true
132+
},
133+
type: {
134+
anyOf: [
135+
{$ref: '#/definitions/simpleTypes'},
136+
{
137+
type: 'array',
138+
items: {$ref: '#/definitions/simpleTypes'},
139+
minItems: 1,
140+
uniqueItems: true
141+
}
142+
]
143+
},
144+
format: {type: 'string'},
145+
contentMediaType: {type: 'string'},
146+
contentEncoding: {type: 'string'},
147+
if: {$ref: '#'},
148+
then: {$ref: '#'},
149+
else: {$ref: '#'},
150+
allOf: {$ref: '#/definitions/schemaArray'},
151+
anyOf: {$ref: '#/definitions/schemaArray'},
152+
oneOf: {$ref: '#/definitions/schemaArray'},
153+
not: {$ref: '#'}
154+
},
155+
default: true
156+
}

0 commit comments

Comments
 (0)