Skip to content
This repository was archived by the owner on Dec 25, 2024. It is now read-only.

Commit 6c88e1f

Browse files
authored
Adds unevaluatedItems schema feature (#224)
* Stores unevaluatedItems in codegenSchema * Component schemas added and written with unevaluatedItems * Writes unevaluated_items info in python schema classes * Adds validate_unevaluated_items * Adds tests of AnyTypeUnevaluatedItemsTrue * Adds tests of AnyTypeUnevaluatedItemsFalse * Adds tests of AnyTypeUnevaluatedItemsString * Adjust component schema in sample spec for unevaluatedItems * Samples and docs updated * Adds type to fix mypy check
1 parent e791bd5 commit 6c88e1f

File tree

41 files changed

+564
-15
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+564
-15
lines changed

docs/generators/java.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
348348
|PropertyNames|✗|OAS3
349349
|Required|✓|OAS2,OAS3
350350
|Type|✓|OAS2,OAS3
351+
|UnevaluatedItems|✗|OAS3
351352
|UniqueItems|✓|OAS2,OAS3
352353
|Xml|✗|OAS2,OAS3
353354

docs/generators/jaxrs-jersey.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
331331
|PropertyNames|✗|OAS3
332332
|Required|✓|OAS2,OAS3
333333
|Type|✓|OAS2,OAS3
334+
|UnevaluatedItems|✗|OAS3
334335
|UniqueItems|✓|OAS2,OAS3
335336
|Xml|✗|OAS2,OAS3
336337

docs/generators/jmeter.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
190190
|PropertyNames|✗|OAS3
191191
|Required|✓|OAS2,OAS3
192192
|Type|✓|OAS2,OAS3
193+
|UnevaluatedItems|✗|OAS3
193194
|UniqueItems|✓|OAS2,OAS3
194195
|Xml|✗|OAS2,OAS3
195196

docs/generators/kotlin.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
300300
|PropertyNames|✗|OAS3
301301
|Required|✓|OAS2,OAS3
302302
|Type|✓|OAS2,OAS3
303+
|UnevaluatedItems|✗|OAS3
303304
|UniqueItems|✓|OAS2,OAS3
304305
|Xml|✗|OAS2,OAS3
305306

docs/generators/python.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
259259
|PropertyNames|✓|OAS3
260260
|Required|✓|OAS2,OAS3
261261
|Type|✓|OAS2,OAS3
262+
|UnevaluatedItems|✓|OAS3
262263
|UniqueItems|✓|OAS2,OAS3
263264
|Xml|✗|OAS2,OAS3
264265

samples/client/3_0_3_unit_test/python/src/unit_test_api/configurations/schema_configuration.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@
4747
'property_names': 'propertyNames',
4848
'required': 'required',
4949
'types': 'type',
50-
'unique_items': 'uniqueItems'
50+
'unique_items': 'uniqueItems',
51+
'unevaluated_items': 'unevaluatedItems'
5152
}
5253

5354
class SchemaConfiguration:

samples/client/3_0_3_unit_test/python/src/unit_test_api/schemas/validation.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,13 @@ def _validate(
109109
if 'prefix_items' in vars(cls_schema):
110110
prefix_items_length = len(vars(cls_schema)['prefix_items'])
111111
for keyword, val in json_schema_data.items():
112+
used_val: typing.Any
112113
if keyword in {'contains', 'min_contains', 'max_contains'}:
113114
used_val = (val, contains_qty)
114115
elif keyword == 'items':
115116
used_val = (val, prefix_items_length)
117+
elif keyword == 'unevaluated_items':
118+
used_val = (val, path_to_schemas)
116119
else:
117120
used_val = val
118121
validator = json_schema_keyword_to_validator[keyword]
@@ -1192,6 +1195,32 @@ def validate_prefix_items(
11921195
return path_to_schemas
11931196

11941197

1198+
def validate_unevaluated_items(
1199+
arg: typing.Any,
1200+
unevaluated_items_validated_path_to_schemas: typing.Tuple[typing.Type[SchemaValidator], PathToSchemasType],
1201+
cls: typing.Type,
1202+
validation_metadata: ValidationMetadata,
1203+
) -> typing.Optional[PathToSchemasType]:
1204+
if not isinstance(arg, tuple):
1205+
return None
1206+
path_to_schemas: PathToSchemasType = {}
1207+
module_namespace = vars(sys.modules[cls.__module__])
1208+
schema = _get_class(unevaluated_items_validated_path_to_schemas[0], module_namespace)
1209+
validated_path_to_schemas = unevaluated_items_validated_path_to_schemas[1]
1210+
for i, val in enumerate(arg):
1211+
path_to_item = validation_metadata.path_to_item + (i,)
1212+
if path_to_item in validated_path_to_schemas:
1213+
continue
1214+
item_validation_metadata = ValidationMetadata(
1215+
path_to_item=path_to_item,
1216+
configuration=validation_metadata.configuration,
1217+
validated_path_to_schemas=validation_metadata.validated_path_to_schemas
1218+
)
1219+
other_path_to_schemas = schema._validate(val, validation_metadata=item_validation_metadata)
1220+
update(path_to_schemas, other_path_to_schemas)
1221+
return path_to_schemas
1222+
1223+
11951224
validator_type = typing.Callable[[typing.Any, typing.Any, type, ValidationMetadata], typing.Optional[PathToSchemasType]]
11961225
json_schema_keyword_to_validator: typing.Mapping[str, validator_type] = {
11971226
'types': validate_types,
@@ -1227,5 +1256,6 @@ def validate_prefix_items(
12271256
'dependent_schemas': validate_dependent_schemas,
12281257
'property_names': validate_property_names,
12291258
'pattern_properties': validate_pattern_properties,
1230-
'prefix_items': validate_prefix_items
1259+
'prefix_items': validate_prefix_items,
1260+
'unevaluated_items': validate_unevaluated_items
12311261
}

samples/client/3_1_0_json_schema/python/.openapi-generator/FILES

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ docs/components/schema/any_type_min_contains_value.md
1212
docs/components/schema/any_type_pattern_properties.md
1313
docs/components/schema/any_type_prefix_items.md
1414
docs/components/schema/any_type_property_names.md
15+
docs/components/schema/any_type_unevaluated_items_false.md
16+
docs/components/schema/any_type_unevaluated_items_false_with_prefix_items.md
17+
docs/components/schema/any_type_unevaluated_items_string.md
18+
docs/components/schema/any_type_unevaluated_items_true.md
1519
docs/components/schema/array_contains_value.md
1620
docs/components/schema/array_max_contains_value.md
1721
docs/components/schema/array_min_contains_value.md
@@ -50,6 +54,10 @@ src/json_schema_api/components/schema/any_type_min_contains_value.py
5054
src/json_schema_api/components/schema/any_type_pattern_properties.py
5155
src/json_schema_api/components/schema/any_type_prefix_items.py
5256
src/json_schema_api/components/schema/any_type_property_names.py
57+
src/json_schema_api/components/schema/any_type_unevaluated_items_false.py
58+
src/json_schema_api/components/schema/any_type_unevaluated_items_false_with_prefix_items.py
59+
src/json_schema_api/components/schema/any_type_unevaluated_items_string.py
60+
src/json_schema_api/components/schema/any_type_unevaluated_items_true.py
5361
src/json_schema_api/components/schema/array_contains_value.py
5462
src/json_schema_api/components/schema/array_max_contains_value.py
5563
src/json_schema_api/components/schema/array_min_contains_value.py

samples/client/3_1_0_json_schema/python/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,10 @@ Class | Description
182182
[AnyTypePatternProperties](docs/components/schema/any_type_pattern_properties.md) |
183183
[AnyTypePrefixItems](docs/components/schema/any_type_prefix_items.md) |
184184
[AnyTypePropertyNames](docs/components/schema/any_type_property_names.md) |
185+
[AnyTypeUnevaluatedItemsFalse](docs/components/schema/any_type_unevaluated_items_false.md) |
186+
[AnyTypeUnevaluatedItemsFalseWithPrefixItems](docs/components/schema/any_type_unevaluated_items_false_with_prefix_items.md) |
187+
[AnyTypeUnevaluatedItemsString](docs/components/schema/any_type_unevaluated_items_string.md) |
188+
[AnyTypeUnevaluatedItemsTrue](docs/components/schema/any_type_unevaluated_items_true.md) |
185189
[ArrayContainsValue](docs/components/schema/array_contains_value.md) |
186190
[ArrayMaxContainsValue](docs/components/schema/array_max_contains_value.md) |
187191
[ArrayMinContainsValue](docs/components/schema/array_min_contains_value.md) |
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# AnyTypeUnevaluatedItemsFalse
2+
json_schema_api.components.schema.any_type_unevaluated_items_false
3+
```
4+
type: schemas.Schema
5+
```
6+
7+
## validate method
8+
Input Type | Return Type | Notes
9+
------------ | ------------- | -------------
10+
dict, schemas.immutabledict, str, datetime.date, datetime.datetime, uuid.UUID, int, float, bool, None, list, tuple, bytes, io.FileIO, io.BufferedReader | schemas.immutabledict, str, float, int, bool, None, tuple, bytes, io.FileIO |
11+
12+
[[Back to top]](#top) [[Back to Component Schemas]](../../../README.md#Component-Schemas) [[Back to README]](../../../README.md)

0 commit comments

Comments
 (0)