Skip to content

Commit 2511b63

Browse files
committed
Fixes YousefED#72
1 parent e5a4319 commit 2511b63

File tree

3 files changed

+42
-13
lines changed

3 files changed

+42
-13
lines changed

test/programs/type-nullable/main.ts

+7
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,18 @@ type Ref = { foo: number };
1616
/** @nullable */
1717
type MyType5 = Ref;
1818

19+
interface MyType6 {};
1920

2021
interface MyObject {
2122
var1: MyType1;
2223
var2: MyType2;
2324
var3: MyType3;
2425
var4: MyType4;
2526
var5: MyType5;
27+
28+
/**
29+
* @nullable
30+
*/
31+
var6: MyType6;
32+
var7: MyType6;
2633
}

test/programs/type-nullable/schema.json

+32-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
{
2-
"type": "object",
2+
"$schema": "http://json-schema.org/draft-04/schema#",
3+
"definitions": {
4+
"MyType6": {
5+
"properties": {
6+
},
7+
"type": "object"
8+
}
9+
},
310
"properties": {
411
"var1": {
512
"type": [
@@ -17,10 +24,10 @@
1724
"var3": {
1825
"anyOf": [
1926
{
20-
"type": "array",
2127
"items": {
2228
"type": "number"
23-
}
29+
},
30+
"type": "array"
2431
},
2532
{
2633
"type": "string"
@@ -33,10 +40,10 @@
3340
"var4": {
3441
"anyOf": [
3542
{
36-
"type": "array",
3743
"items": {
3844
"type": "number"
39-
}
45+
},
46+
"type": "array"
4047
},
4148
{
4249
"type": "null"
@@ -46,28 +53,43 @@
4653
"var5": {
4754
"anyOf": [
4855
{
49-
"type": "object",
5056
"properties": {
5157
"foo": {
5258
"type": "number"
5359
}
5460
},
5561
"required": [
5662
"foo"
57-
]
63+
],
64+
"type": "object"
5865
},
5966
{
6067
"type": "null"
6168
}
6269
]
70+
},
71+
"var6": {
72+
"anyOf": [
73+
{
74+
"$ref": "#/definitions/MyType6"
75+
},
76+
{
77+
"type": "null"
78+
}
79+
]
80+
},
81+
"var7": {
82+
"$ref": "#/definitions/MyType6"
6383
}
6484
},
6585
"required": [
6686
"var1",
6787
"var2",
6888
"var3",
6989
"var4",
70-
"var5"
90+
"var5",
91+
"var6",
92+
"var7"
7193
],
72-
"$schema": "http://json-schema.org/draft-04/schema#"
73-
}
94+
"type": "object"
95+
}

typescript-json-schema.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -619,10 +619,10 @@ export class JsonSchemaGenerator {
619619
} else {
620620
this.getClassDefinition(typ, tc, definition);
621621
}
622+
}
622623

623-
if (otherAnnotations["nullable"]) {
624-
this.makeNullable(definition);
625-
}
624+
if (otherAnnotations["nullable"]) {
625+
this.makeNullable(returnedDefinition);
626626
}
627627

628628
return returnedDefinition;

0 commit comments

Comments
 (0)