@@ -205,7 +205,7 @@ export class ObjectASTNodeImpl extends ASTNodeImpl implements ObjectASTNode {
205
205
}
206
206
}
207
207
208
- export function asSchema ( schema : JSONSchemaRef ) {
208
+ export function asSchema ( schema : JSONSchemaRef ) : JSONSchema {
209
209
if ( isBoolean ( schema ) ) {
210
210
return schema ? { } : { not : { } } ;
211
211
}
@@ -238,13 +238,13 @@ export interface ISchemaCollector {
238
238
class SchemaCollector implements ISchemaCollector {
239
239
schemas : IApplicableSchema [ ] = [ ] ;
240
240
constructor ( private focusOffset = - 1 , private exclude : ASTNode = null ) { }
241
- add ( schema : IApplicableSchema ) {
241
+ add ( schema : IApplicableSchema ) : void {
242
242
this . schemas . push ( schema ) ;
243
243
}
244
- merge ( other : ISchemaCollector ) {
244
+ merge ( other : ISchemaCollector ) : void {
245
245
this . schemas . push ( ...other . schemas ) ;
246
246
}
247
- include ( node : ASTNode ) {
247
+ include ( node : ASTNode ) : boolean {
248
248
return ( this . focusOffset === - 1 || contains ( node , this . focusOffset ) ) && node !== this . exclude ;
249
249
}
250
250
newSub ( ) : ISchemaCollector {
@@ -256,16 +256,20 @@ class NoOpSchemaCollector implements ISchemaCollector {
256
256
private constructor ( ) {
257
257
// ignore
258
258
}
259
- get schemas ( ) {
259
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
260
+ get schemas ( ) : any [ ] {
260
261
return [ ] ;
261
262
}
262
- add ( schema : IApplicableSchema ) {
263
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
264
+ add ( schema : IApplicableSchema ) : void {
263
265
// ignore
264
266
}
265
- merge ( other : ISchemaCollector ) {
267
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
268
+ merge ( other : ISchemaCollector ) : void {
266
269
// ignore
267
270
}
268
- include ( node : ASTNode ) {
271
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
272
+ include ( node : ASTNode ) : boolean {
269
273
return true ;
270
274
}
271
275
newSub ( ) : ISchemaCollector {
@@ -383,7 +387,7 @@ export class ValidationResult {
383
387
}
384
388
}
385
389
386
- export function newJSONDocument ( root : ASTNode , diagnostics : Diagnostic [ ] = [ ] ) {
390
+ export function newJSONDocument ( root : ASTNode , diagnostics : Diagnostic [ ] = [ ] ) : JSONDocument {
387
391
return new JSONDocument ( root , diagnostics , [ ] ) ;
388
392
}
389
393
@@ -468,7 +472,8 @@ function validate(
468
472
validationResult : ValidationResult ,
469
473
matchingSchemas : ISchemaCollector ,
470
474
isKubernetes : boolean
471
- ) {
475
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
476
+ ) : any {
472
477
if ( ! node || ! matchingSchemas . include ( node ) ) {
473
478
return ;
474
479
}
@@ -481,10 +486,10 @@ function validate(
481
486
_validateArrayNode ( node , schema , validationResult , matchingSchemas ) ;
482
487
break ;
483
488
case 'string' :
484
- _validateStringNode ( node , schema , validationResult , matchingSchemas ) ;
489
+ _validateStringNode ( node , schema , validationResult ) ;
485
490
break ;
486
491
case 'number' :
487
- _validateNumberNode ( node , schema , validationResult , matchingSchemas ) ;
492
+ _validateNumberNode ( node , schema , validationResult ) ;
488
493
break ;
489
494
case 'property' :
490
495
return validate ( node . valueNode , schema , validationResult , matchingSchemas , isKubernetes ) ;
@@ -493,8 +498,8 @@ function validate(
493
498
494
499
matchingSchemas . add ( { node : node , schema : schema } ) ;
495
500
496
- function _validateNode ( ) {
497
- function matchesType ( type : string ) {
501
+ function _validateNode ( ) : void {
502
+ function matchesType ( type : string ) : boolean {
498
503
return node . type === type || ( type === 'integer' && node . type === 'number' && node . isInteger ) ;
499
504
}
500
505
@@ -540,7 +545,7 @@ function validate(
540
545
}
541
546
}
542
547
543
- const testAlternatives = ( alternatives : JSONSchemaRef [ ] , maxOneMatch : boolean ) => {
548
+ const testAlternatives = ( alternatives : JSONSchemaRef [ ] , maxOneMatch : boolean ) : number => {
544
549
const matches = [ ] ;
545
550
546
551
// remember the best match that is used for error messages
@@ -592,7 +597,7 @@ function validate(
592
597
testAlternatives ( schema . oneOf , true ) ;
593
598
}
594
599
595
- const testBranch = ( schema : JSONSchemaRef ) => {
600
+ const testBranch = ( schema : JSONSchemaRef ) : void => {
596
601
const subValidationResult = new ValidationResult ( isKubernetes ) ;
597
602
const subMatchingSchemas = matchingSchemas . newSub ( ) ;
598
603
@@ -604,7 +609,7 @@ function validate(
604
609
matchingSchemas . merge ( subMatchingSchemas ) ;
605
610
} ;
606
611
607
- const testCondition = ( ifSchema : JSONSchemaRef , thenSchema ?: JSONSchemaRef , elseSchema ?: JSONSchemaRef ) => {
612
+ const testCondition = ( ifSchema : JSONSchemaRef , thenSchema ?: JSONSchemaRef , elseSchema ?: JSONSchemaRef ) : void => {
608
613
const subSchema = asSchema ( ifSchema ) ;
609
614
const subValidationResult = new ValidationResult ( isKubernetes ) ;
610
615
const subMatchingSchemas = matchingSchemas . newSub ( ) ;
@@ -682,12 +687,7 @@ function validate(
682
687
}
683
688
}
684
689
685
- function _validateNumberNode (
686
- node : NumberASTNode ,
687
- schema : JSONSchema ,
688
- validationResult : ValidationResult ,
689
- matchingSchemas : ISchemaCollector
690
- ) : void {
690
+ function _validateNumberNode ( node : NumberASTNode , schema : JSONSchema , validationResult : ValidationResult ) : void {
691
691
const val = node . value ;
692
692
693
693
if ( isNumber ( schema . multipleOf ) ) {
@@ -748,12 +748,7 @@ function validate(
748
748
}
749
749
}
750
750
751
- function _validateStringNode (
752
- node : StringASTNode ,
753
- schema : JSONSchema ,
754
- validationResult : ValidationResult ,
755
- matchingSchemas : ISchemaCollector
756
- ) : void {
751
+ function _validateStringNode ( node : StringASTNode , schema : JSONSchema , validationResult : ValidationResult ) : void {
757
752
if ( isNumber ( schema . minLength ) && node . value . length < schema . minLength ) {
758
753
validationResult . problems . push ( {
759
754
location : { offset : node . offset , length : node . length } ,
@@ -992,7 +987,7 @@ function validate(
992
987
}
993
988
}
994
989
995
- const propertyProcessed = ( prop : string ) => {
990
+ const propertyProcessed = ( prop : string ) : void => {
996
991
let index = unprocessedProperties . indexOf ( prop ) ;
997
992
while ( index >= 0 ) {
998
993
unprocessedProperties . splice ( index , 1 ) ;
@@ -1179,7 +1174,8 @@ function validate(
1179
1174
}
1180
1175
1181
1176
//Alternative comparison is specifically used by the kubernetes/openshift schema but may lead to better results then genericComparison depending on the schema
1182
- function alternativeComparison ( subValidationResult , bestMatch , subSchema , subMatchingSchemas ) {
1177
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1178
+ function alternativeComparison ( subValidationResult , bestMatch , subSchema , subMatchingSchemas ) : any {
1183
1179
const compareResult = subValidationResult . compareKubernetes ( bestMatch . validationResult ) ;
1184
1180
if ( compareResult > 0 ) {
1185
1181
// our node is the best matching so far
@@ -1197,7 +1193,8 @@ function validate(
1197
1193
}
1198
1194
1199
1195
//genericComparison tries to find the best matching schema using a generic comparison
1200
- function genericComparison ( maxOneMatch , subValidationResult , bestMatch , subSchema , subMatchingSchemas ) {
1196
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1197
+ function genericComparison ( maxOneMatch , subValidationResult , bestMatch , subSchema , subMatchingSchemas ) : any {
1201
1198
if ( ! maxOneMatch && ! subValidationResult . hasProblems ( ) && ! bestMatch . validationResult . hasProblems ( ) ) {
1202
1199
// no errors, both are equally good matches
1203
1200
bestMatch . matchingSchemas . merge ( subMatchingSchemas ) ;
0 commit comments