Skip to content

Commit 5d295b3

Browse files
johngeorgewrightdomoritz
authored andcommitted
fix: 🐛 use fully qualified name (YousefED#271)
1 parent 6d1699e commit 5d295b3

File tree

4 files changed

+44
-1
lines changed

4 files changed

+44
-1
lines changed

test/programs/custom-dates/main.ts

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace foo {
2+
export interface Date {
3+
day?: number;
4+
month?: number;
5+
year?: number;
6+
}
7+
8+
export interface Bar {
9+
date: Date;
10+
}
11+
}
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-07/schema#",
3+
"definitions": {
4+
"foo.Date": {
5+
"properties": {
6+
"day": {
7+
"type": "number"
8+
},
9+
"month": {
10+
"type": "number"
11+
},
12+
"year": {
13+
"type": "number"
14+
}
15+
},
16+
"type": "object"
17+
}
18+
},
19+
"properties": {
20+
"date": {
21+
"$ref": "#/definitions/foo.Date"
22+
}
23+
},
24+
"required": [
25+
"date"
26+
],
27+
"type": "object"
28+
}

test/schema.test.ts

+4
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,10 @@ describe("schema", () => {
270270
assertSchema("string-literals-inline", "MyObject");
271271
});
272272

273+
describe("custom dates", () => {
274+
assertSchema("custom-dates", "foo.Bar");
275+
});
276+
273277
describe("dates", () => {
274278
assertSchema("dates", "MyObject");
275279
assertRejection("dates", "MyObject", {

typescript-json-schema.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -858,7 +858,7 @@ export class JsonSchemaGenerator {
858858

859859
const symbol = typ.getSymbol();
860860
// FIXME: We can't just compare the name of the symbol - it ignores the namespace
861-
const isRawType = (!symbol || symbol.name === "Date" || symbol.name === "integer" || this.tc.getIndexInfoOfType(typ, ts.IndexKind.Number) !== undefined);
861+
const isRawType = (!symbol || this.tc.getFullyQualifiedName(symbol) === "Date" || symbol.name === "integer" || this.tc.getIndexInfoOfType(typ, ts.IndexKind.Number) !== undefined);
862862

863863
// special case: an union where all child are string literals -> make an enum instead
864864
let isStringEnum = false;

0 commit comments

Comments
 (0)