@@ -4,26 +4,33 @@ from collections import Counter
4
4
import time
5
5
6
6
import falcon
7
- from falcon.media.validators.jsonschema import validate
8
-
7
+ from falcon.media import validators
8
+ try :
9
+ import jsonschema
10
+ except ImportError :
11
+ jsonschema = None
12
+ try :
13
+ import jsonschema_rs
14
+ except ImportError :
15
+ jsonschema_rs = None
9
16
10
17
_MESSAGE_SCHEMA = {
11
- ' definitions' : {},
12
- ' $schema' : ' http://json-schema.org/draft-07/schema#' ,
13
- ' $id' : ' http://example.com/root.json' ,
14
- ' type' : ' object' ,
15
- ' title' : ' The Root Schema' ,
16
- ' required' : [' message' ],
17
- ' properties' : {
18
- ' message' : {
19
- ' $id' : ' #/properties/message' ,
20
- ' type' : ' string' ,
21
- ' title' : ' The Message Schema' ,
22
- ' default' : ' ' ,
23
- ' examples' : [' hello world' ],
24
- ' pattern' : ' ^(.*)$'
25
- }
26
- }
18
+ ' definitions' : {},
19
+ ' $schema' : ' http://json-schema.org/draft-07/schema#' ,
20
+ ' $id' : ' http://example.com/root.json' ,
21
+ ' type' : ' object' ,
22
+ ' title' : ' The Root Schema' ,
23
+ ' required' : [' message' ],
24
+ ' properties' : {
25
+ ' message' : {
26
+ ' $id' : ' #/properties/message' ,
27
+ ' type' : ' string' ,
28
+ ' title' : ' The Message Schema' ,
29
+ ' default' : ' ' ,
30
+ ' examples' : [' hello world' ],
31
+ ' pattern' : ' ^(.*)$'
32
+ }
33
+ }
27
34
}
28
35
29
36
@@ -43,20 +50,37 @@ class NOPClass:
43
50
pass
44
51
45
52
46
- class TestResourceWithValidation :
47
- @ validate (resp_schema = _MESSAGE_SCHEMA, is_async = True )
48
- async def on_get(self , req, resp):
49
- resp.media = {
50
- ' message' : ' hello world'
51
- }
53
+ if jsonschema:
54
+ class TestResourceWithValidation :
55
+ @ validators.jsonschema.validate (resp_schema = _MESSAGE_SCHEMA, is_async = True )
56
+ async def on_get(self , req, resp):
57
+ resp.media = {
58
+ ' message' : ' hello world'
59
+ }
52
60
53
61
54
- class TestResourceWithValidationNoHint :
55
- @ validate (resp_schema = _MESSAGE_SCHEMA)
56
- async def on_get(self , req, resp):
57
- resp.media = {
58
- ' message' : ' hello world'
59
- }
62
+ class TestResourceWithValidationNoHint :
63
+ @ validators.jsonschema.validate (resp_schema = _MESSAGE_SCHEMA)
64
+ async def on_get(self , req, resp):
65
+ resp.media = {
66
+ ' message' : ' hello world'
67
+ }
68
+
69
+ if jsonschema_rs:
70
+ class TestResourceWithValidationRs :
71
+ @ validators.jsonschema_rs.validate (resp_schema = _MESSAGE_SCHEMA, is_async = True )
72
+ async def on_get(self , req, resp):
73
+ resp.media = {
74
+ ' message' : ' hello world'
75
+ }
76
+
77
+
78
+ class TestResourceWithValidationNoHintRs :
79
+ @ validators.jsonschema_rs.validate (resp_schema = _MESSAGE_SCHEMA)
80
+ async def on_get(self , req, resp):
81
+ resp.media = {
82
+ ' message' : ' hello world'
83
+ }
60
84
61
85
62
86
class TestResourceWithScheduledJobs :
@@ -85,7 +109,7 @@ class TestResourceWithScheduledJobsAsyncRequired:
85
109
pass
86
110
87
111
# NOTE(kgriffs): This will fail later since we can't detect
88
- # up front that it isn't a coroutine function.
112
+ # up front that it isn't a coroutine function.
89
113
resp.schedule(background_job_sync)
90
114
91
115
0 commit comments