Skip to content

Commit a422f5f

Browse files
committed
make sure that we include comments for aliased proeprties
1 parent 0c7594a commit a422f5f

File tree

3 files changed

+31
-7
lines changed

3 files changed

+31
-7
lines changed

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

+15
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,26 @@
1+
/**
2+
* My string
3+
*/
14
type MyString = string;
25

6+
/**
7+
* My type alias
8+
*/
9+
type MyAlias = MySubObject;
10+
11+
/**
12+
* My sub object
13+
*/
314
interface MySubObject {
415
propA: number;
516
propB: number;
617
}
718

19+
/**
20+
* My Object
21+
*/
822
interface MyObject {
923
primitive: MyString;
1024
object: MySubObject;
25+
alias: MyAlias;
1126
}

Diff for: test/programs/type-aliases/schema.json

+15-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
{
22
"$schema": "http://json-schema.org/draft-04/schema#",
33
"definitions": {
4+
"MyAlias": {
5+
"$ref": "#/definitions/MySubObject",
6+
"description": "My sub object"
7+
},
48
"MyString": {
9+
"description": "My string",
510
"type": "string"
611
},
712
"MySubObject": {
13+
"description": "My sub object",
814
"properties": {
915
"propA": {
1016
"type": "number"
@@ -13,14 +19,18 @@
1319
"type": "number"
1420
}
1521
},
16-
"type": "object",
1722
"required": [
1823
"propA",
1924
"propB"
20-
]
25+
],
26+
"type": "object"
2127
}
2228
},
29+
"description": "My Object",
2330
"properties": {
31+
"alias": {
32+
"$ref": "#/definitions/MyAlias"
33+
},
2434
"object": {
2535
"$ref": "#/definitions/MySubObject"
2636
},
@@ -30,7 +40,8 @@
3040
},
3141
"required": [
3242
"primitive",
33-
"object"
43+
"object",
44+
"alias"
3445
],
3546
"type": "object"
36-
}
47+
}

Diff for: typescript-json-schema.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -615,9 +615,7 @@ export class JsonSchemaGenerator {
615615
// if it will be a $ref and it is not yet created
616616
if (!asRef || !this.reffedDefinitions[fullTypeName]) {
617617
if (asRef) { // must be here to prevent recursivity problems
618-
this.reffedDefinitions[fullTypeName] = this.args.useTypeAliasRef && symbol && reffedType && reffedType.getFlags() & ts.TypeFlags.IndexedAccess ? {
619-
"$ref": "#/definitions/" + symbol.getName()
620-
} : definition;
618+
this.reffedDefinitions[fullTypeName] = asTypeAliasRef && reffedType.getFlags() & ts.TypeFlags.IndexedAccess && symbol ? this.getTypeDefinition(typ, tc, true, undefined, symbol, symbol) : definition;
621619
if (this.args.useTitle && fullTypeName) {
622620
definition.title = fullTypeName;
623621
}

0 commit comments

Comments
 (0)