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

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

17 statements  

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.not_implemented, 

53 "writeOnly": oas_keywords.not_implemented, 

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 "writeOnly": oas_keywords.read_writeOnly, 

72 }, 

73) 

74OAS30WriteValidator = extend( 

75 OAS30Validator, 

76 validators={ 

77 "required": oas_keywords.write_required, 

78 "readOnly": oas_keywords.write_readOnly, 

79 }, 

80) 

81 

82OAS31Validator = extend( 

83 Draft202012Validator, 

84 { 

85 # adjusted to OAS 

86 "allOf": oas_keywords.allOf, 

87 "oneOf": oas_keywords.oneOf, 

88 "anyOf": oas_keywords.anyOf, 

89 "description": oas_keywords.not_implemented, 

90 # fixed OAS fields 

91 "discriminator": oas_keywords.not_implemented, 

92 "xml": oas_keywords.not_implemented, 

93 "externalDocs": oas_keywords.not_implemented, 

94 "example": oas_keywords.not_implemented, 

95 }, 

96 type_checker=oas31_type_checker, 

97 format_checker=oas_format.oas31_format_checker, 

98)