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

Commit bdad3e6

Browse files
authored
Adds unevaluatedProperties feature (#229)
* Adds unevaluatedProperties to codegenSchema * Samples regen including new schema classes * Adds unevaluatedProperties to schema classes * Adds generation of UnevaluatedProperties schema classes * Ads validate_unevaluated_properties * Adds tests of ArrayUnevaluatedItemsFalseWithPrefixItems * Adds tests for AnyTypeUnevaluatedPropertiesTrue/False * Adds tests of AnyTypeUnevaluatedPropertiesString * Adds remaining unevaluatedProperties tests * Adds unevaluatedProperties as disableable keyword and a schema feature for docs * Samples and docs regen
1 parent 9b1c56f commit bdad3e6

File tree

47 files changed

+964
-20
lines changed

Some content is hidden

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

47 files changed

+964
-20
lines changed

docs/generators/java.md

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

docs/generators/jaxrs-jersey.md

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

docs/generators/jmeter.md

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

docs/generators/kotlin.md

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

docs/generators/python.md

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

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
@@ -48,7 +48,8 @@
4848
'required': 'required',
4949
'types': 'type',
5050
'unique_items': 'uniqueItems',
51-
'unevaluated_items': 'unevaluatedItems'
51+
'unevaluated_items': 'unevaluatedItems',
52+
'unevaluated_properties': 'unevaluatedProperties'
5253
}
5354

