Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/openapi_schema_validator/validators.py: 100%

17 statements  

« prev     ^ index     » next       coverage.py v7.3.1, created at 2023-09-25 06:30 +0000

1import warnings 

2from typing import Any 

3from typing import Type 

4 

5from jsonschema import _keywords 

6from jsonschema import _legacy_keywords 

7from jsonschema.validators import Draft202012Validator 

8from jsonschema.validators import create 

9from jsonschema.validators import extend 

10from jsonschema_specifications import REGISTRY as SPECIFICATIONS 

11 

12from openapi_schema_validator import _format as oas_format 

13from openapi_schema_validator import _keywords as oas_keywords 

14from openapi_schema_validator import _types as oas_types 

15from openapi_schema_validator._types import oas31_type_checker 

16 

17OAS30Validator = create( 

18 meta_schema=SPECIFICATIONS.contents( 

19 "http://json-schema.org/draft-04/schema#", 

20 ), 

21 validators={ 

22 "multipleOf": _keywords.multipleOf, 

23 # exclusiveMaximum supported inside maximum_draft3_draft4 

24 "maximum": _legacy_keywords.maximum_draft3_draft4, 

25 # exclusiveMinimum supported inside minimum_draft3_draft4 

26 "minimum": _legacy_keywords.minimum_draft3_draft4, 

27 "maxLength": _keywords.maxLength, 

28 "minLength": _keywords.minLength, 

29 "pattern": _keywords.pattern, 

30 "maxItems": _keywords.maxItems, 

31 "minItems": _keywords.minItems, 

32 "uniqueItems": _keywords.uniqueItems, 

33 "maxProperties": _keywords.maxProperties, 

34 "minProperties": _keywords.minProperties, 

35 "enum": _keywords.enum, 

36 # adjusted to OAS 

37 "type": oas_keywords.type, 

38 "allOf": oas_keywords.allOf, 

39 "oneOf": oas_keywords.oneOf, 

40 "anyOf": oas_keywords.anyOf, 

41 "not": _keywords.not_, 

42 "items": oas_keywords.items, 

43 "properties": _keywords.properties, 

44 "required": oas_keywords.required, 

45 "additionalProperties": oas_keywords.additionalProperties, 

46 # TODO: adjust description 

47 "format": oas_keywords.format, 

48 # TODO: adjust default 

49 "$ref": _keywords.ref, 

50 # fixed OAS fields 

51 "discriminator": oas_keywords.not_implemented, 

52 "readOnly": oas_keywords.readOnly, 

53 "writeOnly": oas_keywords.writeOnly, 

54 "xml": oas_keywords.not_implemented, 

55 "externalDocs": oas_keywords.not_implemented, 

56 "example": oas_keywords.not_implemented, 

57 "deprecated": oas_keywords.not_implemented, 

58 }, 

59 type_checker=oas_types.oas30_type_checker, 

60 format_checker=oas_format.oas30_format_checker, 

61 # NOTE: version causes conflict with global jsonschema validator 

62 # See https://github.com/python-openapi/openapi-schema-validator/pull/12 

63 # version="oas30", 

64 id_of=lambda schema: schema.get("id", ""), 

65) 

66 

67OAS30ReadValidator = extend( 

68 OAS30Validator, 

69 validators={ 

70 "required": oas_keywords.read_required, 

71 "readOnly": oas_keywords.not_implemented, 

72 "writeOnly": oas_keywords.writeOnly, 

73 }, 

74) 

75OAS30WriteValidator = extend( 

76 OAS30Validator, 

77 validators={ 

78 "required": oas_keywords.write_required, 

79 "readOnly": oas_keywords.readOnly, 

80 "writeOnly": oas_keywords.not_implemented, 

81 }, 

82) 

83 

84OAS31Validator = extend( 

85 Draft202012Validator, 

86 { 

87 # adjusted to OAS 

88 "allOf": oas_keywords.allOf, 

89 "oneOf": oas_keywords.oneOf, 

90 "anyOf": oas_keywords.anyOf, 

91 "description": oas_keywords.not_implemented, 

92 # fixed OAS fields 

93 "discriminator": oas_keywords.not_implemented, 

94 "xml": oas_keywords.not_implemented, 

95 "externalDocs": oas_keywords.not_implemented, 

96 "example": oas_keywords.not_implemented, 

97 }, 

98 type_checker=oas31_type_checker, 

99 format_checker=oas_format.oas31_format_checker, 

100)