Skip to content

Commit 9de84a9

Browse files
committed
chore: cleanup
1 parent 209233f commit 9de84a9

File tree

3 files changed

+42
-38
lines changed

3 files changed

+42
-38
lines changed

src/compileSchema.getChild.test.ts

Lines changed: 40 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ describe("compileSchema : getNodeChild", () => {
1414

1515
assert(isSchemaNode(node), "should have returned a valid schema node");
1616

17-
assert.deepEqual(node.schema, { type: "string", minLength: 1 });
17+
assert.deepEqual(node?.schema, { type: "string", minLength: 1 });
1818
});
1919

2020
it("should return node of property even it type differs", () => {
@@ -27,7 +27,7 @@ describe("compileSchema : getNodeChild", () => {
2727

2828
assert(isSchemaNode(node), "should have returned a valid schema node");
2929

30-
assert.deepEqual(node.schema, { type: "string", minLength: 1 });
30+
assert.deepEqual(node?.schema, { type: "string", minLength: 1 });
3131
});
3232

3333
it("should return undefined if property is not defined, but allowed", () => {
@@ -61,7 +61,7 @@ describe("compileSchema : getNodeChild", () => {
6161
}
6262
}).getNodeChild("title", { body: "abc" });
6363

64-
assert.deepEqual(node.schema, { type: "string", allOf: [{ minLength: 1 }] });
64+
assert.deepEqual(node?.schema, { type: "string", allOf: [{ minLength: 1 }] });
6565
});
6666

6767
it("should reduce parent schema for returned property", () => {
@@ -79,7 +79,7 @@ describe("compileSchema : getNodeChild", () => {
7979
]
8080
}).getNodeChild("title", { body: "abc" });
8181

82-
assert.deepEqual(node.schema, { type: "string", minLength: 1 });
82+
assert.deepEqual(node?.schema, { type: "string", minLength: 1 });
8383
});
8484
});
8585

@@ -91,7 +91,7 @@ describe("compileSchema : getNodeChild", () => {
9191

9292
assert(isSchemaNode(node), "should have returned a valid schema property node");
9393

94-
assert.deepEqual(node.schema, { anyOf: [{ multipleOf: 2 }, { multipleOf: 3 }] });
94+
assert.deepEqual(node?.schema, { anyOf: [{ multipleOf: 2 }, { multipleOf: 3 }] });
9595
});
9696
});
9797

@@ -107,7 +107,7 @@ describe("compileSchema : getNodeChild", () => {
107107

108108
assert(isSchemaNode(node), "should have returned a valid schema property node");
109109

110-
assert.deepEqual(node.schema, { type: "string", maxLength: 3 });
110+
assert.deepEqual(node?.schema, { type: "string", maxLength: 3 });
111111
});
112112

