|
1 | 1 | # -*- coding: utf-8 -*-
|
| 2 | +from jsonschema.validators import Draft202012Validator |
| 3 | +from jsonschema.validators import Draft4Validator |
| 4 | +from jsonschema_spec.handlers import default_handlers |
| 5 | + |
| 6 | +from openapi_schema_validator.validators import OAS30Validator |
| 7 | +from openapi_schema_validator.validators import OAS31Validator |
2 | 8 | from openapi_spec_validator.shortcuts import (
|
3 | 9 | validate_spec_factory, validate_spec_url_factory,
|
4 | 10 | )
|
5 |
| -from openapi_spec_validator.handlers import UrlHandler, FileObjectHandler |
6 | 11 | from openapi_spec_validator.schemas import get_openapi_schema
|
7 |
| -from openapi_spec_validator.factories import \ |
8 |
| - Draft202012JSONSpecValidatorFactory, Draft4JSONSpecValidatorFactory |
9 | 12 | from openapi_spec_validator.validators import SpecValidator
|
10 | 13 |
|
11 | 14 | __author__ = 'Artur Maciag'
|
|
31 | 34 | 'validate_spec_url',
|
32 | 35 | ]
|
33 | 36 |
|
34 |
| -file_object_handler = FileObjectHandler() |
35 |
| -all_urls_handler = UrlHandler('http', 'https', 'file') |
36 |
| -default_handlers = { |
37 |
| - '<all_urls>': all_urls_handler, |
38 |
| - 'http': UrlHandler('http'), |
39 |
| - 'https': UrlHandler('https'), |
40 |
| - 'file': UrlHandler('file'), |
41 |
| -} |
42 |
| - |
43 | 37 | # v2.0 spec
|
44 |
| -schema_v2, schema_v2_url = get_openapi_schema('2.0') |
45 |
| -openapi_v2_validator_factory = Draft4JSONSpecValidatorFactory( |
46 |
| - schema_v2, schema_v2_url, |
47 |
| - resolver_handlers=default_handlers, |
48 |
| -) |
| 38 | +schema_v2, _ = get_openapi_schema('2.0') |
| 39 | +openapi_v2_schema_validator = Draft4Validator(schema_v2) |
49 | 40 | openapi_v2_spec_validator = SpecValidator(
|
50 |
| - openapi_v2_validator_factory, |
| 41 | + openapi_v2_schema_validator, OAS30Validator, |
51 | 42 | resolver_handlers=default_handlers,
|
52 | 43 | )
|
53 | 44 |
|
54 | 45 | # v3.0 spec
|
55 |
| -schema_v30, schema_v30_url = get_openapi_schema('3.0') |
56 |
| -openapi_v30_validator_factory = Draft4JSONSpecValidatorFactory( |
57 |
| - schema_v30, schema_v30_url, |
58 |
| - resolver_handlers=default_handlers, |
59 |
| -) |
| 46 | +schema_v30, _ = get_openapi_schema('3.0') |
| 47 | +openapi_v30_schema_validator = Draft4Validator(schema_v30) |
60 | 48 | openapi_v30_spec_validator = SpecValidator(
|
61 |
| - openapi_v30_validator_factory, |
| 49 | + openapi_v30_schema_validator, OAS30Validator, |
62 | 50 | resolver_handlers=default_handlers,
|
63 | 51 | )
|
64 | 52 |
|
65 | 53 | # v3.1 spec
|
66 |
| -schema_v31, schema_v31_url = get_openapi_schema('3.1') |
67 |
| -openapi_v31_validator_factory = Draft202012JSONSpecValidatorFactory( |
68 |
| - schema_v31, schema_v31_url, |
69 |
| - resolver_handlers=default_handlers, |
70 |
| -) |
| 54 | +schema_v31, _ = get_openapi_schema('3.1') |
| 55 | +openapi_v31_schema_validator = Draft202012Validator(schema_v31) |
71 | 56 | openapi_v31_spec_validator = SpecValidator(
|
72 |
| - openapi_v31_validator_factory, |
| 57 | + openapi_v31_schema_validator, OAS31Validator, |
73 | 58 | resolver_handlers=default_handlers,
|
74 | 59 | )
|
75 | 60 |
|
|
89 | 74 |
|
90 | 75 | # aliases to the latest v3 version
|
91 | 76 | schema_v3 = schema_v31
|
92 |
| -schema_v3_url = schema_v31_url |
93 |
| -openapi_v3_validator_factory = openapi_v31_validator_factory |
94 | 77 | openapi_v3_spec_validator = openapi_v31_spec_validator
|
95 | 78 | validate_v3_spec = validate_v31_spec
|
96 | 79 | validate_v3_spec_url = validate_v31_spec_url
|
|
0 commit comments