|
| 1 | +{ |
| 2 | + "$schema": "https://json-schema.org/draft/2020-12/schema", |
| 3 | + "$id": "https://raw.githubusercontent.com/smocker-dev/smocker/main/docs/mock.schema.json", |
| 4 | + "title": "Smocker mocks", |
| 5 | + "description": "Schema for Smocker mock definitions (a single mock or a list of mocks), as accepted by POST /mocks and stored in mocks.yml. Source of truth: server/types.", |
| 6 | + "oneOf": [ |
| 7 | + { "$ref": "#/$defs/mock" }, |
| 8 | + { "type": "array", "items": { "$ref": "#/$defs/mock" } } |
| 9 | + ], |
| 10 | + "$defs": { |
| 11 | + "matcherName": { |
| 12 | + "type": "string", |
| 13 | + "enum": [ |
| 14 | + "ShouldResemble", |
| 15 | + "ShouldAlmostEqual", |
| 16 | + "ShouldContainSubstring", |
| 17 | + "ShouldEndWith", |
| 18 | + "ShouldEqual", |
| 19 | + "ShouldEqualJSON", |
| 20 | + "ShouldStartWith", |
| 21 | + "ShouldBeEmpty", |
| 22 | + "ShouldMatch", |
| 23 | + "ShouldNotResemble", |
| 24 | + "ShouldNotAlmostEqual", |
| 25 | + "ShouldNotContainSubstring", |
| 26 | + "ShouldNotEndWith", |
| 27 | + "ShouldNotEqual", |
| 28 | + "ShouldNotStartWith", |
| 29 | + "ShouldNotBeEmpty", |
| 30 | + "ShouldNotMatch" |
| 31 | + ] |
| 32 | + }, |
| 33 | + "stringMatcherObject": { |
| 34 | + "type": "object", |
| 35 | + "properties": { |
| 36 | + "matcher": { "$ref": "#/$defs/matcherName" }, |
| 37 | + "value": { "type": "string" } |
| 38 | + }, |
| 39 | + "required": ["matcher"], |
| 40 | + "additionalProperties": false |
| 41 | + }, |
| 42 | + "stringMatcher": { |
| 43 | + "description": "A plain string is shorthand for { matcher: ShouldEqual, value: <string> }.", |
| 44 | + "anyOf": [ |
| 45 | + { "type": "string" }, |
| 46 | + { "$ref": "#/$defs/stringMatcherObject" } |
| 47 | + ] |
| 48 | + }, |
| 49 | + "stringMatcherSlice": { |
| 50 | + "description": "A single matcher or a list of matchers.", |
| 51 | + "anyOf": [ |
| 52 | + { "$ref": "#/$defs/stringMatcher" }, |
| 53 | + { "type": "array", "items": { "$ref": "#/$defs/stringMatcher" } } |
| 54 | + ] |
| 55 | + }, |
| 56 | + "multimapMatcher": { |
| 57 | + "description": "Map of key to matcher(s), e.g. query parameters or headers to match.", |
| 58 | + "type": "object", |
| 59 | + "additionalProperties": { "$ref": "#/$defs/stringMatcherSlice" } |
| 60 | + }, |
| 61 | + "multimap": { |
| 62 | + "description": "Map of key to string value(s), e.g. response headers.", |
| 63 | + "type": "object", |
| 64 | + "additionalProperties": { |
| 65 | + "anyOf": [ |
| 66 | + { "type": "string" }, |
| 67 | + { "type": "array", "items": { "type": "string" } } |
| 68 | + ] |
| 69 | + } |
| 70 | + }, |
| 71 | + "bodyMatcher": { |
| 72 | + "description": "Matches the request body: a matcher on the whole body (string shorthand or { matcher, value }), or a map of JSON paths to matchers.", |
| 73 | + "anyOf": [ |
| 74 | + { "type": "string" }, |
| 75 | + { "$ref": "#/$defs/stringMatcherObject" }, |
| 76 | + { |
| 77 | + "type": "object", |
| 78 | + "additionalProperties": { "$ref": "#/$defs/stringMatcher" } |
| 79 | + } |
| 80 | + ] |
| 81 | + }, |
| 82 | + "duration": { |
| 83 | + "description": "A Go duration string (e.g. \"10ms\", \"1s\") or a number of nanoseconds.", |
| 84 | + "type": ["string", "integer"] |
| 85 | + }, |
| 86 | + "delay": { |
| 87 | + "description": "A fixed delay, or a random delay between min and max.", |
| 88 | + "anyOf": [ |
| 89 | + { "$ref": "#/$defs/duration" }, |
| 90 | + { |
| 91 | + "type": "object", |
| 92 | + "properties": { |
| 93 | + "min": { "$ref": "#/$defs/duration" }, |
| 94 | + "max": { "$ref": "#/$defs/duration" } |
| 95 | + }, |
| 96 | + "additionalProperties": false |
| 97 | + } |
| 98 | + ] |
| 99 | + }, |
| 100 | + "request": { |
| 101 | + "type": "object", |
| 102 | + "properties": { |
| 103 | + "method": { "$ref": "#/$defs/stringMatcher" }, |
| 104 | + "path": { "$ref": "#/$defs/stringMatcher" }, |
| 105 | + "body": { "$ref": "#/$defs/bodyMatcher" }, |
| 106 | + "query_params": { "$ref": "#/$defs/multimapMatcher" }, |
| 107 | + "headers": { "$ref": "#/$defs/multimapMatcher" } |
| 108 | + }, |
| 109 | + "additionalProperties": false |
| 110 | + }, |
| 111 | + "response": { |
| 112 | + "type": "object", |
| 113 | + "properties": { |
| 114 | + "body": { "type": "string" }, |
| 115 | + "status": { "type": "integer" }, |
| 116 | + "delay": { "$ref": "#/$defs/delay" }, |
| 117 | + "headers": { "$ref": "#/$defs/multimap" } |
| 118 | + }, |
| 119 | + "additionalProperties": false |
| 120 | + }, |
| 121 | + "dynamicResponse": { |
| 122 | + "type": "object", |
| 123 | + "properties": { |
| 124 | + "engine": { |
| 125 | + "type": "string", |
| 126 | + "enum": ["go_template", "go_template_yaml", "go_template_json", "lua"] |
| 127 | + }, |
| 128 | + "script": { "type": "string" } |
| 129 | + }, |
| 130 | + "required": ["engine", "script"], |
| 131 | + "additionalProperties": false |
| 132 | + }, |
| 133 | + "proxy": { |
| 134 | + "type": "object", |
| 135 | + "properties": { |
| 136 | + "host": { "type": "string" }, |
| 137 | + "delay": { "$ref": "#/$defs/delay" }, |
| 138 | + "follow_redirect": { "type": "boolean" }, |
| 139 | + "skip_verify_tls": { "type": "boolean" }, |
| 140 | + "keep_host": { "type": "boolean" }, |
| 141 | + "headers": { "$ref": "#/$defs/multimap" } |
| 142 | + }, |
| 143 | + "required": ["host"], |
| 144 | + "additionalProperties": false |
| 145 | + }, |
| 146 | + "context": { |
| 147 | + "type": "object", |
| 148 | + "properties": { |
| 149 | + "times": { "type": "integer", "minimum": 0 } |
| 150 | + }, |
| 151 | + "additionalProperties": false |
| 152 | + }, |
| 153 | + "state": { |
| 154 | + "description": "Server-managed runtime state (present in stored/returned mocks, not written by hand).", |
| 155 | + "type": "object", |
| 156 | + "properties": { |
| 157 | + "id": { "type": "string" }, |
| 158 | + "times_count": { "type": "integer" }, |
| 159 | + "locked": { "type": "boolean" }, |
| 160 | + "creation_date": { "type": "string" } |
| 161 | + }, |
| 162 | + "additionalProperties": false |
| 163 | + }, |
| 164 | + "mock": { |
| 165 | + "type": "object", |
| 166 | + "properties": { |
| 167 | + "request": { "$ref": "#/$defs/request" }, |
| 168 | + "response": { "$ref": "#/$defs/response" }, |
| 169 | + "dynamic_response": { "$ref": "#/$defs/dynamicResponse" }, |
| 170 | + "proxy": { "$ref": "#/$defs/proxy" }, |
| 171 | + "context": { "$ref": "#/$defs/context" }, |
| 172 | + "state": { "$ref": "#/$defs/state" } |
| 173 | + }, |
| 174 | + "additionalProperties": false, |
| 175 | + "oneOf": [ |
| 176 | + { "required": ["response"] }, |
| 177 | + { "required": ["dynamic_response"] }, |
| 178 | + { "required": ["proxy"] } |
| 179 | + ] |
| 180 | + } |
| 181 | + } |
| 182 | +} |
0 commit comments