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

Commit 0804007

Browse files
authored
Adds 3.1.0 dependent schemas (#214)
* Adds dependentSchemas data store and writes to it * Fixes input param name in javadoc * Adds two test schemas to th 310 spec file for dependentSchemas * Writes out dependend schema info in the schema class * Writes out dependentSchemas inline schemas in py files * Adds validate_dependent_schemas * Adds python tests * Adds keyword to list of disableable ones, adds schem feature property for docs and turns it on in python generator * Sample regen * Docs regen
1 parent a129d3d commit 0804007

File tree

35 files changed

+427
-3
lines changed

35 files changed

+427
-3
lines changed

docs/generators/java.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
320320
|Contains|✗|OAS3
321321
|Default|✗|OAS2,OAS3
322322
|DependentRequired|✗|OAS3
323+
|DependentSchemas|✗|OAS3
323324
|Discriminator|✓|OAS2,OAS3
324325
|Enum|✓|OAS2,OAS3
325326
|ExclusiveMinimum|✓|OAS2,OAS3

docs/generators/jaxrs-jersey.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
303303
|Contains|✗|OAS3
304304
|Default|✗|OAS2,OAS3
305305
|DependentRequired|✗|OAS3
306+
|DependentSchemas|✗|OAS3
306307
|Discriminator|✓|OAS2,OAS3
307308
|Enum|✓|OAS2,OAS3
308309
|ExclusiveMinimum|✓|OAS2,OAS3

docs/generators/jmeter.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
162162
|Contains|✗|OAS3
163163
|Default|✗|OAS2,OAS3
164164
|DependentRequired|✗|OAS3
165+
|DependentSchemas|✗|OAS3
165166
|Discriminator|✓|OAS2,OAS3
166167
|Enum|✓|OAS2,OAS3
167168
|ExclusiveMinimum|✓|OAS2,OAS3

docs/generators/kotlin.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
272272
|Contains|✗|OAS3
273273
|Default|✗|OAS2,OAS3
274274
|DependentRequired|✗|OAS3
275+
|DependentSchemas|✗|OAS3
275276
|Discriminator|✓|OAS2,OAS3
276277
|Enum|✓|OAS2,OAS3
277278
|ExclusiveMinimum|✓|OAS2,OAS3

docs/generators/python.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
231231
|Contains|✓|OAS3
232232
|Default|✓|OAS2,OAS3
233233
|DependentRequired|✓|OAS3
234+
|DependentSchemas|✓|OAS3
234235
|Discriminator|✓|OAS2,OAS3
235236
|Enum|✓|OAS2,OAS3
236237
|ExclusiveMinimum|✓|OAS2,OAS3

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
'const_value_to_name': 'const',
2020
'contains': 'contains',
2121
'dependent_required': 'dependentRequired',
22+
'dependent_schemas': 'dependentSchemas',
2223
'discriminator': 'discriminator',
2324
# default omitted because it has no validation impact
2425
'enum_value_to_name': 'enum',

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,6 +1081,28 @@ def validate_dependent_required(
10811081
return None
10821082

10831083

1084+
def validate_dependent_schemas(
1085+
arg: typing.Any,
1086+
dependent_schemas: typing.Mapping[str, typing.Type[SchemaValidator]],
1087+
cls: typing.Type,
1088+
validation_metadata: ValidationMetadata,
1089+
) -> typing.Optional[PathToSchemasType]:
1090+
if not isinstance(arg, immutabledict):
1091+
return None
1092+
path_to_schemas: PathToSchemasType = {}
1093+
module_namespace = vars(sys.modules[cls.__module__])
1094+
for key, schema in dependent_schemas.items():
1095+
if key not in arg:
1096+
continue
1097+
schema = _get_class(schema, module_namespace)
1098+
if validation_metadata.validation_ran_earlier(schema):
1099+
add_deeper_validated_schemas(validation_metadata, path_to_schemas)
1100+
continue
1101+
other_path_to_schemas = schema._validate(arg, validation_metadata=validation_metadata)
1102+
update(path_to_schemas, other_path_to_schemas)
1103+
return path_to_schemas
1104+
1105+
10841106
validator_type = typing.Callable[[typing.Any, typing.Any, type, ValidationMetadata], typing.Optional[PathToSchemasType]]
10851107
json_schema_keyword_to_validator: typing.Mapping[str, validator_type] = {
10861108
'types': validate_types,
@@ -1113,4 +1135,5 @@ def validate_dependent_required(
11131135
'max_contains': validate_max_contains,
11141136
'const_value_to_name': validate_const,
11151137
'dependent_required': validate_dependent_required,
1138+
'dependent_schemas': validate_dependent_schemas
11161139
}

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
@@ -6,12 +6,14 @@ docs/apis/tags/default_api.md
66
docs/components/schema/any_type_const_string.md
77
docs/components/schema/any_type_contains_value.md
88
docs/components/schema/any_type_dependent_required.md
9+
docs/components/schema/any_type_dependent_schemas.md
910
docs/components/schema/any_type_max_contains_value.md
1011
docs/components/schema/any_type_min_contains_value.md
1112
docs/components/schema/array_contains_value.md
1213
docs/components/schema/array_max_contains_value.md
1314
docs/components/schema/array_min_contains_value.md
1415
docs/components/schema/object_dependent_required.md
16+
docs/components/schema/object_dependent_schemas.md
1517
docs/components/schema/string_const_string.md
1618
docs/paths/some_path/get.md
1719
docs/paths/some_path/get/responses/response_200/content/application_json/schema.md
@@ -36,12 +38,14 @@ src/json_schema_api/components/schema/__init__.py
3638
src/json_schema_api/components/schema/any_type_const_string.py
3739
src/json_schema_api/components/schema/any_type_contains_value.py
3840
src/json_schema_api/components/schema/any_type_dependent_required.py
41+
src/json_schema_api/components/schema/any_type_dependent_schemas.py
3942
src/json_schema_api/components/schema/any_type_max_contains_value.py
4043
src/json_schema_api/components/schema/any_type_min_contains_value.py
4144
src/json_schema_api/components/schema/array_contains_value.py
4245
src/json_schema_api/components/schema/array_max_contains_value.py
4346
src/json_schema_api/components/schema/array_min_contains_value.py
4447
src/json_schema_api/components/schema/object_dependent_required.py
48+
src/json_schema_api/components/schema/object_dependent_schemas.py
4549
src/json_schema_api/components/schema/string_const_string.py
4650
src/json_schema_api/components/schemas/__init__.py
4751
src/json_schema_api/configurations/__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
@@ -176,12 +176,14 @@ Class | Description
176176
[AnyTypeConstString](docs/components/schema/any_type_const_string.md) |
177177
[AnyTypeContainsValue](docs/components/schema/any_type_contains_value.md) |
178178
[AnyTypeDependentRequired](docs/components/schema/any_type_dependent_required.md) |
179+
[AnyTypeDependentSchemas](docs/components/schema/any_type_dependent_schemas.md) |
179180
[AnyTypeMaxContainsValue](docs/components/schema/any_type_max_contains_value.md) |
180181
[AnyTypeMinContainsValue](docs/components/schema/any_type_min_contains_value.md) |
181182
[ArrayContainsValue](docs/components/schema/array_contains_value.md) |
182183
[ArrayMaxContainsValue](docs/components/schema/array_max_contains_value.md) |
183184
[ArrayMinContainsValue](docs/components/schema/array_min_contains_value.md) |
184185
[ObjectDependentRequired](docs/components/schema/object_dependent_required.md) |
186+
[ObjectDependentSchemas](docs/components/schema/object_dependent_schemas.md) |
185187
[StringConstString](docs/components/schema/string_const_string.md) |
186188

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