@@ -8,13 +8,24 @@ import javascript
88 * Provides classes and predicates for working with JSON schema libraries.
99 */
1010module 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 {
1313 /** Gets the data flow node whose value is being validated. */
1414 abstract DataFlow:: Node getInput ( ) ;
1515
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+ */
1721 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+ }
1829 }
1930
2031 /** A data flow node that is used a JSON schema. */
@@ -89,7 +100,7 @@ module JsonSchema {
89100 }
90101
91102 /** A call to the `validate` method of `ajv`. */
92- class AjvValidationCall extends ValidationCall , DataFlow :: CallNode {
103+ class AjvValidationCall extends ValidationCall {
93104 Instance instance ;
94105 int argIndex ;
95106
@@ -161,20 +172,20 @@ module JsonSchema {
161172 }
162173
163174 /**
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 .
166177 */
167- class JoiValidationErrorRead extends ValidationCall {
168- API :: CallNode validateCall ;
178+ class JoiValidationErrorRead extends ValidationCall , API :: CallNode {
179+ JoiValidationErrorRead ( ) { this = objectSchema ( ) . getMember ( "validate" ) . getACall ( ) }
169180
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 ) }
174182
175- override DataFlow :: Node getInput ( ) { result = validateCall . getArgument ( 0 ) }
183+ override boolean getPolarity ( ) { none ( ) }
176184
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+ }
178189 }
179190 }
180191}
0 commit comments