Skip to content

Commit 9b1ee8d

Browse files
loopingzdomoritz
andauthored
fix: do not compute definition of ignored fields (YousefED#299) (YousefED#390)
Co-authored-by: Dominik Moritz <[email protected]>
1 parent 09bee3f commit 9b1ee8d

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

test/programs/annotation-tjs/main.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
// All of these formats are defined in this specification: http://json-schema.org/latest/json-schema-validation.html#rfc.section.8.3
2+
3+
interface MyRef {}
4+
25
interface MyObject {
36
/**
47
* @TJS-format date-time
@@ -51,7 +54,7 @@ interface MyObject {
5154
regexPattern: string;
5255

5356
/**
54-
* @TJS-pattern ^[a-zA-Z0-9]{4}-abc_123$
57+
* @TJS-pattern ^[a-zA-Z0-9]{4}-abc_123$
5558
*/
5659
regexPatternWithWhitespace: string;
5760

@@ -79,4 +82,9 @@ interface MyObject {
7982
* @TJS-hide false
8083
*/
8184
booleanAnnotationWithFalse: string;
85+
86+
/**
87+
* @TJS-ignore
88+
*/
89+
complexWithRefIgnored: MyRef;
8290
}

typescript-json-schema.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -1089,6 +1089,16 @@ export class JsonSchemaGenerator {
10891089

10901090
let returnedDefinition = definition; // returned definition, may be a $ref
10911091

1092+
// Parse property comments now to skip recursive if ignore.
1093+
if (prop) {
1094+
const defs = {};
1095+
const others = {};
1096+
this.parseCommentsIntoDefinition(prop, defs, others);
1097+
if (defs.hasOwnProperty("ignore")) {
1098+
return defs;
1099+
}
1100+
}
1101+
10921102
const symbol = typ.getSymbol();
10931103
// FIXME: We can't just compare the name of the symbol - it ignores the namespace
10941104
const isRawType =
@@ -1176,7 +1186,6 @@ export class JsonSchemaGenerator {
11761186
if (prop) {
11771187
this.parseCommentsIntoDefinition(prop, returnedDefinition, otherAnnotations);
11781188
}
1179-
11801189
// Create the actual definition only if is an inline definition, or
11811190
// if it will be a $ref and it is not yet created
11821191
if (!asRef || !this.reffedDefinitions[fullTypeName]) {

0 commit comments

Comments
 (0)