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 11{
22 "$schema" : " http://json-schema.org/draft-07/schema#" ,
3- "properties " : {
4- "varBoolean " : {
3+ "definitions " : {
4+ "Foo " : {
55 "anyOf" : [
66 {
77 "enum" : [
1515 {
1616 "type" : " number"
1717 }
18- ],
18+ ]
19+ }
20+ },
21+ "properties" : {
22+ "varBoolean" : {
23+ "$ref" : " #/definitions/Foo" ,
1924 "default" : false
2025 },
2126 "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" ,
3628 "default" : 123
3729 },
3830 "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" ,
5332 "default" : " 123"
5433 }
5534 },
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 11{
22 "$schema" : " http://json-schema.org/draft-07/schema#" ,
33 "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+ },
423 "MyType6" : {
524 "type" : " object"
625 }
1332 ]
1433 },
1534 "var2" : {
16- "type" : [
17- " string" ,
18- " number" ,
19- " null"
35+ "anyOf" : [
36+ {
37+ "$ref" : " #/definitions/MyType2"
38+ },
39+ {
40+ "type" : " null"
41+ }
2042 ]
2143 },
2244 "var3" : {
2345 "anyOf" : [
2446 {
25- "items" : {
26- "type" : " number"
27- },
28- "type" : " array"
29- },
30- {
31- "type" : " string"
47+ "$ref" : " #/definitions/MyType3"
3248 },
3349 {
3450 "type" : " null"
91107 ],
92108 "type" : " object"
93109}
94-
Original file line number Diff line number Diff line change 11{
22 "$schema" : " http://json-schema.org/draft-07/schema#" ,
3- "properties " : {
4- "var1 " : {
3+ "definitions " : {
4+ "MyType1 " : {
55 "type" : [
66 " string" ,
77 " number"
88 ]
99 },
10- "var2 " : {
10+ "MyType2 " : {
1111 "anyOf" : [
1212 {
13+ "type" : " array" ,
1314 "items" : {
1415 "type" : " number"
15- },
16- "type" : " array"
16+ }
1717 },
1818 {
1919 "type" : " string"
2020 }
2121 ]
2222 }
2323 },
24+ "properties" : {
25+ "var1" : {
26+ "$ref" : " #/definitions/MyType1"
27+ },
28+ "var2" : {
29+ "$ref" : " #/definitions/MyType2"
30+ }
31+ },
2432 "required" : [
2533 " var1" ,
2634 " var2"
Original file line number Diff line number Diff line change @@ -215,6 +215,7 @@ describe("schema", () => {
215215 aliasRef : true ,
216216 topRef : true ,
217217 } ) ;
218+ assertSchema ( "type-alias-or" , "MyObject" ) ;
218219 // disabled because of #80
219220 // assertSchema("type-aliases-recursive-alias-topref", "MyAlias", {
220221 // useTypeAliasRef: true,
Original file line number Diff line number Diff line change @@ -1220,14 +1220,18 @@ export class JsonSchemaGenerator {
12201220
12211221 const symbol = typ . getSymbol ( ) ;
12221222 // 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 ||
12251225 // Window is incorrectly marked as rawType here for some reason
12261226 ( this . tc . getFullyQualifiedName ( symbol ) !== "Window" &&
12271227 ( this . tc . getFullyQualifiedName ( symbol ) === "Date" ||
12281228 symbol . name === "integer" ||
12291229 this . tc . getIndexInfoOfType ( typ , ts . IndexKind . Number ) !== undefined ) ) ;
12301230
1231+ if ( isRawType && reffedType ?. escapedName && ( typ as any ) . types ) {
1232+ isRawType = false ;
1233+ }
1234+
12311235 // special case: an union where all child are string literals -> make an enum instead
12321236 let isStringEnum = false ;
12331237 if ( typ . flags & ts . TypeFlags . Union ) {
You can’t perform that action at this time.
0 commit comments