From bf89fe5c6ad24fbbe87e692c0eb358cbc4375a94 Mon Sep 17 00:00:00 2001 From: readyou <791100944@qq.com> Date: Wed, 11 Dec 2019 17:50:58 +0800 Subject: [PATCH] add json schema --- httprunner/loader/schemas/v2/api.schema.json | 42 +++++++ .../schemas/v2/common/config.schema.json | 25 +++++ .../schemas/v2/common/extract.schema.json | 13 +++ .../loader/schemas/v2/common/hook.schema.json | 10 ++ .../schemas/v2/common/request.schema.json | 93 ++++++++++++++++ .../schemas/v2/common/validate.schema.json | 15 +++ .../loader/schemas/v2/testcase.schema.json | 104 ++++++++++++++++++ .../loader/schemas/v2/testsuite.schema.json | 58 ++++++++++ 8 files changed, 360 insertions(+) create mode 100644 httprunner/loader/schemas/v2/api.schema.json create mode 100644 httprunner/loader/schemas/v2/common/config.schema.json create mode 100644 httprunner/loader/schemas/v2/common/extract.schema.json create mode 100644 httprunner/loader/schemas/v2/common/hook.schema.json create mode 100644 httprunner/loader/schemas/v2/common/request.schema.json create mode 100644 httprunner/loader/schemas/v2/common/validate.schema.json create mode 100644 httprunner/loader/schemas/v2/testcase.schema.json create mode 100644 httprunner/loader/schemas/v2/testsuite.schema.json diff --git a/httprunner/loader/schemas/v2/api.schema.json b/httprunner/loader/schemas/v2/api.schema.json new file mode 100644 index 00000000..431a61b8 --- /dev/null +++ b/httprunner/loader/schemas/v2/api.schema.json @@ -0,0 +1,42 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema", + "$id": "https://raw.githubusercontent.com/readyou/httprunner/dev/httprunner/loader/schemas/v2/api.schema.json", + "title": "Api for httprunner", + "description": "Api for httprunner", + "type": "object", + "properties": { + "name": { + "type": "string", + "description": "Name of the api" + }, + "base_url": { + "type": "string", + "description": "The base_url will be added before a relative URI" + }, + "request": { + "$ref": "https://raw.githubusercontent.com/readyou/httprunner/dev/httprunner/loader/schemas/v2/common/request.schema.json" + }, + "variables": { + "type": "object", + "description": "Variables for the api" + }, + "extract": { + "type": "array", + "description": "Extract rules", + "items": { + "$ref": "https://raw.githubusercontent.com/readyou/httprunner/dev/httprunner/loader/schemas/v2/common/extract.schema.json" + } + }, + "validate": { + "type": "array", + "description": "Validate rules", + "items": { + "$ref": "https://raw.githubusercontent.com/readyou/httprunner/dev/httprunner/loader/schemas/v2/common/validate.schema.json" + } + } + }, + "required": [ + "name", + "request" + ] +} \ No newline at end of file diff --git a/httprunner/loader/schemas/v2/common/config.schema.json b/httprunner/loader/schemas/v2/common/config.schema.json new file mode 100644 index 00000000..67de36ac --- /dev/null +++ b/httprunner/loader/schemas/v2/common/config.schema.json @@ -0,0 +1,25 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema", + "$id": "https://raw.githubusercontent.com/readyou/httprunner/dev/httprunner/loader/schemas/v2/common/config.schema.json", + "title": "Config for httprunner", + "description": "Used in teststep/testcase/testsuite", + "type": "object", + "properties": { + "name": { + "type": "string" + }, + "base_url": { + "type": "string", + "description": "The base_url will be added before a relative URI" + }, + "variables": { + "type": "object" + }, + "setup_hooks": { + "$ref": "https://raw.githubusercontent.com/readyou/httprunner/dev/httprunner/loader/schemas/v2/common/hook.schema.json" + }, + "teardown_hooks": { + "$ref": "https://raw.githubusercontent.com/readyou/httprunner/dev/httprunner/loader/schemas/v2/common/hook.schema.json" + } + } +} \ No newline at end of file diff --git a/httprunner/loader/schemas/v2/common/extract.schema.json b/httprunner/loader/schemas/v2/common/extract.schema.json new file mode 100644 index 00000000..cf24863d --- /dev/null +++ b/httprunner/loader/schemas/v2/common/extract.schema.json @@ -0,0 +1,13 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema", + "$id": "https://raw.githubusercontent.com/readyou/httprunner/dev/httprunner/loader/schemas/v2/common/extract.schema.json", + "title": "Extract rules for httprunner", + "description": "Used to extract variables for later requests", + "type": "object", + "patternProperties": { + ".*": { + "description": "extracted_variable_name: extract_rule", + "type": "string" + } + } +} \ No newline at end of file diff --git a/httprunner/loader/schemas/v2/common/hook.schema.json b/httprunner/loader/schemas/v2/common/hook.schema.json new file mode 100644 index 00000000..f80be216 --- /dev/null +++ b/httprunner/loader/schemas/v2/common/hook.schema.json @@ -0,0 +1,10 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema", + "$id": "https://raw.githubusercontent.com/readyou/httprunner/dev/httprunner/loader/schemas/v2/common/hook.schema.json", + "title": "setup_hooks or teardown_hooks for httprunner", + "description": "Define setup_hooks or teardown_hooks for httprunner", + "type": "array", + "items": { + "type": "string" + } +} \ No newline at end of file diff --git a/httprunner/loader/schemas/v2/common/request.schema.json b/httprunner/loader/schemas/v2/common/request.schema.json new file mode 100644 index 00000000..c9385ea0 --- /dev/null +++ b/httprunner/loader/schemas/v2/common/request.schema.json @@ -0,0 +1,93 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema", + "$id": "https://raw.githubusercontent.com/readyou/httprunner/dev/httprunner/loader/schemas/v2/common/request.schema.json", + "title": "request for httprunner", + "description": "Used to define a api or used in a teststep. Same parameters as python's package 'requests'", + "type": "object", + "properties": { + "method": { + "type": "string", + "description": "Request method", + "enum": [ + "GET", + "POST", + "OPTIONS", + "HEAD", + "PUT", + "PATCH", + "DELETE" + ] + }, + "url": { + "description": "Request url", + "type": "string" + }, + "params": { + "type": "object", + "description": "Used to define the parameters of a 'GET' request" + }, + "data": { + "type": "object", + "description": "Used to define the parameters of a 'POST' request in the application/x-www-form-urlencoded format" + }, + "json": { + "type": "object", + "description": "Used to define the parameters of a 'POST' request in the application/json format" + }, + "headers": { + "description": "Request headers", + "type": "object" + }, + "cookies": { + "description": "Request cookies", + "type": "object" + }, + "files": { + "type": "object" + }, + "auth": { + "type": "array" + }, + "timeout": { + "type": "number" + }, + "allow_redirects": { + "type": "boolean" + }, + "proxies": { + "type": "object" + }, + "verify": { + "oneOf": [ + { + "type": "boolean" + }, + { + "type": "string" + } + ] + }, + "stream": { + "type": "boolean" + }, + "cert": { + "oneOf": [ + { + "type": "string" + }, + { + "type": "array", + "maxItems": 2, + "minItems": 2, + "items": { + "type": "string" + } + } + ] + } + }, + "required": [ + "method", + "url" + ] +} \ No newline at end of file diff --git a/httprunner/loader/schemas/v2/common/validate.schema.json b/httprunner/loader/schemas/v2/common/validate.schema.json new file mode 100644 index 00000000..14371992 --- /dev/null +++ b/httprunner/loader/schemas/v2/common/validate.schema.json @@ -0,0 +1,15 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema", + "$id": "https://raw.githubusercontent.com/readyou/httprunner/dev/httprunner/loader/schemas/v2/common/validate.schema.json", + "title": "Validate rule of httprunner", + "description": "Validate rule of httprunner", + "type": "object", + "patternProperties": { + ".*": { + "type": "array", + "description": "validate_function_name: [check_value, expect_value]", + "minItems": 2, + "maxItems": 2 + } + } +} \ No newline at end of file diff --git a/httprunner/loader/schemas/v2/testcase.schema.json b/httprunner/loader/schemas/v2/testcase.schema.json new file mode 100644 index 00000000..b4c4198c --- /dev/null +++ b/httprunner/loader/schemas/v2/testcase.schema.json @@ -0,0 +1,104 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema", + "$id": "https://raw.githubusercontent.com/readyou/httprunner/dev/httprunner/loader/schemas/v2/testcase.schema.json", + "title": "Testcase for httprunner", + "description": "Testcase for httprunner", + "type": "object", + "properties": { + "config": { + "$ref": "https://raw.githubusercontent.com/readyou/httprunner/dev/httprunner/loader/schemas/v2/common/config.schema.json" + }, + "teststeps": { + "description": "Teststep of a testcase", + "type": "array", + "items": { + "$ref": "#/definitions/teststep" + } + } + }, + "required": [ + "teststeps" + ], + "definitions": { + "teststep": { + "type": "object", + "oneOf": [ + { + "properties": { + "name": { + "description": "Teststep name", + "type": "string" + }, + "api": { + "description": "Api reference, it's usually the relative path of the api", + "type": "string" + }, + "variables": { + "type": "object" + }, + "extract": { + "description": "Extract rules", + "type": "array", + "items": { + "$ref": "https://raw.githubusercontent.com/readyou/httprunner/dev/httprunner/loader/schemas/v2/common/extract.schema.json" + } + }, + "validate": { + "description": "Validate rules", + "type": "array", + "items": { + "$ref": "https://raw.githubusercontent.com/readyou/httprunner/dev/httprunner/loader/schemas/v2/common/validate.schema.json" + } + }, + "setup_hooks": { + "$ref": "https://raw.githubusercontent.com/readyou/httprunner/dev/httprunner/loader/schemas/v2/common/hook.schema.json" + }, + "teardown_hooks": { + "$ref": "https://raw.githubusercontent.com/readyou/httprunner/dev/httprunner/loader/schemas/v2/common/hook.schema.json" + } + }, + "required": [ + "api" + ] + }, + { + "properties": { + "name": { + "description": "Teststep name", + "type": "string" + }, + "request": { + "$ref": "https://raw.githubusercontent.com/readyou/httprunner/dev/httprunner/loader/schemas/v2/common/request.schema.json" + }, + "variables": { + "type": "object" + }, + "extract": { + "description": "Extract rules", + "type": "array", + "items": { + "$ref": "https://raw.githubusercontent.com/readyou/httprunner/dev/httprunner/loader/schemas/v2/common/extract.schema.json" + } + }, + "validate": { + "description": "Validate rules", + "type": "array", + "items": { + "$ref": "https://raw.githubusercontent.com/readyou/httprunner/dev/httprunner/loader/schemas/v2/common/validate.schema.json" + } + }, + "setup_hooks": { + "$ref": "https://raw.githubusercontent.com/readyou/httprunner/dev/httprunner/loader/schemas/v2/common/hook.schema.json" + }, + "teardown_hooks": { + "$ref": "https://raw.githubusercontent.com/readyou/httprunner/dev/httprunner/loader/schemas/v2/common/hook.schema.json" + } + }, + "required": [ + "request" + ] + } + ] + } + } +} \ No newline at end of file diff --git a/httprunner/loader/schemas/v2/testsuite.schema.json b/httprunner/loader/schemas/v2/testsuite.schema.json new file mode 100644 index 00000000..41e0de57 --- /dev/null +++ b/httprunner/loader/schemas/v2/testsuite.schema.json @@ -0,0 +1,58 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema", + "$id": "https://raw.githubusercontent.com/readyou/httprunner/dev/httprunner/loader/schemas/v2/testsuite.schema.json", + "title": "Testsuite for httprunner", + "description": "Testsuite for httprunner", + "type": "object", + "properties": { + "config": { + "allOf": [ + { + "$ref": "https://raw.githubusercontent.com/readyou/httprunner/dev/httprunner/loader/schemas/v2/common/config.schema.json" + } + ], + "properties": { + "verify": { + "type": "boolean" + } + } + }, + "testcases": { + "type": "array", + "items": { + "$ref": "#/definitions/testcase" + } + }, + "setup_hooks": { + "$ref": "https://raw.githubusercontent.com/readyou/httprunner/dev/httprunner/loader/schemas/v2/common/hook.schema.json" + }, + "teardown_hooks": { + "$ref": "https://raw.githubusercontent.com/readyou/httprunner/dev/httprunner/loader/schemas/v2/common/hook.schema.json" + } + }, + "required": [ + "testcases" + ], + "definitions": { + "testcase": { + "type": "object", + "properties": { + "name": { + "description": "Testcase name", + "type": "string" + }, + "parameters": { + "description": "Parameters will generate cartesian product variables, each set of variables is tested once", + "type": "object" + }, + "testcase": { + "description": "Testcase reference, it's usually the relative path of the testcase", + "type": "string" + } + }, + "required": [ + "testcase" + ] + } + } +} \ No newline at end of file