-
-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathvalidators.py
94 lines (90 loc) · 3.41 KB
/
validators.py
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
83
84
85
86
87
88
89
90
91
92
93
94
from jsonschema import _keywords
from jsonschema import _legacy_keywords
from jsonschema.validators import Draft202012Validator
from jsonschema.validators import create
from jsonschema.validators import extend
from jsonschema_specifications import REGISTRY as SPECIFICATIONS
from openapi_schema_validator import _format as oas_format
from openapi_schema_validator import _keywords as oas_keywords
from openapi_schema_validator import _types as oas_types
from openapi_schema_validator._types import oas31_type_checker
OAS30Validator = create(
meta_schema=SPECIFICATIONS.contents(
"http://json-schema.org/draft-04/schema#",
),
validators={
"multipleOf": _keywords.multipleOf,
# exclusiveMaximum supported inside maximum_draft3_draft4
"maximum": _legacy_keywords.maximum_draft3_draft4,
# exclusiveMinimum supported inside minimum_draft3_draft4
"minimum": _legacy_keywords.minimum_draft3_draft4,
"maxLength": _keywords.maxLength,
"minLength": _keywords.minLength,
"pattern": _keywords.pattern,
"maxItems": _keywords.maxItems,
"minItems": _keywords.minItems,
"uniqueItems": _keywords.uniqueItems,
"maxProperties": _keywords.maxProperties,
"minProperties": _keywords.minProperties,
"enum": _keywords.enum,
# adjusted to OAS
"type": oas_keywords.type,
"allOf": oas_keywords.allOf,
"oneOf": oas_keywords.oneOf,
"anyOf": oas_keywords.anyOf,
"not": _keywords.not_,
"items": oas_keywords.items,
"properties": _keywords.properties,
"required": oas_keywords.required,
"additionalProperties": oas_keywords.additionalProperties,
# TODO: adjust description
"format": oas_keywords.format,
# TODO: adjust default
"$ref": _keywords.ref,
# fixed OAS fields
"discriminator": oas_keywords.not_implemented,
"readOnly": oas_keywords.not_implemented,
"writeOnly": oas_keywords.not_implemented,
"xml": oas_keywords.not_implemented,
"externalDocs": oas_keywords.not_implemented,
"example": oas_keywords.not_implemented,
"deprecated": oas_keywords.not_implemented,
},
type_checker=oas_types.oas30_type_checker,
format_checker=oas_format.oas30_format_checker,
# NOTE: version causes conflict with global jsonschema validator
# See https://github.com/python-openapi/openapi-schema-validator/pull/12
# version="oas30",
id_of=lambda schema: schema.get("id", ""),
)
OAS30ReadValidator = extend(
OAS30Validator,
validators={
"required": oas_keywords.read_required,
"writeOnly": oas_keywords.read_writeOnly,
},
)
OAS30WriteValidator = extend(
OAS30Validator,
validators={
"required": oas_keywords.write_required,
"readOnly": oas_keywords.write_readOnly,
},
)
OAS31Validator = extend(
Draft202012Validator,
{
# adjusted to OAS
"allOf": oas_keywords.allOf,
"oneOf": oas_keywords.oneOf,
"anyOf": oas_keywords.anyOf,
"description": oas_keywords.not_implemented,
# fixed OAS fields
"discriminator": oas_keywords.not_implemented,
"xml": oas_keywords.not_implemented,
"externalDocs": oas_keywords.not_implemented,
"example": oas_keywords.not_implemented,
},
type_checker=oas31_type_checker,
format_checker=oas_format.oas31_format_checker,
)