File tree 3 files changed +22
-8
lines changed
3 files changed +22
-8
lines changed Original file line number Diff line number Diff line change @@ -156,6 +156,17 @@ Supported security types:
156
156
Customizations
157
157
##############
158
158
159
+ Spec validation
160
+ ***************
161
+
162
+ By default, spec dict is validated on spec creation time. Disabling the validation can improve the performance.
163
+
164
+ .. code-block :: python
165
+
166
+ from openapi_core import create_spec
167
+
168
+ spec = create_spec(spec_dict, validate_spec = False )
169
+
159
170
Deserializers
160
171
*************
161
172
Original file line number Diff line number Diff line change 1
1
"""OpenAPI core schema shortcuts module"""
2
2
from jsonschema .validators import RefResolver
3
- from openapi_spec_validator import default_handlers
3
+ from openapi_spec_validator import (
4
+ default_handlers , openapi_v3_spec_validator ,
5
+ )
4
6
5
7
from openapi_core .schema .specs .factories import SpecFactory
6
8
7
9
8
- def create_spec (spec_dict , spec_url = '' , handlers = default_handlers ):
10
+ def create_spec (
11
+ spec_dict , spec_url = '' , handlers = default_handlers ,
12
+ validate_spec = True ,
13
+ ):
14
+ if validate_spec :
15
+ openapi_v3_spec_validator .validate (spec_dict , spec_url = spec_url )
16
+
9
17
spec_resolver = RefResolver (
10
18
spec_url , spec_dict , handlers = handlers )
11
19
spec_factory = SpecFactory (spec_resolver )
Original file line number Diff line number Diff line change 1
1
# -*- coding: utf-8 -*-
2
2
"""OpenAPI core specs factories module"""
3
3
4
- from openapi_spec_validator import openapi_v3_spec_validator
5
4
from openapi_spec_validator .validators import Dereferencer
6
5
7
6
from openapi_core .compat import lru_cache
19
18
20
19
class SpecFactory (object ):
21
20
22
- def __init__ (self , spec_resolver , config = None ):
21
+ def __init__ (self , spec_resolver ):
23
22
self .spec_resolver = spec_resolver
24
- self .config = config or {}
25
23
26
24
def create (self , spec_dict , spec_url = '' ):
27
- if self .config .get ('validate_spec' , True ):
28
- openapi_v3_spec_validator .validate (spec_dict , spec_url = spec_url )
29
-
30
25
spec_dict_deref = self .dereferencer .dereference (spec_dict )
31
26
32
27
info_spec = spec_dict_deref .get ('info' , {})
You can’t perform that action at this time.
0 commit comments