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

+1
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

+1
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

+1
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

+1
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

+1
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

+2-1
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

+29-2
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

+12
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

+6
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
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)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# AnyTypeUnevaluatedPropertiesFalseWithProperties
2+
json_schema_api.components.schema.any_type_unevaluated_properties_false_with_properties
3+
```
4+
type: schemas.Schema
5+
```
6+
7+
## validate method
8+
Input Type | Return Type | Notes
9+
------------ | ------------- | -------------
10+
[AnyTypeUnevaluatedPropertiesFalseWithPropertiesDictInput](#anytypeunevaluatedpropertiesfalsewithpropertiesdictinput), [AnyTypeUnevaluatedPropertiesFalseWithPropertiesDict](#anytypeunevaluatedpropertiesfalsewithpropertiesdict), str, datetime.date, datetime.datetime, uuid.UUID, int, float, bool, None, list, tuple, bytes, io.FileIO, io.BufferedReader | [AnyTypeUnevaluatedPropertiesFalseWithPropertiesDict](#anytypeunevaluatedpropertiesfalsewithpropertiesdict), str, float, int, bool, None, tuple, bytes, io.FileIO |
11+
12+
## AnyTypeUnevaluatedPropertiesFalseWithPropertiesDictInput
13+
```
14+
type: typing.Mapping[str, schemas.INPUT_TYPES_ALL]
15+
```
16+
Key | Type | Description | Notes
17+
------------ | ------------- | ------------- | -------------
18+
**someProp** | str | | [optional]
19+
**any_string_name** | dict, schemas.immutabledict, list, tuple, decimal.Decimal, float, int, str, datetime.date, datetime.datetime, uuid.UUID, bool, None, bytes, io.FileIO, io.BufferedReader, schemas.FileIO | any string name can be used but the value must be the correct type | [optional]
20+
21+
## AnyTypeUnevaluatedPropertiesFalseWithPropertiesDict
22+
```
23+
base class: schemas.immutabledict[str, str]
24+
25+
```
26+
### __new__ method
27+
Keyword Argument | Type | Description | Notes
28+
---------------- | ---- | ----------- | -----
29+
**someProp** | str, schemas.Unset | | [optional]
30+
**kwargs** | schemas.immutabledict, tuple, float, int, str, bool, None, bytes, schemas.FileIO | any string name can be used but the value must be the correct type | [optional] typed value is accessed with the get_additional_property_ method
31+
32+
### properties
33+
Property | Type | Description | Notes
34+
-------- | ---- | ----------- | -----
35+
**someProp** | str, schemas.Unset | | [optional]
36+
37+
### methods
38+
Method | Input Type | Return Type | Notes
39+
------ | ---------- | ----------- | ------
40+
from_dict_ | [AnyTypeUnevaluatedPropertiesFalseWithPropertiesDictInput](#anytypeunevaluatedpropertiesfalsewithpropertiesdictinput), [AnyTypeUnevaluatedPropertiesFalseWithPropertiesDict](#anytypeunevaluatedpropertiesfalsewithpropertiesdict), str, datetime.date, datetime.datetime, uuid.UUID, int, float, bool, None, list, tuple, bytes, io.FileIO, io.BufferedReader | [AnyTypeUnevaluatedPropertiesFalseWithPropertiesDict](#anytypeunevaluatedpropertiesfalsewithpropertiesdict), str, float, int, bool, None, tuple, bytes, io.FileIO | a constructor
41+
get_additional_property_ | str | schemas.immutabledict, tuple, float, int, str, bool, None, bytes, schemas.FileIO, schemas.Unset }} | provides type safety for additional properties
42+
43+
[[Back to top]](#top) [[Back to Component Schemas]](../../../README.md#Component-Schemas) [[Back to README]](../../../README.md)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# AnyTypeUnevaluatedPropertiesString
2+
json_schema_api.components.schema.any_type_unevaluated_properties_string
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)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# AnyTypeUnevaluatedPropertiesTrue
2+
json_schema_api.components.schema.any_type_unevaluated_properties_true
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)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# ArrayUnevaluatedItemsFalseWithPrefixItems
2+
json_schema_api.components.schema.array_unevaluated_items_false_with_prefix_items
3+
```
4+
type: schemas.Schema
5+
```
6+
7+
## validate method
8+
Input Type | Return Type | Notes
9+
------------ | ------------- | -------------
10+
list, tuple | tuple |
11+
12+
[[Back to top]](#top) [[Back to Component Schemas]](../../../README.md#Component-Schemas) [[Back to README]](../../../README.md)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# ObjectUnevaluatedPropertiesFalseWithProperties
2+
json_schema_api.components.schema.object_unevaluated_properties_false_with_properties
3+
```
4+
type: schemas.Schema
5+
```
6+
7+
## validate method
8+
Input Type | Return Type | Notes
9+
------------ | ------------- | -------------
10+
[ObjectUnevaluatedPropertiesFalseWithPropertiesDictInput](#objectunevaluatedpropertiesfalsewithpropertiesdictinput), [ObjectUnevaluatedPropertiesFalseWithPropertiesDict](#objectunevaluatedpropertiesfalsewithpropertiesdict) | [ObjectUnevaluatedPropertiesFalseWithPropertiesDict](#objectunevaluatedpropertiesfalsewithpropertiesdict) |
11+
12+
## ObjectUnevaluatedPropertiesFalseWithPropertiesDictInput
13+
```
14+
type: typing.Mapping[str, schemas.INPUT_TYPES_ALL]
15+
```
16+
Key | Type | Description | Notes
17+
------------ | ------------- | ------------- | -------------
18+
**someProp** | str | | [optional]
19+
**any_string_name** | dict, schemas.immutabledict, list, tuple, decimal.Decimal, float, int, str, datetime.date, datetime.datetime, uuid.UUID, bool, None, bytes, io.FileIO, io.BufferedReader, schemas.FileIO | any string name can be used but the value must be the correct type | [optional]
20+
21+
## ObjectUnevaluatedPropertiesFalseWithPropertiesDict
22+
```
23+
base class: schemas.immutabledict[str, str]
24+
25+
```
26+
### __new__ method
27+
Keyword Argument | Type | Description | Notes
28+
---------------- | ---- | ----------- | -----
29+
**someProp** | str, schemas.Unset | | [optional]
30+
**kwargs** | schemas.immutabledict, tuple, float, int, str, bool, None, bytes, schemas.FileIO | any string name can be used but the value must be the correct type | [optional] typed value is accessed with the get_additional_property_ method
31+
32+
### properties
33+
Property | Type | Description | Notes
34+
-------- | ---- | ----------- | -----
35+
**someProp** | str, schemas.Unset | | [optional]
36+
37+
### methods
38+
Method | Input Type | Return Type | Notes
39+
------ | ---------- | ----------- | ------
40+
from_dict_ | [ObjectUnevaluatedPropertiesFalseWithPropertiesDictInput](#objectunevaluatedpropertiesfalsewithpropertiesdictinput), [ObjectUnevaluatedPropertiesFalseWithPropertiesDict](#objectunevaluatedpropertiesfalsewithpropertiesdict) | [ObjectUnevaluatedPropertiesFalseWithPropertiesDict](#objectunevaluatedpropertiesfalsewithpropertiesdict) | a constructor
41+
get_additional_property_ | str | schemas.immutabledict, tuple, float, int, str, bool, None, bytes, schemas.FileIO, schemas.Unset }} | provides type safety for additional properties
42+
43+
[[Back to top]](#top) [[Back to Component Schemas]](../../../README.md#Component-Schemas) [[Back to README]](../../../README.md)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# coding: utf-8
2+
3+
"""
4+
Example
5+
No description provided (generated by Openapi JSON Schema Generator https://github.com/openapi-json-schema-tools/openapi-json-schema-generator) # noqa: E501
6+
The version of the OpenAPI document: 1.0.0
7+
Generated by: https://github.com/openapi-json-schema-tools/openapi-json-schema-generator
8+
"""
9+
10+
from __future__ import annotations
11+
from json_schema_api.shared_imports.schema_imports import * # pyright: ignore [reportWildcardImportFromLibrary]
12+
13+
_Not: typing_extensions.TypeAlias = schemas.AnyTypeSchema
14+
15+
16+
@dataclasses.dataclass(frozen=True)
17+
class UnevaluatedProperties(
18+
schemas.AnyTypeSchema[schemas.immutabledict[str, schemas.OUTPUT_BASE_TYPES], typing.Tuple[schemas.OUTPUT_BASE_TYPES, ...]],
19+
):
20+
# any type
21+
not_: typing.Type[_Not] = dataclasses.field(default_factory=lambda: _Not) # type: ignore
22+
23+
24+
25+
@dataclasses.dataclass(frozen=True)
26+
class AnyTypeUnevaluatedPropertiesFalse(
27+
schemas.AnyTypeSchema[schemas.immutabledict[str, schemas.OUTPUT_BASE_TYPES], typing.Tuple[schemas.OUTPUT_BASE_TYPES, ...]],
28+
):
29+
"""NOTE: This class is auto generated by OpenAPI JSON Schema Generator.
30+
Ref: https://github.com/openapi-json-schema-tools/openapi-json-schema-generator
31+
32+
Do not edit the class manually.
33+
"""
34+
# any type
35+
unevaluated_properties: typing.Type[UnevaluatedProperties] = dataclasses.field(default_factory=lambda: UnevaluatedProperties) # type: ignore
36+

0 commit comments

Comments
 (0)