Skip to content

Commit 2690d42

Browse files
committed
Add test and fix by @mrix for namspaced type aliases.
1 parent 067915e commit 2690d42

File tree

4 files changed

+60
-1
lines changed

4 files changed

+60
-1
lines changed

Diff for: test/programs/type-aliases-local-namsepace/main.ts

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
namespace A {
2+
export interface A {a: any;}
3+
}
4+
namespace B {
5+
export interface B {b: any;}
6+
}
7+
namespace C {
8+
import A = B.B;
9+
export interface C {c: A;}
10+
}
11+
namespace D {
12+
import A = C.C;
13+
export interface D {d: A;}
14+
}
15+
16+
interface MyObject extends D.D {}
+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-04/schema#",
3+
"definitions": {
4+
"B.B": {
5+
"properties": {
6+
"b": {
7+
}
8+
},
9+
"required": [
10+
"b"
11+
],
12+
"type": "object"
13+
},
14+
"C.C": {
15+
"properties": {
16+
"c": {
17+
"$ref": "#/definitions/B.B"
18+
}
19+
},
20+
"required": [
21+
"c"
22+
],
23+
"type": "object"
24+
}
25+
},
26+
"properties": {
27+
"d": {
28+
"$ref": "#/definitions/C.C"
29+
}
30+
},
31+
"required": [
32+
"d"
33+
],
34+
"type": "object"
35+
}

Diff for: test/schema.test.ts

+4
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ describe("schema", function () {
7272
});
7373
assertSchema("type-aliases-fixed-size-array", "main.ts", "MyFixedSizeArray");
7474
assertSchema("type-aliases-multitype-array", "main.ts", "MyArray");
75+
assertSchema("type-aliases-local-namsepace", "main.ts", "MyObject", {
76+
useTypeAliasRef: true
77+
});
78+
7579
assertSchema("type-anonymous", "main.ts", "MyObject");
7680
assertSchema("type-primitives", "main.ts", "MyObject");
7781
assertSchema("type-nullable", "main.ts", "MyObject");

Diff for: typescript-json-schema.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,11 @@ export class JsonSchemaGenerator {
587587

588588
let fullTypeName = "";
589589
if (asTypeAliasRef) {
590-
fullTypeName = tc.getFullyQualifiedName(reffedType).replace(REGEX_FILE_NAME, "");
590+
fullTypeName = tc.getFullyQualifiedName(
591+
reffedType.getFlags() & ts.SymbolFlags.Alias ?
592+
tc.getAliasedSymbol(reffedType) :
593+
reffedType
594+
).replace(REGEX_FILE_NAME, "");
591595
} else if (asRef) {
592596
fullTypeName = tc.typeToString(typ, undefined, ts.TypeFormatFlags.UseFullyQualifiedType);
593597
}

0 commit comments

Comments
 (0)