Skip to content

Commit 94293e7

Browse files
authored
Remove check for !forceNotRef (#549)
1 parent b3ea0a0 commit 94293e7

File tree

4 files changed

+60
-1
lines changed

4 files changed

+60
-1
lines changed

test/programs/no-ref/main.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
type MySubType = {
2+
id: string;
3+
};
4+
5+
export type MyModule = {
6+
address: MySubType & { extraProp: number };
7+
address2: MySubType;
8+
address3: MySubType;
9+
};

test/programs/no-ref/schema.json

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"type": "object",
3+
"properties": {
4+
"address": {
5+
"additionalProperties": false,
6+
"type": "object",
7+
"properties": {
8+
"id": {
9+
"type": "string"
10+
},
11+
"extraProp": {
12+
"type": "number"
13+
}
14+
},
15+
"required": ["extraProp", "id"]
16+
},
17+
"address2": {
18+
"additionalProperties": false,
19+
"type": "object",
20+
"properties": {
21+
"id": {
22+
"type": "string"
23+
}
24+
},
25+
"required": ["id"]
26+
},
27+
"address3": {
28+
"additionalProperties": false,
29+
"type": "object",
30+
"properties": {
31+
"id": {
32+
"type": "string"
33+
}
34+
},
35+
"required": ["id"]
36+
}
37+
},
38+
"additionalProperties": false,
39+
"required": ["address", "address2", "address3"],
40+
"$schema": "http://json-schema.org/draft-07/schema#"
41+
}

test/schema.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,15 @@ describe("schema", () => {
266266
});
267267
});
268268

269+
describe("no-refs", () => {
270+
assertSchema("no-ref", "MyModule", {
271+
ref: false,
272+
aliasRef: false,
273+
topRef: false,
274+
noExtraProps: true,
275+
});
276+
});
277+
269278
describe("annotations", () => {
270279
assertSchema("annotation-default", "MyObject");
271280
assertSchema("annotation-ref", "MyObject", {}, undefined, undefined, {

typescript-json-schema.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1422,7 +1422,7 @@ export class JsonSchemaGenerator {
14221422
}
14231423
}
14241424

1425-
if (this.recursiveTypeRef.get(fullTypeName) === definition && !forceNotRef) {
1425+
if (this.recursiveTypeRef.get(fullTypeName) === definition) {
14261426
this.recursiveTypeRef.delete(fullTypeName);
14271427
// If the type was recursive (there is reffedDefinitions) - lets replace it to reference
14281428
if (this.reffedDefinitions[fullTypeName]) {

0 commit comments

Comments
 (0)