File tree Expand file tree Collapse file tree 7 files changed +95
-50
lines changed Expand file tree Collapse file tree 7 files changed +95
-50
lines changed Original file line number Diff line number Diff line change 1
1
{
2
2
"$schema" : " http://json-schema.org/draft-07/schema#" ,
3
- "properties " : {
4
- "varBoolean " : {
3
+ "definitions " : {
4
+ "Foo " : {
5
5
"anyOf" : [
6
6
{
7
7
"enum" : [
15
15
{
16
16
"type" : " number"
17
17
}
18
- ],
18
+ ]
19
+ }
20
+ },
21
+ "properties" : {
22
+ "varBoolean" : {
23
+ "$ref" : " #/definitions/Foo" ,
19
24
"default" : false
20
25
},
21
26
"varInteger" : {
22
- "anyOf" : [
23
- {
24
- "enum" : [
25
- " a" ,
26
- " b" ,
27
- " c" ,
28
- false ,
29
- true
30
- ]
31
- },
32
- {
33
- "type" : " number"
34
- }
35
- ],
27
+ "$ref" : " #/definitions/Foo" ,
36
28
"default" : 123
37
29
},
38
30
"varString" : {
39
- "anyOf" : [
40
- {
41
- "enum" : [
42
- " a" ,
43
- " b" ,
44
- " c" ,
45
- false ,
46
- true
47
- ]
48
- },
49
- {
50
- "type" : " number"
51
- }
52
- ],
31
+ "$ref" : " #/definitions/Foo" ,
53
32
"default" : " 123"
54
33
}
55
34
},
Original file line number Diff line number Diff line change
1
+ interface A { }
2
+ interface B { }
3
+
4
+ type C = A | B ;
5
+
6
+ interface MyObject {
7
+ c : C ;
8
+ }
Original file line number Diff line number Diff line change
1
+ {
2
+ "$schema" : " http://json-schema.org/draft-07/schema#" ,
3
+ "definitions" : {
4
+ "A" : {
5
+ "type" : " object"
6
+ },
7
+ "B" : {
8
+ "type" : " object"
9
+ },
10
+ "C" : {
11
+ "anyOf" : [
12
+ {
13
+ "$ref" : " #/definitions/A"
14
+ },
15
+ {
16
+ "$ref" : " #/definitions/B"
17
+ }
18
+ ]
19
+ }
20
+ },
21
+ "properties" : {
22
+ "c" : {
23
+ "$ref" : " #/definitions/C"
24
+ }
25
+ },
26
+ "required" : [
27
+ " c"
28
+ ],
29
+ "type" : " object"
30
+ }
Original file line number Diff line number Diff line change 1
1
{
2
2
"$schema" : " http://json-schema.org/draft-07/schema#" ,
3
3
"definitions" : {
4
+ "MyType2" : {
5
+ "type" : [
6
+ " string" ,
7
+ " number"
8
+ ]
9
+ },
10
+ "MyType3" : {
11
+ "anyOf" : [
12
+ {
13
+ "items" : {
14
+ "type" : " number"
15
+ },
16
+ "type" : " array"
17
+ },
18
+ {
19
+ "type" : " string"
20
+ }
21
+ ]
22
+ },
4
23
"MyType6" : {
5
24
"type" : " object"
6
25
}
13
32
]
14
33
},
15
34
"var2" : {
16
- "type" : [
17
- " string" ,
18
- " number" ,
19
- " null"
35
+ "anyOf" : [
36
+ {
37
+ "$ref" : " #/definitions/MyType2"
38
+ },
39
+ {
40
+ "type" : " null"
41
+ }
20
42
]
21
43
},
22
44
"var3" : {
23
45
"anyOf" : [
24
46
{
25
- "items" : {
26
- "type" : " number"
27
- },
28
- "type" : " array"
29
- },
30
- {
31
- "type" : " string"
47
+ "$ref" : " #/definitions/MyType3"
32
48
},
33
49
{
34
50
"type" : " null"
91
107
],
92
108
"type" : " object"
93
109
}
94
-
Original file line number Diff line number Diff line change 1
1
{
2
2
"$schema" : " http://json-schema.org/draft-07/schema#" ,
3
- "properties " : {
4
- "var1 " : {
3
+ "definitions " : {
4
+ "MyType1 " : {
5
5
"type" : [
6
6
" string" ,
7
7
" number"
8
8
]
9
9
},
10
- "var2 " : {
10
+ "MyType2 " : {
11
11
"anyOf" : [
12
12
{
13
+ "type" : " array" ,
13
14
"items" : {
14
15
"type" : " number"
15
- },
16
- "type" : " array"
16
+ }
17
17
},
18
18
{
19
19
"type" : " string"
20
20
}
21
21
]
22
22
}
23
23
},
24
+ "properties" : {
25
+ "var1" : {
26
+ "$ref" : " #/definitions/MyType1"
27
+ },
28
+ "var2" : {
29
+ "$ref" : " #/definitions/MyType2"
30
+ }
31
+ },
24
32
"required" : [
25
33
" var1" ,
26
34
" var2"
Original file line number Diff line number Diff line change @@ -215,6 +215,7 @@ describe("schema", () => {
215
215
aliasRef : true ,
216
216
topRef : true ,
217
217
} ) ;
218
+ assertSchema ( "type-alias-or" , "MyObject" ) ;
218
219
// disabled because of #80
219
220
// assertSchema("type-aliases-recursive-alias-topref", "MyAlias", {
220
221
// useTypeAliasRef: true,
Original file line number Diff line number Diff line change @@ -1220,14 +1220,18 @@ export class JsonSchemaGenerator {
1220
1220
1221
1221
const symbol = typ . getSymbol ( ) ;
1222
1222
// FIXME: We can't just compare the name of the symbol - it ignores the namespace
1223
- const isRawType =
1224
- ! symbol ||
1223
+ let isRawType =
1224
+ ! symbol ||
1225
1225
// Window is incorrectly marked as rawType here for some reason
1226
1226
( this . tc . getFullyQualifiedName ( symbol ) !== "Window" &&
1227
1227
( this . tc . getFullyQualifiedName ( symbol ) === "Date" ||
1228
1228
symbol . name === "integer" ||
1229
1229
this . tc . getIndexInfoOfType ( typ , ts . IndexKind . Number ) !== undefined ) ) ;
1230
1230
1231
+ if ( isRawType && reffedType ?. escapedName && ( typ as any ) . types ) {
1232
+ isRawType = false ;
1233
+ }
1234
+
1231
1235
// special case: an union where all child are string literals -> make an enum instead
1232
1236
let isStringEnum = false ;
1233
1237
if ( typ . flags & ts . TypeFlags . Union ) {
You can’t perform that action at this time.
0 commit comments