Skip to content

Commit 8616cf2

Browse files
RyanLBdomoritz
authored andcommitted
[Fixes YousefED#106] Don't add ignored properties to "required" arrays (YousefED#125)
* [Fixes YousefED#106] Don't add ignored properties to "required" arrays * [squashme] PR feedback
1 parent 9576ebe commit 8616cf2

File tree

4 files changed

+34
-1
lines changed

4 files changed

+34
-1
lines changed
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
interface MyObject {
2+
/**
3+
* @ignore
4+
*/
5+
ignored: boolean;
6+
7+
/**
8+
* @ignore
9+
*/
10+
ignoredOptional?: boolean;
11+
12+
required: boolean;
13+
optional?: boolean;
14+
}
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-04/schema#",
3+
"properties": {
4+
"required": {
5+
"type": "boolean"
6+
},
7+
"optional": {
8+
"type": "boolean"
9+
}
10+
},
11+
"required": [
12+
"required"
13+
],
14+
"type": "object"
15+
}

test/schema.test.ts

+2
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ describe("schema", () => {
6969
assertSchema("class-single", "main.ts", "MyObject");
7070
assertSchema("class-extends", "main.ts", "MyObject");
7171

72+
assertSchema("ignored-required", "main.ts", "MyObject");
73+
7274
assertSchema("interface-single", "main.ts", "MyObject");
7375
assertSchema("interface-multi", "main.ts", "MyObject");
7476
assertSchema("interface-extends", "main.ts", "MyObject");

typescript-json-schema.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,9 @@ export class JsonSchemaGenerator {
585585
}
586586
if (this.args.generateRequired) {
587587
const requiredProps = props.reduce((required: string[], prop: ts.Symbol) => {
588-
if (!(prop.flags & ts.SymbolFlags.Optional) && !(<any>prop).mayBeUndefined) {
588+
let def = {};
589+
this.parseCommentsIntoDefinition(prop, def, {});
590+
if (!(prop.flags & ts.SymbolFlags.Optional) && !(<any>prop).mayBeUndefined && !def.hasOwnProperty("ignore")) {
589591
required.push(prop.getName());
590592
}
591593
return required;

0 commit comments

Comments
 (0)