{ "$schema": "http://json-schema.org/draft-07/schema", "description": "common json schema definitions for httprunner api/testcase/testsuite", "definitions": { "name": { "description": "used as api/teststep/testcase/testsuite identification", "type": "string", "examples": [ "basic test for httpbin" ] }, "base_url": { "description": "The base_url will be used with relative URI", "type": "string", "examples": [ "https://httpbin.org" ] }, "variables": { "description": "define variables for api/teststep/testcase/testsuite", "oneOf": [ { "type": "object", "examples": [ { "var1": "value1", "var2": "value2" } ] }, { "type": "array", "items": { "type": "object", "maxProperties": 1, "minProperties": 1 }, "examples": [ [ { "var1": "value1" }, { "var2": "value2" } ] ] }, { "type": "string", "pattern": "^\\$.*", "examples": [ "$prepared_variables", "${prepare_variables()}", "${prepare_variables($a, $b)}" ] } ] }, "verify": { "description": "whether to verify the server’s TLS certificate", "type": "boolean", "examples": [ true, false ] }, "hook": { "description": "used to define setup_hooks/teardown_hooks for api/teststep/testcase", "type": "array", "items": { "oneOf": [ { "description": "call setup/teardown hook functions, return nothing", "type": "string", "examples": [ [ "${sleep(2)}", "${hook_print(setup)}", "${modify_request_json($request, android)}", "${alter_response($response)}" ] ] }, { "description": "call setup/teardown hook functions, return value and assign to variable", "type": "object", "examples": [ { "total": "${sum_two(1, 5)}" }, { "filed_name": "get_decoded_response_field($response)" } ] } ] } }, "config": { "description": "used in testcase/testsuite to configure common fields", "type": "object", "properties": { "name": { "$ref": "#/definitions/name" }, "base_url": { "$ref": "#/definitions/base_url" }, "variables": { "$ref": "#/definitions/variables" }, "setup_hooks": { "$ref": "#/definitions/hook" }, "teardown_hooks": { "$ref": "#/definitions/hook" }, "verify": { "$ref": "#/definitions/verify" } }, "required": ["name"] }, "request": { "description": "used to define a api request. properties is the same as python package `requests.request`", "type": "object", "properties": { "method": { "type": "string", "description": "request method", "enum": [ "GET", "POST", "OPTIONS", "HEAD", "PUT", "PATCH", "DELETE", "CONNECT", "TRACE" ] }, "url": { "description": "request url, may be absolute or relative URI", "type": "string", "examples": [ "http://httpbin.org/get?a=1&b=2", "/get?a=1&b=2", "get?a=1&b=2" ] }, "params": { "description": "query string for request url", "type": "object", "examples": [ { "a": 1, "b": 2 } ] }, "data": { "anyOf": [ { "description": "request body in json format", "type": "object", "examples": [ { "a": 1, "b": 2 } ] }, { "description": "request body in application/x-www-form-urlencoded format", "type": "string", "examples": [ "a=1&b=2" ] }, { "description": "request body prepared with function, or reference a variable", "type": "string", "examples": [ "$post_data", "${prepare_data($a, $b)}" ] } ] }, "json": { "oneOf": [ { "description": "request body in json format", "type": "object" }, { "description": "request body prepared with function, or reference a variable", "type": "string", "pattern": "^\\$.*", "examples": [ "$post_data", "${prepare_post_data($a, $b)}" ] } ] }, "headers": { "description": "request headers", "oneOf": [ { "description": "request headers in json format", "type": "object", "examples": [ { "User-Agent": "python-requests/2.18.4", "Content-Type": "application/json" } ] }, { "description": "request headers prepared with function, or reference a variable", "type": "string", "examples": [ "$prepared_headers", "${prepare_headers($a, $b)}" ] } ] }, "cookies": { "description": "request cookies", "type": "object" }, "files": { "description": "request files, used to upload files", "type": "object" }, "auth": { "description": "Auth tuple to enable Basic/Digest/Custom HTTP Auth.", "type": "array" }, "timeout": { "description": "How many seconds to wait for the server to send data before giving up", "type": "number", "examples": [ 120 ] }, "allow_redirects": { "description": "Enable/disable GET/OPTIONS/POST/PUT/PATCH/DELETE/HEAD redirection. Defaults to True", "type": "boolean" }, "proxies": { "description": "Dictionary mapping protocol to the URL of the proxy", "type": "object" }, "verify": { "description": "configure verify for current api/teststep", "$ref": "#/definitions/verify" }, "stream": { "description": "if False, the response content will be immediately downloaded.", "type": "boolean" }, "upload": { "description": "upload files", "type": "object", "examples": [ { "file": "data/file_to_upload", "md5": "123" } ] } }, "required": [ "method", "url" ] }, "extract": { "description": "used to extract session variables for later requests", "oneOf": [ { "type": "object", "patternProperties": { "^[A-Za-z_][A-Za-z0-9_]*$": { "description": "extraction rule for session variable, maybe in jsonpath/regex/jmespath", "type": "string" } }, "examples": [ { "code__by_jsonpath": "$.code", "item_id__by_jsonpath": "$..items.*.id", "var_name__by_regex": "\"LB[\\d]*(.*)RB[\\d]*\"", "content_type": "headers.content-type", "first_name": "content.person.name.first_name" } ] }, { "type": "array", "items": { "type": "object", "patternProperties": { "^[A-Za-z_][A-Za-z0-9_]*$": { "description": "extraction rule for session variable, maybe in jsonpath/regex/jmespath", "type": "string" } }, "minProperties": 1, "maxProperties": 1 }, "examples": [ { "code__by_jsonpath": "$.code" }, { "item_id__by_jsonpath": "$..items.*.id" }, { "var_name__by_regex": "\"LB[\\d]*(.*)RB[\\d]*\"" }, { "content_type": "headers.content-type" }, { "first_name": "content.person.name.first_name" } ] } ] }, "validate": { "description": "used to validate response fields", "type": "array", "items": { "description": "one validator definition", "oneOf": [ { "type": "object", "properties": { "check": { "type": "string" }, "comparator": { "type": "string" }, "expect": { "description": "expected value" } }, "required": ["check", "expect"], "examples": [ { "check": "body.code", "comparator": "gt", "expect": 0 }, { "check": "status_code", "expect": 200 } ] }, { "type": "object", "patternProperties": { "^[A-Za-z_][A-Za-z0-9_]*$": { "description": "validate_func_name: [check_value, expect_value]", "type": "array", "minItems": 2, "maxItems": 2 } }, "examples": [ { "eq": ["status_code", 200] }, { "gt": ["body.code", 0] } ] } ] } } } }