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

Commit bd48337

Browse files
authored
Adds patternProperties (#220)
* Adds patternProperties to codegenSchema * Adds sample spec schemas and stores data in java codegenSchema class * Writes pattern_properties info in python schema class * Writes pattern property schemas in python * Adds validate_pattern_properties * Adds python tests of patternProperties * Removes unneeded line from test file * Samples and docs regen * Fixes bug
1 parent 834b21b commit bd48337

File tree

31 files changed

+493
-36
lines changed

31 files changed

+493
-36
lines changed

docs/generators/java.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
342342
|Nullable|✗|OAS3
343343
|OneOf|✗|OAS3
344344
|Pattern|✓|OAS2,OAS3
345+
|PatternProperties|✗|OAS3
345346
|Properties|✓|OAS2,OAS3
346347
|PropertyNames|✗|OAS3
347348
|Required|✓|OAS2,OAS3

docs/generators/jaxrs-jersey.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
325325
|Nullable|✗|OAS3
326326
|OneOf|✗|OAS3
327327
|Pattern|✓|OAS2,OAS3
328+
|PatternProperties|✗|OAS3
328329
|Properties|✓|OAS2,OAS3
329330
|PropertyNames|✗|OAS3
330331
|Required|✓|OAS2,OAS3

docs/generators/jmeter.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
184184
|Nullable|✗|OAS3
185185
|OneOf|✗|OAS3
186186
|Pattern|✓|OAS2,OAS3
187+
|PatternProperties|✗|OAS3
187188
|Properties|✓|OAS2,OAS3
188189
|PropertyNames|✗|OAS3
189190
|Required|✓|OAS2,OAS3

docs/generators/kotlin.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
294294
|Nullable|✗|OAS3
295295
|OneOf|✗|OAS3
296296
|Pattern|✓|OAS2,OAS3
297+
|PatternProperties|✗|OAS3
297298
|Properties|✓|OAS2,OAS3
298299
|PropertyNames|✗|OAS3
299300
|Required|✓|OAS2,OAS3

docs/generators/python.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
253253
|Nullable|✓|OAS3
254254
|OneOf|✓|OAS3
255255
|Pattern|✓|OAS2,OAS3
256+
|PatternProperties|✓|OAS3
256257
|Properties|✓|OAS2,OAS3
257258
|PropertyNames|✓|OAS3
258259
|Required|✓|OAS2,OAS3

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

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1124,6 +1124,36 @@ def validate_property_names(
11241124
return None
11251125

11261126

1127+
def validate_pattern_properties(
1128+
arg: typing.Any,
1129+
pattern_properties: typing.Mapping[PatternInfo, typing.Type[SchemaValidator]],
1130+
cls: typing.Type,
1131+
validation_metadata: ValidationMetadata,
1132+
) -> typing.Optional[PathToSchemasType]:
1133+
if not isinstance(arg, immutabledict):
1134+
return None
1135+
path_to_schemas: PathToSchemasType = {}
1136+
module_namespace = vars(sys.modules[cls.__module__])
1137+
for property_name, property_value in arg.items():
1138+
path_to_item = validation_metadata.path_to_item + (property_name,)
1139+
property_validation_metadata = ValidationMetadata(
1140+
path_to_item=path_to_item,
1141+
configuration=validation_metadata.configuration,
1142+
validated_path_to_schemas=validation_metadata.validated_path_to_schemas
1143+
)
1144+
for pattern_info, schema in pattern_properties.items():
1145+
flags = pattern_info.flags if pattern_info.flags is not None else 0
1146+
if not re.search(pattern_info.pattern, property_name, flags=flags):
1147+
continue
1148+
schema = _get_class(schema, module_namespace)
1149+
if validation_metadata.validation_ran_earlier(schema):
1150+
add_deeper_validated_schemas(validation_metadata, path_to_schemas)
1151+
continue
1152+
other_path_to_schemas = schema._validate(property_value, validation_metadata=property_validation_metadata)
1153+
update(path_to_schemas, other_path_to_schemas)
1154+
return path_to_schemas
1155+
1156+
11271157
validator_type = typing.Callable[[typing.Any, typing.Any, type, ValidationMetadata], typing.Optional[PathToSchemasType]]
11281158
json_schema_keyword_to_validator: typing.Mapping[str, validator_type] = {
11291159
'types': validate_types,
@@ -1157,5 +1187,6 @@ def validate_property_names(
11571187
'const_value_to_name': validate_const,
11581188
'dependent_required': validate_dependent_required,
11591189
'dependent_schemas': validate_dependent_schemas,
1160-
'property_names': validate_property_names
1190+
'property_names': validate_property_names,
1191+
'pattern_properties': validate_pattern_properties
11611192
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ docs/components/schema/any_type_dependent_required.md
99
docs/components/schema/any_type_dependent_schemas.md
1010
docs/components/schema/any_type_max_contains_value.md
1111
docs/components/schema/any_type_min_contains_value.md
12+
docs/components/schema/any_type_pattern_properties.md
1213
docs/components/schema/any_type_property_names.md
1314
docs/components/schema/array_contains_value.md
1415
docs/components/schema/array_max_contains_value.md
1516
docs/components/schema/array_min_contains_value.md
1617
docs/components/schema/object_dependent_required.md
1718
docs/components/schema/object_dependent_schemas.md
19+
docs/components/schema/object_pattern_properties.md
1820
docs/components/schema/object_property_names.md
1921
docs/components/schema/string_const_string.md
2022
docs/paths/some_path/get.md
@@ -43,12 +45,14 @@ src/json_schema_api/components/schema/any_type_dependent_required.py
4345
src/json_schema_api/components/schema/any_type_dependent_schemas.py
4446
src/json_schema_api/components/schema/any_type_max_contains_value.py
4547
src/json_schema_api/components/schema/any_type_min_contains_value.py
48+
src/json_schema_api/components/schema/any_type_pattern_properties.py
4649
src/json_schema_api/components/schema/any_type_property_names.py
4750
src/json_schema_api/components/schema/array_contains_value.py
4851
src/json_schema_api/components/schema/array_max_contains_value.py
4952
src/json_schema_api/components/schema/array_min_contains_value.py
5053
src/json_schema_api/components/schema/object_dependent_required.py
5154
src/json_schema_api/components/schema/object_dependent_schemas.py
55+
src/json_schema_api/components/schema/object_pattern_properties.py
5256
src/json_schema_api/components/schema/object_property_names.py
5357
src/json_schema_api/components/schema/string_const_string.py
5458
src/json_schema_api/components/schemas/__init__.py

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,12 +179,14 @@ Class | Description
179179
[AnyTypeDependentSchemas](docs/components/schema/any_type_dependent_schemas.md) |
180180
[AnyTypeMaxContainsValue](docs/components/schema/any_type_max_contains_value.md) |
181181
[AnyTypeMinContainsValue](docs/components/schema/any_type_min_contains_value.md) |
182+
[AnyTypePatternProperties](docs/components/schema/any_type_pattern_properties.md) |
182183
[AnyTypePropertyNames](docs/components/schema/any_type_property_names.md) |
183184
[ArrayContainsValue](docs/components/schema/array_contains_value.md) |
184185
[ArrayMaxContainsValue](docs/components/schema/array_max_contains_value.md) |
185186
[ArrayMinContainsValue](docs/components/schema/array_min_contains_value.md) |
186187
[ObjectDependentRequired](docs/components/schema/object_dependent_required.md) |
187188
[ObjectDependentSchemas](docs/components/schema/object_dependent_schemas.md) |
189+
[ObjectPatternProperties](docs/components/schema/object_pattern_properties.md) |
188190
[ObjectPropertyNames](docs/components/schema/object_property_names.md) |
189191
[StringConstString](docs/components/schema/string_const_string.md) |
190192

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# AnyTypePatternProperties
2+
json_schema_api.components.schema.any_type_pattern_properties
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)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# ObjectPatternProperties
2+
json_schema_api.components.schema.object_pattern_properties
3+
```
4+
type: schemas.Schema
5+
```
6+
7+
## validate method
8+
Input Type | Return Type | Notes
9+
------------ | ------------- | -------------
10+
dict, schemas.immutabledict | schemas.immutabledict |
11+
12+
[[Back to top]](#top) [[Back to Component Schemas]](../../../README.md#Component-Schemas) [[Back to README]](../../../README.md)

0 commit comments

Comments
 (0)