5455
class SchemaConfiguration:

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

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def _validate(
108108
used_val = (val, contains_qty)
109109
elif keyword == 'items':
110110
used_val = (val, prefix_items_length)
111-
elif keyword == 'unevaluated_items':
111+
elif keyword in {'unevaluated_items', 'unevaluated_properties'}:
112112
used_val = (val, path_to_schemas)
113113
else:
114114
used_val = val
@@ -1217,6 +1217,32 @@ def validate_unevaluated_items(
12171217
return path_to_schemas
12181218

12191219

1220+
def validate_unevaluated_properties(
1221+
arg: typing.Any,
1222+
unevaluated_properties_validated_path_to_schemas: typing.Tuple[typing.Type[SchemaValidator], PathToSchemasType],
1223+
cls: typing.Type,
1224+
validation_metadata: ValidationMetadata,
1225+
) -> typing.Optional[PathToSchemasType]:
1226+
if not isinstance(arg, immutabledict):
1227+
return None
1228+
path_to_schemas: PathToSchemasType = {}
1229+
module_namespace = vars(sys.modules[cls.__module__])
1230+
schema = _get_class(unevaluated_properties_validated_path_to_schemas[0], module_namespace)
1231+
validated_path_to_schemas = unevaluated_properties_validated_path_to_schemas[1]
1232+
for property_name, val in arg.items():
1233+
path_to_item = validation_metadata.path_to_item + (property_name,)
1234+
if path_to_item in validated_path_to_schemas:
1235+
continue
1236+
property_validation_metadata = ValidationMetadata(
1237+
path_to_item=path_to_item,
1238+
configuration=validation_metadata.configuration,
1239+
validated_path_to_schemas=validation_metadata.validated_path_to_schemas
1240+
)
1241+
other_path_to_schemas = schema._validate(val, validation_metadata=property_validation_metadata)
1242+
update(path_to_schemas, other_path_to_schemas)
1243+
return path_to_schemas
1244+
1245+
12201246
validator_type = typing.Callable[[typing.Any, typing.Any, type, ValidationMetadata], typing.Optional[PathToSchemasType]]
12211247
json_schema_keyword_to_validator: typing.Mapping[str, validator_type] = {
12221248
'types': validate_types,
@@ -1253,5 +1279,6 @@ def validate_unevaluated_items(
12531279
'property_names': validate_property_names,
12541280
'pattern_properties': validate_pattern_properties,
12551281
'prefix_items': validate_prefix_items,
1256-
'unevaluated_items': validate_unevaluated_items
1282+
'unevaluated_items': validate_unevaluated_items,
1283+
'unevaluated_properties': validate_unevaluated_properties
12571284
}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,20 @@ docs/components/schema/any_type_unevaluated_items_false.md
1616
docs/components/schema/any_type_unevaluated_items_false_with_prefix_items.md
1717
docs/components/schema/any_type_unevaluated_items_string.md
1818
docs/components/schema/any_type_unevaluated_items_true.md
19+
docs/components/schema/any_type_unevaluated_properties_false.md
20+
docs/components/schema/any_type_unevaluated_properties_false_with_properties.md
21+
docs/components/schema/any_type_unevaluated_properties_string.md
22+
docs/components/schema/any_type_unevaluated_properties_true.md
1923
docs/components/schema/array_contains_value.md
2024
docs/components/schema/array_max_contains_value.md
2125
docs/components/schema/array_min_contains_value.md
2226
docs/components/schema/array_prefix_items.md
27+
docs/components/schema/array_unevaluated_items_false_with_prefix_items.md
2328
docs/components/schema/object_dependent_required.md
2429
docs/components/schema/object_dependent_schemas.md
2530
docs/components/schema/object_pattern_properties.md
2631
docs/components/schema/object_property_names.md
32+
docs/components/schema/object_unevaluated_properties_false_with_properties.md
2733
docs/components/schema/string_const_string.md
2834
docs/paths/some_path/get.md
2935
docs/paths/some_path/get/responses/response_200/content/application_json/schema.md
@@ -58,14 +64,20 @@ src/json_schema_api/components/schema/any_type_unevaluated_items_false.py
5864
src/json_schema_api/components/schema/any_type_unevaluated_items_false_with_prefix_items.py
5965
src/json_schema_api/components/schema/any_type_unevaluated_items_string.py
6066
src/json_schema_api/components/schema/any_type_unevaluated_items_true.py
67+
src/json_schema_api/components/schema/any_type_unevaluated_properties_false.py
68+
src/json_schema_api/components/schema/any_type_unevaluated_properties_false_with_properties.py
69+
src/json_schema_api/components/schema/any_type_unevaluated_properties_string.py
70+
src/json_schema_api/components/schema/any_type_unevaluated_properties_true.py
6171
src/json_schema_api/components/schema/array_contains_value.py
6272
src/json_schema_api/components/schema/array_max_contains_value.py
6373
src/json_schema_api/components/schema/array_min_contains_value.py
6474
src/json_schema_api/components/schema/array_prefix_items.py
75+
src/json_schema_api/components/schema/array_unevaluated_items_false_with_prefix_items.py
6576
src/json_schema_api/components/schema/object_dependent_required.py
6677
src/json_schema_api/components/schema/object_dependent_schemas.py
6778
src/json_schema_api/components/schema/object_pattern_properties.py
6879
src/json_schema_api/components/schema/object_property_names.py
80+
src/json_schema_api/components/schema/object_unevaluated_properties_false_with_properties.py
6981
src/json_schema_api/components/schema/string_const_string.py
7082
src/json_schema_api/components/schemas/__init__.py
7183
src/json_schema_api/configurations/__init__.py

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,14 +186,20 @@ Class | Description
186186
[AnyTypeUnevaluatedItemsFalseWithPrefixItems](docs/components/schema/any_type_unevaluated_items_false_with_prefix_items.md) |
187187
[AnyTypeUnevaluatedItemsString](docs/components/schema/any_type_unevaluated_items_string.md) |
188188
[AnyTypeUnevaluatedItemsTrue](docs/components/schema/any_type_unevaluated_items_true.md) |
189+
[AnyTypeUnevaluatedPropertiesFalse](docs/components/schema/any_type_unevaluated_properties_false.md) |
190+
[AnyTypeUnevaluatedPropertiesFalseWithProperties](docs/components/schema/any_type_unevaluated_properties_false_with_properties.md) |
191+
[AnyTypeUnevaluatedPropertiesString](docs/components/schema/any_type_unevaluated_properties_string.md) |
192+
[AnyTypeUnevaluatedPropertiesTrue](docs/components/schema/any_type_unevaluated_properties_true.md) |
189193
[ArrayContainsValue](docs/components/schema/array_contains_value.md) |
190194
[ArrayMaxContainsValue](docs/components/schema/array_max_contains_value.md) |
191195
[ArrayMinContainsValue](docs/components/schema/array_min_contains_value.md) |
192196
[ArrayPrefixItems](docs/components/schema/array_prefix_items.md) |
197+
[ArrayUnevaluatedItemsFalseWithPrefixItems](docs/components/schema/array_unevaluated_items_false_with_prefix_items.md) |
193198
[ObjectDependentRequired](docs/components/schema/object_dependent_required.md) |
194199
[ObjectDependentSchemas](docs/components/schema/object_dependent_schemas.md) |
195200
[ObjectPatternProperties](docs/components/schema/object_pattern_properties.md) |
196201
[ObjectPropertyNames](docs/components/schema/object_property_names.md) |
202+
[ObjectUnevaluatedPropertiesFalseWithProperties](docs/components/schema/object_unevaluated_properties_false_with_properties.md) |
197203
[StringConstString](docs/components/schema/string_const_string.md) |
198204

199205
## Notes for Large OpenAPI documents
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# AnyTypeUnevaluatedPropertiesFalse
2+
json_schema_api.components.schema.any_type_unevaluated_properties_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)