@@ -833,12 +833,34 @@ public function seeResponseContainsJson($json = [])
833833 }
834834
835835 /**
836- * Checks whether last response matches the supplied json schema
837- * Supply schema as json string
836+ * Checks whether last response matches the supplied json schema (https://json-schema.org/)
837+ * Supply schema as json string.
838838 *
839+ * Examples:
840+ *
841+ * ``` php
842+ * <?php
843+ * // response: {"name": "john", "age": 20}
844+ * $I->seeResponseIsValidOnJsonSchemaString('{"type": "object"}');
845+ *
846+ * // response {"name": "john", "age": 20}
847+ * $schema = [
848+ * "properties" => [
849+ * "age" => [
850+ * "type" => "integer",
851+ * "minimum" => 18
852+ * ]
853+ * ]
854+ * ];
855+ * $I->seeResponseIsValidOnJsonSchemaString(json_encode($schema));
856+ *
857+ * ?>
858+ * ```
859+ *
860+ * @param string $schema
839861 * @part json
840862 */
841- public function seeResponseIsValidOnJsonSchema ($ schema )
863+ public function seeResponseIsValidOnJsonSchemaString ($ schema )
842864 {
843865 $ responseContent = $ this ->connectionModule ->_getResponseContent ();
844866 \PHPUnit \Framework \Assert::assertNotEquals ('' , $ responseContent , 'response is empty ' );
@@ -861,6 +883,24 @@ public function seeResponseIsValidOnJsonSchema($schema)
861883 );
862884 }
863885
886+ /**
887+ * Checks whether last response matches the supplied json schema (https://json-schema.org/)
888+ * Supply schema as relative file path in your project directory or an absolute path
889+ *
890+ * @see codecept_absolute_path()
891+ *
892+ * @param string $schemaFilename
893+ * @part json
894+ */
895+ public function seeResponseIsValidOnJsonSchema ($ schemaFilename )
896+ {
897+ $ file = codecept_absolute_path ($ schemaFilename );
898+ if (!file_exists ($ file )) {
899+ throw new ModuleException (__CLASS__ , "File $ file does not exist " );
900+ }
901+ $ this ->seeResponseIsValidOnJsonSchemaString (file_get_contents ($ file ));
902+ }
903+
864904 /**
865905 * Converts string to json and asserts that no error occured while decoding.
866906 *
0 commit comments