@@ -8,13 +8,24 @@ import javascript
8
8
* Provides classes and predicates for working with JSON schema libraries.
9
9
*/
10
10
module JsonSchema {
11
- /** A node that validates an input against a JSON schema. */
12
- abstract class ValidationCall extends DataFlow:: Node {
11
+ /** A call that validates an input against a JSON schema. */
12
+ abstract class ValidationCall extends DataFlow:: CallNode {
13
13
/** Gets the data flow node whose value is being validated. */
14
14
abstract DataFlow:: Node getInput ( ) ;
15
15
16
- /** Gets the return value that indicates successful validation. */
16
+ /**
17
+ * Gets if the return value indicates successfull or unsuccessful validation.
18
+ * Is not defined if the return value from this call does not directly
19
+ * indicate success.
20
+ */
17
21
boolean getPolarity ( ) { result = true }
22
+
23
+ /**
24
+ * Gets a value that indicates whether the validation was successful.
25
+ */
26
+ DataFlow:: Node getAValidationResultAccess ( boolean polarity ) {
27
+ result = this and polarity = getPolarity ( )
28
+ }
18
29
}
19
30
20
31
/** A data flow node that is used a JSON schema. */
@@ -89,7 +100,7 @@ module JsonSchema {
89
100
}
90
101
91
102
/** A call to the `validate` method of `ajv`. */
92
- class AjvValidationCall extends ValidationCall , DataFlow :: CallNode {
103
+ class AjvValidationCall extends ValidationCall {
93
104
Instance instance ;
94
105
int argIndex ;
95
106
@@ -161,20 +172,20 @@ module JsonSchema {
161
172
}
162
173
163
174
/**
164
- * A read of the `error` property from a validation result, seen as a `ValidationCall` .
165
- * If `error` exists, then the validation failed .
175
+ * A call to the `validate` method from the [`joi`](https://npmjs.org/package/joi) library .
176
+ * The `error` property in the result indicates whether the validation was successful .
166
177
*/
167
- class JoiValidationErrorRead extends ValidationCall {
168
- API :: CallNode validateCall ;
178
+ class JoiValidationErrorRead extends ValidationCall , API :: CallNode {
179
+ JoiValidationErrorRead ( ) { this = objectSchema ( ) . getMember ( "validate" ) . getACall ( ) }
169
180
170
- JoiValidationErrorRead ( ) {
171
- validateCall = objectSchema ( ) .getMember ( "validate" ) .getACall ( ) and
172
- this = validateCall .getReturn ( ) .getMember ( "error" ) .getAnImmediateUse ( )
173
- }
181
+ override DataFlow:: Node getInput ( ) { result = this .getArgument ( 0 ) }
174
182
175
- override DataFlow :: Node getInput ( ) { result = validateCall . getArgument ( 0 ) }
183
+ override boolean getPolarity ( ) { none ( ) }
176
184
177
- override boolean getPolarity ( ) { result = false }
185
+ override DataFlow:: Node getAValidationResultAccess ( boolean polarity ) {
186
+ result = this .getReturn ( ) .getMember ( "error" ) .getAnImmediateUse ( ) and
187
+ polarity = false
188
+ }
178
189
}
179
190
}
180
191
}
0 commit comments