forked from TykTechnologies/tyk-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhttpbin_json_schema_validation.yaml
82 lines (79 loc) · 2.36 KB
/
httpbin_json_schema_validation.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
apiVersion: tyk.tyk.io/v1alpha1
kind: ApiDefinition
metadata:
name: httpbin-json-schema-validation
spec:
name: httpbin-json-schema-validation
use_keyless: true
protocol: http
active: true
proxy:
target_url: http://httpbin.org
listen_path: /httpbin
strip_listen_path: true
version_data:
default_version: Default
not_versioned: true
versions:
Default:
name: Default
use_extended_paths: true
paths:
black_list: []
ignored: []
white_list: []
extended_paths:
validate_json:
- error_response_code: 422
disabled: false
path: /get
method: GET
schema:
properties:
userName:
type: string
minLength: 2
age:
type: integer
minimum: 1
required:
- userName
type: object
# k apply -f config/samples/httpbin_json_schema_validation.yaml
# apidefinition.tyk.tyk.io/httpbin-json-schema-validation created
# curl -i -X GET "http://localhost:8080/httpbin/get" -H "Content-Type: application/json" -d '{"userName":"b","age":0}'
# HTTP/1.1 422 Unprocessable Entity
# Content-Type: application/json
# X-Generator: tyk.io
# Date: Thu, 03 Feb 2022 21:36:40 GMT
# Content-Length: 118
#
# {
# "error": "userName: String length must be greater than or equal to 2; age: Must be greater than or equal to 1"
# }%
# curl -i -X GET "http://localhost:8080/httpbin/get" -H "Content-Type: application/json" -d '{"userName":"burak","age":2}'
# HTTP/1.1 200 OK
# Access-Control-Allow-Credentials: true
# Access-Control-Allow-Origin: *
# Content-Length: 366
# Content-Type: application/json
# Date: Thu, 03 Feb 2022 21:40:13 GMT
# Server: gunicorn/19.9.0
# X-Ratelimit-Limit: 0
# X-Ratelimit-Remaining: 0
# X-Ratelimit-Reset: 0
#
# {
# "args": {},
# "headers": {
# "Accept": "*/*",
# "Accept-Encoding": "gzip",
# "Content-Length": "28",
# "Content-Type": "application/json",
# "Host": "httpbin.org",
# "User-Agent": "curl/7.77.0",
# "X-Amzn-Trace-Id": "Root=1-61fc4bbd-678a309c73e8ee4a0fe7dbee"
# },
# "origin": "127.0.0.1, 176.88.45.17",
# "url": "http://httpbin.org/get"
# }