113113
it("should reduce parent if-else schema when returning node", () => {
@@ -121,7 +121,7 @@ describe("compileSchema : getNodeChild", () => {
121121

122122
assert(isSchemaNode(node), "should have returned a valid schema property node");
123123

124-
assert.deepEqual(node.schema, { type: "string", minLength: 4 });
124+
assert.deepEqual(node?.schema, { type: "string", minLength: 4 });
125125
});
126126

127127
it("should reduce parent anyOf schema when returning property node", () => {
@@ -133,7 +133,7 @@ describe("compileSchema : getNodeChild", () => {
133133

134134
assert(isSchemaNode(node), "should have returned a valid schema property node");
135135

136-
assert.deepEqual(node.schema, { type: "string", minLength: 1 });
136+
assert.deepEqual(node?.schema, { type: "string", minLength: 1 });
137137
});
138138

139139
it("should reduce all matching parent anyOf schema when returning property node", () => {
@@ -145,7 +145,7 @@ describe("compileSchema : getNodeChild", () => {
145145

146146
assert(isSchemaNode(node), "should have returned a valid schema property node");
147147

148-
assert.deepEqual(node.schema, { type: "string", minLength: 1, maxLength: 1 });
148+
assert.deepEqual(node?.schema, { type: "string", minLength: 1, maxLength: 1 });
149149
});
150150

151151
it("should reduce all allOf schema when returning property node", () => {
@@ -157,7 +157,7 @@ describe("compileSchema : getNodeChild", () => {
157157

158158
assert(isSchemaNode(node), "should have returned a valid schema property node");
159159

160-
assert.deepEqual(node.schema, { type: "string", minLength: 1, maxLength: 1 });
160+
assert.deepEqual(node?.schema, { type: "string", minLength: 1, maxLength: 1 });
161161
});
162162

163163
it("should reduce matching oneOf schema when returning property node", () => {
@@ -169,7 +169,7 @@ describe("compileSchema : getNodeChild", () => {
169169

170170
assert(isSchemaNode(node), "should have returned a valid schema property node");
171171

172-
assert.deepEqual(node.schema, { type: "string", maxLength: 1 });
172+
assert.deepEqual(node?.schema, { type: "string", maxLength: 1 });
173173
});
174174

175175
it("should return matching oneOf schema with `additionalProperties=false`", () => {
@@ -181,7 +181,7 @@ describe("compileSchema : getNodeChild", () => {
181181
}).getNodeChild("title", { title: "" });
182182
assert(isSchemaNode(node), "should have returned a valid schema property node");
183183

184-
assert.deepEqual(node.schema, { type: "string" });
184+
assert.deepEqual(node?.schema, { type: "string" });
185185
});
186186

187187
it("should return error when multiple oneOf-items match", () => {
@@ -216,7 +216,7 @@ describe("compileSchema : getNodeChild", () => {
216216

217217
assert(isSchemaNode(node), "should have returned a valid schema property node");
218218

219-
assert.deepEqual(node.schema, { type: "string", minLength: 1 });
219+
assert.deepEqual(node?.schema, { type: "string", minLength: 1 });
220220
});
221221

222222
it("should get merged property from patternProperties", () => {
@@ -228,7 +228,7 @@ describe("compileSchema : getNodeChild", () => {
228228

229229
assert(isSchemaNode(node), "should have returned a valid schema property node");
230230

231-
assert.deepEqual(node.schema, { type: "string", minLength: 1, maxLength: 3 });
231+
assert.deepEqual(node?.schema, { type: "string", minLength: 1, maxLength: 3 });
232232
});
233233

234234
it("should get property from merged allOf schema", () => {
@@ -239,7 +239,7 @@ describe("compileSchema : getNodeChild", () => {
239239

240240
assert(isSchemaNode(node), "should have returned a valid schema property node");
241241

242-
assert.deepEqual(node.schema, { type: "string", minLength: 1 });
242+
assert.deepEqual(node?.schema, { type: "string", minLength: 1 });
243243
});
244244

245245
it("should return combined allOf schema", () => {
@@ -260,7 +260,7 @@ describe("compileSchema : getNodeChild", () => {
260260

261261
const { node } = res.reduceNode({ trigger: true });
262262

263-
assert.deepEqual(node.schema, {
263+
assert.deepEqual(node?.schema, {
264264
type: "object",
265265
properties: {
266266
trigger: { type: "boolean" },
@@ -281,7 +281,7 @@ describe("compileSchema : getNodeChild", () => {
281281

282282
assert(isSchemaNode(node), "should have returned a valid schema property node");
283283

284-
assert.deepEqual(node.schema, { type: "number", minimum: 1 });
284+
assert.deepEqual(node?.schema, { type: "number", minimum: 1 });
285285
});
286286

287287
it("should get property from matching oneOf schema", () => {
@@ -295,7 +295,7 @@ describe("compileSchema : getNodeChild", () => {
295295

296296
assert(isSchemaNode(node), "should have returned a valid schema property node");
297297

298-
assert.deepEqual(node.schema, { type: "string", minLength: 2 });
298+
assert.deepEqual(node?.schema, { type: "string", minLength: 2 });
299299
});
300300

301301
it("should return `undefined` for valid oneOf property missing the property", () => {
@@ -320,7 +320,7 @@ describe("compileSchema : getNodeChild", () => {
320320

321321
assert(isSchemaNode(node), "should have returned a valid schema property node");
322322

323-
assert.deepEqual(node.schema, { type: "string", maxLength: 2 });
323+
assert.deepEqual(node?.schema, { type: "string", maxLength: 2 });
324324
});
325325

326326
it("should get property from else schema", () => {
@@ -333,7 +333,7 @@ describe("compileSchema : getNodeChild", () => {
333333

334334
assert(isSchemaNode(node), "should have returned a valid schema property node");
335335

336-
assert.deepEqual(node.schema, { type: "number", minimum: 1 });
336+
assert.deepEqual(node?.schema, { type: "number", minimum: 1 });
337337
});
338338
});
339339

@@ -372,7 +372,7 @@ describe("step", () => {
372372
}
373373
}).getNodeChild("title");
374374

375-
assert.deepEqual(node.schema, { type: "string" });
375+
assert.deepEqual(node?.schema, { type: "string" });
376376
});
377377

378378
it("should return error undefined for undefined schema", () => {
@@ -445,7 +445,7 @@ describe("step", () => {
445445
{ type: "object", properties: { title: { type: "number" } } }
446446
]
447447
}).getNodeChild("title", { title: 4 });
448-
assert.deepEqual(node.schema, { type: "number" });
448+
assert.deepEqual(node?.schema, { type: "number" });
449449
});
450450

451451
it("should return matching oneOf, for objects missing properties", () => {
@@ -455,7 +455,7 @@ describe("step", () => {
455455
{ type: "object", additionalProperties: { type: "number" } }
456456
]
457457
}).getNodeChild("title", { title: 4, test: 2 });
458-
assert.deepEqual(node.schema, { type: "number" });
458+
assert.deepEqual(node?.schema, { type: "number" });
459459
});
460460

461461
it("should return matching anyOf", () => {
@@ -466,7 +466,7 @@ describe("step", () => {
466466
]
467467
}).getNodeChild("title", { title: 4, test: 2 });
468468

469-
assert.deepEqual(node.schema, { type: "number" });
469+
assert.deepEqual(node?.schema, { type: "number" });
470470
});
471471

472472
it("should return combined anyOf schema", () => {
@@ -478,7 +478,7 @@ describe("step", () => {
478478
]
479479
}).getNodeChild("title", { title: 4, test: 2 });
480480

481-
assert.deepEqual(node.schema, { type: "number", minimum: 2 });
481+
assert.deepEqual(node?.schema, { type: "number", minimum: 2 });
482482
});
483483

484484
it("should resolve references from anyOf schema", () => {
@@ -495,15 +495,15 @@ describe("step", () => {
495495
]
496496
}).getNodeChild("title", { title: 4, test: 2 });
497497

498-
assert.deepEqual(node.schema, { type: "number", minimum: 2 });
498+
assert.deepEqual(node?.schema, { type: "number", minimum: 2 });
499499
});
500500

501501
it("should return matching allOf schema", () => {
502502
const { node } = compileSchema({
503503
allOf: [{ type: "object" }, { additionalProperties: { type: "number" } }]
504504
}).getNodeChild("title", { title: 4, test: 2 });
505505

506-
assert.deepEqual(node.schema, { type: "number" });
506+
assert.deepEqual(node?.schema, { type: "number" });
507507
});
508508

509509
it("should resolve references in allOf schema", () => {
@@ -515,7 +515,7 @@ describe("step", () => {
515515
allOf: [{ $ref: "#/definitions/object" }, { $ref: "#/definitions/additionalNumber" }]
516516
}).getNodeChild("title", { title: 4, test: 2 });
517517

518-
assert.deepEqual(node.schema, { type: "number" });
518+
assert.deepEqual(node?.schema, { type: "number" });
519519
});
520520

521521
it("should return matching patternProperty", () => {
@@ -527,7 +527,7 @@ describe("step", () => {
527527
}
528528
}).getNodeChild("second");
529529

530-
assert.deepEqual(node.schema, { type: "string", id: "second" });
530+
assert.deepEqual(node?.schema, { type: "string", id: "second" });
531531
});
532532

533533
it("should return additionalProperties schema for not matching patternProperty", () => {
@@ -540,7 +540,7 @@ describe("step", () => {
540540
additionalProperties: { type: "object" }
541541
}).getNodeChild("third");
542542

543-
assert.deepEqual(node.schema, { type: "object" });
543+
assert.deepEqual(node?.schema, { type: "object" });
544544
});
545545
});
546546

@@ -558,16 +558,16 @@ describe("step", () => {
558558
type: "array",
559559
items: { type: "string" }
560560
}).getNodeChild(0);
561-
assert.deepEqual(node.schema, { type: "string" });
561+
assert.deepEqual(node?.schema, { type: "string" });
562562
});
563563

564564
it("should return item at index", () => {
565-
const { node, error } = compileSchema({
565+
const { node } = compileSchema({
566566
type: "array",
567567
prefixItems: [{ type: "string" }, { type: "number" }, { type: "boolean" }]
568568
}).getNodeChild(1, ["3", 2]);
569569

570-
assert.deepEqual(node.schema, { type: "number" });
570+
assert.deepEqual(node?.schema, { type: "number" });
571571
});
572572

573573
it("should return matching item in oneOf", () => {
@@ -583,7 +583,7 @@ describe("step", () => {
583583

584584
const { node } = res.reduceNode({ title: 2 });
585585

586-
assert.deepEqual(node.schema, {
586+
assert.deepEqual(node?.schema, {
587587
type: "object",
588588
properties: { title: { type: "number" } }
589589
});
@@ -599,9 +599,10 @@ describe("step", () => {
599599
}
600600
}).getNodeChild(1, [{ title: "two" }, { title: 4 }]);
601601

602+
assert(res, "should have returned node");
602603
const { node } = res.reduceNode({ title: 4 });
603604

604-
assert.deepEqual(node.schema, { type: "object", properties: { title: { type: "number" } } });
605+
assert.deepEqual(node?.schema, { type: "object", properties: { title: { type: "number" } } });
605606
});
606607

607608
it("should return combined anyOf schema", () => {
@@ -615,9 +616,10 @@ describe("step", () => {
615616
}
616617
}).getNodeChild(1, [{ title: "two" }, { title: 4 }]);
617618

619+
assert(res, "should have returned node");
618620
const { node } = res.reduceNode({ title: 4 });
619621

620-
assert.deepEqual(node.schema, { type: "object", properties: { title: { type: "number", minimum: 2 } } });
622+
assert.deepEqual(node?.schema, { type: "object", properties: { title: { type: "number", minimum: 2 } } });
621623
});
622624

623625
it("should return combined allOf schema", () => {
@@ -630,9 +632,10 @@ describe("step", () => {
630632
}
631633
}).getNodeChild(1, [{ title: "two" }, { title: 4 }]);
632634

635+
assert(res, "should have returned node");
633636
const { node } = res.reduceNode({ title: "two" });
634637

635-
assert.deepEqual(node.schema, {
638+
assert.deepEqual(node?.schema, {
636639
type: "object",
637640
properties: { title: { type: "number", minimum: 3 } }
638641
});

src/compileSchema.validate.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { compileSchema } from "./compileSchema";
22
import { strict as assert } from "assert";
33
import { Draft, JsonError, SchemaNode } from "./types";
44
import { draft2020 } from "./draft2020";
5-
import { ValidationResult } from "./Keyword";
65

76
describe("compileSchema.validate", () => {
87
describe("integer", () => {

src/tests/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ import { JsonSchema } from "../types";
33

44
export function shouldReturnTypeNode(schema: JsonSchema) {
55
const root = compileSchema(schema);
6+
// eslint-disable-next-line
67
const { node: childNode, error } = root.getNode("/test", undefined, { createSchema: true });
78
// getNode should return NodeOrError
89
}
910

1011
export function shouldReturnTypeNodeOrUndefined(schema: JsonSchema) {
1112
const root = compileSchema(schema);
13+
// eslint-disable-next-line
1214
const { node: childNode, error } = root.getNode("/test");
1315
// getNode should return OptionalNodeOrError
1416
}

0 commit comments

Comments
 (0)